Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paypal Advanced Recurring billing with Express Checkout and Credit card payment using hosted pages

In my application, I need to set recurring billing section using paypal advanced and I am using the payflow section to do the same. I need both Pay with PayPal button process (Express Checkout process) and Credit card payment to create the recurring profile. My initial request is like this:

public static PayPalRedirectAdv PayFlow()
{

    NameValueCollection requestArray = new NameValueCollection()
    {

        {"PARTNER", "PayPal"},             // You'll want to change these 4
        {"VENDOR", "merchantname"},           // To use your own credentials
        {"USER", "username"},
        {"PWD", "abcdenfg"},
        {"TRXTYPE", "A"},
        {"AMT", "1.00"},
        {"CURRENCY", "USD"},
        {"CREATESECURETOKEN", "Y"},
        {"SECURETOKENID", "tokenId generated"},  
        {"RETURNURL", UrlReturn}, 
        {"CANCELURL", UrlCancel},
        {"ERRORURL", lUrlError},
        {"BILLINGTYPE","RecurringBilling"}

    };

    NameValueCollection resp = run_payflow_call(requestArray); // Will call the payflow end point via HttpWebRequest
    if (resp["RESULT"] == "0")
    {
        string mode = "TEST";
        return new PayPalRedirectAdv
        {
            Url = "https://payflowlink.paypal.com?SECURETOKEN=" + resp["SECURETOKEN"] + "&SECURETOKENID=" + resp["SECURETOKENID"] + "&MODE=" + mode
        };
    }
    else
    {
        return new PayPalRedirectAdv { Url = string.Empty };
    }
}

Once the process is completed, I have set the url to an IFrame and it is embedded in one of my views in my mvc project. When the IFrame is loaded, it has two issues.

1) The page is redirected to the top level. This means that the browser window is redirected to IFrame url. I have chosen Layout C as my hosted checkout page. When I use credentials supplied in the demo project, the browser navigation is solved; i.e Iframe correctly loaded in my view. Is there any setting in the Paypal manager settings to prevent this? I tried to fix this by sandboxing top level navigation, but this won't allow me to redirect to paypal site by clicking the "Check out with Paypal" button.

2) For a payment with a Credit card, once the transaction is successful, I will convert the existing transaction to a profile by:

    "TRXTYPE=R&TENDER=C&PARTNER=PayPal&VENDOR=Acme&USER=Acme&PWD=a1b2c3d4&ACTION=A&PROFILENAME=RegularSubscription&ORIGID=<PNREF>&START=12012002&PAYPERIOD=
WEEK&TERM=12&OPTIONALTRX=S&OPTIONALTRXAMT=2.00&COMMENT1=First-time
customer&AMT=42.00"

This works fine and the recurring profile is created.

However, when I click on the "Check out with Paypal" button, this will take me to the Paypal page where I could login to Paypal using my Paypal credentials and then when I click the "paynow" button, it will deduct money from my account. This also has an PNERF value and when I used the same code above to convert the transaction to recurring profile by replacing Tender as P, but it shows me a response message that "the transaction id corresponding to this id is not found". The Paypal checkout process doesn't show any information about the user is going for a reccuring payment section.

Also, I followed Express Checkout with recurring billing to do the task, but I got BAID as null in the DoExpressCheckout step.

I need both pay with paypal and pay with credit options on my site, so what parameters should I use to accomplish this?

Thanks in advance.

like image 995
BonDaviD Avatar asked Aug 22 '13 11:08

BonDaviD


People also ask

What is PayPal Express checkout payment?

PayPal Checkout, formerly known as PayPal Express Checkout, is a tool made for online sellers. It allows customers to buy goods or services easily, without the need to input their shipping and billing details. This ensures that the customer's personal and payment information is transmitted securely to the merchant.

What is PayPal Advanced payment?

PayPal Payments Advanced (PPA) enables merchants to accept PayPal and credit cards. PPA provides merchants with a PayPal merchant account. Integration with PPA is similar to integration with the PayPal Payflow Gateway.

What is the difference between PayPal Standard and Express checkout?

PayPal Express is very similar to PayPal Standard with one major difference: the checkout flow. PayPal Express avoids the IPN issues that arise with PayPal Standard. Customers will be directed to PayPal from your site, but they don't complete checkout at PayPal.

How do PayPal recurring payments work?

Recurring payments are collected on the same day of the month. If the initial recurring payment falls on the 31st, PayPal eventually adjusts the billing cycle to the last of the month.


1 Answers

string strUsername = "<<paypal_username>>";
    string strPassword = "<<paypal_password>>";
    string strSignature = "<<paypal_signature>>";
    string strCredentials = "USER=" + strUsername + "&PWD=" + strPassword + "&SIGNATURE=" + strSignature;

    string strNVPSandboxServer = "https://api-3t.sandbox.paypal.com/nvp";
    string strAPIVersion = "2.3";
    //4456193676582624                                                                   4025609244685781
    string strNVP = strCredentials + "&METHOD=DoDirectPayment" +
        "&CREDITCARDTYPE=VISA" +
         "&ACCT=<<CARDNO>>" +
         "&EXPDATE=<<EXPDATE>>" +
         "&CVV2=<<CVV>" +
         "&AMT=<<AMOUNT>>" +
         "&FIRSTNAME=<<CUST_NAME>>" +
         "&LASTNAME=<<CUST_LASTNAME>>" +
         "&CURRENCYCODE=<<CURRENCY_CODE>>" +
         "&IPADDRESS=<<USER_IP>>" +
         "&STREET=<<ADDRESS>>" +
         "&CITY=<<CITY>>" +
         "&STATE=<<STATE>>" +
         "&COUNTRY=<<COUNTRY>>" +
         "&ZIP=<<XIPCODE>>" +
         "&COUNTRYCODE=<<COUNTRY>>" +
         "&PAYMENTACTION=SALE" +
         "&L_NAME0=item1&L_DESC0=test1description&L_AMT0=1&L_QTY0=1" +
         "&L_NAME1=item2&L_DESC1=test2description&L_AMT1=2&L_QTY1=2" +
         "&L_NAME2=item3&L_DESC2=test3description&L_AMT2=3&L_QTY2=3" +
         "&VERSION=" + strAPIVersion;
    //strNVP = Server.UrlEncode(strNVP);
    try
    {
        //Create web request and web response objects, make sure you using the correct server (sandbox/live)
        HttpWebRequest wrWebRequest = (HttpWebRequest)WebRequest.Create(strNVPSandboxServer);
        wrWebRequest.Method = "POST";
        StreamWriter requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());
        requestWriter.Write(strNVP);
        requestWriter.Close();

        // Get the response.
        HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
        StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());

        //and read the response
        string responseData = responseReader.ReadToEnd();
        responseReader.Close();

        string result = Server.UrlDecode(responseData);

        string[] arrResult = result.Split('&');
        Hashtable htResponse = new Hashtable();
        string[] responseItemArray;
        foreach (string responseItem in arrResult)
        {
            responseItemArray = responseItem.Split('=');
            htResponse.Add(responseItemArray[0], responseItemArray[1]);
        }

        string strAck = htResponse["ACK"].ToString();

        if (strAck == "Success" || strAck == "SuccessWithWarning")
        {
            string strAmt = htResponse["AMT"].ToString();
            string strCcy = htResponse["CURRENCYCODE"].ToString();
            string strTransactionID = htResponse["TRANSACTIONID"].ToString();
            //ordersDataSource.InsertParameters["TransactionID"].DefaultValue = strTransactionID;

            string strSuccess = "Thank you, your order for: $" + strAmt + " " + strCcy + " has been processed.";
            Response.Write(strSuccess);
            //successLabel.Text = strSuccess;
        }
        else
        {
            string strErr = "Error: " + htResponse["L_LONGMESSAGE0"].ToString();
            string strErrcode = "Error code: " + htResponse["L_ERRORCODE0"].ToString();
            //errLabel.Text = strErr;
            //errcodeLabel.Text = strErrcode;
            return;
        }
    }
    catch (Exception ex)
    {
        // do something to catch the error, like write to a log file.
        Response.Write("error processing");
    }`enter code here`

try to use this code....no DLL needed to request for paypal payment.

like image 195
user3573206 Avatar answered Nov 14 '22 23:11

user3573206