Using PayPal’s PayFlowPro to setup Recurring Billing in Asp.net

Home / Asp.net / Using PayPal’s PayFlowPro to setup Recurring Billing in Asp.net

First step is to set up a business account with PayPal in addition to creating an Internet Merchant Account which will allow you to work with PFP. These tasks are beyond the scope of this white paper and this article assumes that these items have already been established. For more information on this, please visit PayPal.

When the accounts are established, the next step is to download the PayFlowPro SDK from PayPal and install it. Once installed and properly referenced in your Web project, you are ready to begin your adventure into getting your site customized to work with PFP!

The way that PFP manages recurring billing is through a vehicle called Profiles. For each customer that you wish to bill on a recurring basis, you will be required to create a Profile. On most sites, this would be done at the initial time of billing.

Following below is code sample

 

public int AddUpdateProfileWithTransaction()
{
    PayflowConnectionData Connection = new PayflowConnectionData("payflowpro.paypal.com", 443);;
  UserInfo User = 
        new UserInfo("<user>", "<vendor>", "<partner>", "<password>");
    // Create Invoice
    Invoice Inv = new Invoice();
    // Set Amount
    Currency Amt = new Currency(new decimal(7.95), "USD");
    Inv.Amt = Amt;
    Inv.InvNum = "xxxxx";

    // Create and set Bill To Info
    BillTo Bill = new BillTo();
    Bill.Street = “1600 Pennsylvania Ave.”;
    Bill.Zip = ”20006”;
    Bill.City = ”Washington”;
    Bill.State = ”DC”;
    Bill.FirstName = “George”;
    Bill.LastName = “Bush”;
    Bill.BillToCountry = ”US”;
    Bill.Email = “president@whitehouse.gov”;

    Inv.BillTo = Bill;

    PayPal.Payments.DataObjects.CreditCard CC = 
        new PayPal.Payments.DataObjects.CreditCard
        (“5105555555550155”, string.Format("{0}{1}",”05”,”09”)); // ( cardno, Expdate in MMYY format)
    CC.Cvv2 = “123”;

    // Create a new Tender - Card Tender data object.
    CardTender Card = new CardTender(CC);

    RecurringInfo RecurInfo = new RecurringInfo();

    // The date that the first payment will be processed. 
    // Note - this value must be greater
    // than the current date! We will charge the customer 
    // for the first month in a sep. Transaction
    // Format must be mmddyyyy
   DateTime StartBilling = DateTime.Now.AddMonths(1);

    RecurInfo.Start = StartBilling.ToString("MMddyyyy");
    RecurInfo.ProfileName = string.Format("{0}, {1}", “Bush” , “George”);
    // Specifies how often the payment occurs. All PAYPERIOD values must use 
    // capital letters and can be any of WEEK / BIWK / SMMO / FRWK / MONT / 
    // QTER / SMYR / YEAR
    RecurInfo.PayPeriod = "MONT";
    RecurInfo.Term = 0; // Number of payments 0 = indef.

    // Perform an Optional Transaction. Verify that we need to do this!!
    RecurInfo.OptionalTrx = "S"; // S = Sale, A = Authorization

    // Set the amount if doing a "Sale" for the Optional Transaction.
    Currency oTrxAmt = new Currency(new decimal(7.95), "USD");
    RecurInfo.OptionalTrxAmt = oTrxAmt;

    // Create a new Recurring Add Transaction.
    RecurringAddTransaction Trans = new RecurringAddTransaction(
    User, Connection, Inv, Card, RecurInfo, PayflowUtility.RequestId);

    // Submit the Transaction
    Response Resp = Trans.SubmitTransaction();

    // Return the transaction response parameters.
    if (Resp != null)
    {
        // Get the Transaction Response parameters.
        TransactionResponse TrxnResponse = Resp.TransactionResponse;

        // Get the Recurring Response parameters.
        RecurringResponse RecurResponse = Resp.RecurringResponse;

        if ((TrxnResponse != null) && (RecurResponse != null))
        {
            if (TrxnResponse.Result == 0)
            {
                // Return the ProfileID if desired
                // ProfileID = RecurResponse.ProfileId;
                return 0; //Success!!!
            }
            else
            {
                try
                {
                    int RetCode = int.Parse(RecurResponse.TrxResult);
                    return RetCode; 
                }
                catch (Exception)
                {
                    return TrxnResponse.Result;
                }
            }
        }    
        else
        {
            _TransactionID = "";
            return -1;
        }
    }    
    else
    {
        _TransactionID = "";
        return -1;
    }
}

edgedoll.com

Comments(0)

Leave a Comment