Paypal Parallel Payment on Android

Paypal parallel payment on Android

 

In this post I shall be going around to explain how to integrate paypal parallel payment on Android.

Before we move on to integration, let me explain what parallel payment is, in very short.
Parallel payment allows you to pay to multiple merchants in just a single transaction. For example. I am running a website to book tickets, and for every booking I keep some percentage of the amount, and the rest is paid to the cineplex. In this scenario we will be using parallel payments.

You can read more about Parallel payment on paypal parallel payment guide.

 

In order to integrate parallel payments, you should be having following.

1.) Account at developer.paypal.com.
2.) Create an app at: https://www.paypal-apps.com/user/my-account/applications or you can use dummy app Id, APP-80W284485P519543T
3.) Get the api keys and grant API access. I don’t remember exactly but I believe you will have to navigate to:
https://www.paypal.com/webapps/customerprofile/summary.view then go to “Api Access”, then “Update” and finally “Grant Api Access”.

Your Api keys should be looking something like this:


API Username :   ash_avr_api1.fastmail.fm
API Password :   M67KH997ARZ52JH6
Signature  :  BGkC1TWFxKJWAj2s1.2xl9z.gDhyA3wOeKPnzhEjrPWP9cjMN-XPQSrt

 

For the integration part, the API end point for this particular payment type is:
https://svcs.sandbox.paypal.com/AdaptivePayments/Pay

 

While making post request to this api, you will have to set certain fields in header.

-H "X-PAYPAL-SECURITY-USERID:  insert_developer_user_name_here"
-H "X-PAYPAL-SECURITY-PASSWORD: insert_developer_password_here"
-H "X-PAYPAL-SECURITY-SIGNATURE: insert_developer_signature_here"
-H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON"
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON"
-H "X-PAYPAL-APPLICATION-ID:   APP-80W284485P519543T"     #Standard Sandbox App ID

Besides header, you will also have to post certain other values to this api.
Remember you can either user name value pairs or JSON.

Below are the input parameters that will be required.

actionType=PAY      #The action taken in the Pay request (that is, the PAY action)
&clientDetails.applicationId=APP-80W284485P519543T #Standard Sandbox App ID
&clientDetails.ipAddress=127.0.0.1     #Address from which request is sent  
&senderEmail=sender_email
&currencyCode=USD        #The currency, e.g. US dollars
&receiverList.receiver(0).amount=3.00     #The payment amount for the first receiver
&receiverList.receiver(0).email=first_receiver_email
&receiverList.receiver(1).amount=4.00    #The payment amount for the second receiver
&receiverList.receiver(1).email=second_receiver_email
&requestEnvelope.errorLanguage=en_US
&returnUrl=http://www.yourdomain.com/success.html    #For use if the consumer proceeds with payment
&cancelUrl=http://www.yourdomain.com/cancel.html    #For use if the consumer decides not to proceed with payment

If you want to test the above api, here is the curl command:


curl -s --insecure -H "X-PAYPAL-SECURITY-USERID: ash_avr_api1.fastmail.fm" -H "X-PAYPAL-SECURITY-PASSWORD: M67KH997ARZ52JH6" -H "X-PAYPAL-SECURITY-SIGNATURE: BGkC1TWFxKJWAj2s1.2xl9z.gDhyA3wOeKPnzhEjrPWP9cjMN-XPQSrt" -H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" -H "X-PAYPAL-RESPONSE-DATA-FORMAT=JSON"   https://svcs.sandbox.paypal.com/AdaptivePayments/Pay -d "{\"actionType\":\"PAY\", \"currencyCode\":\"USD\", \"receiverList\":{\"receiver\":[{\"amount\":\"1.00\",\"email\":\"rec1_1312486368_biz@gmail.com\"}]}, \"returnUrl\":\"http://www.example.com/success.html\", \"cancelUrl\":\"http://www.example.com/failure.html\", \"requestEnvelope\":{\"errorLanguage\":\"en_US\", \"detailLevel\":\"ReturnAll\"}}"

 

 

It might be looking complicated, but if you will give some time to it, you will get it easily.

 

In response of above api you will be getting these keys:

responseEnvelope.ack=Success
&payKey=AP-70S20255150981234    #Value of the pay key, for use in a redirect to the PayPal site
&paymentExecStatus=CREATED    #Indicates that a payment is set up, ready for a sender to click Pay on the PayPal site

 

Now open your webview and navigate to:

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=AP-3GA876285V2310346

 

Bang!.  Its done now.

In case you want to get an idea of code snippet, you can view Paypal Parallel Payment here.

Leave a Reply