userimage

Paypal implementation using Adaptive payment for novice

Overview

Recently I worked on an e commerce project to integrate Paypal as a Payment Gateway service using Paypal Adaptive Payment Rest APIs. AS I am quite new so face little difficulties to complete the development. In between the development period we made so many analysis and discussion between the team and took suggestions from the experts those who already integrated on there projects. And finally we chosen Paypal Adaptive Payment with the REST API services to use in our project.

Here I will give some brief history and explanation related to Paypal and its development environment and share some experience gain through the development which I feel it might be useful for the people who wanted to integrate Paypal gateway service on there mobile apps or web applications.


A short story behind Transaction

Now a days, made any kind of online transactions is as simple as it is compare to earlier days of transactions. And if I am not wrong people are rapidly moving and giving interest into this era of internet. Means will get maximum day to day useful stuffs by sitting at home itself and just giving little bit of time to the internet. And from where e commerce market is rapidly growing with this. But the growth is not stop here people need more flexibility to made the transaction processes. Suppose we are going through any website and made a recharge of sim card or purchase some item from any e commerce like application the common thing in between is transaction where we need to enter our card details every time for each purchase which is really a repetitive task for us. So to get reveal from this one of the payment gateway service like Paypal came to picture which will reduce this repetitive transaction process and save the time too within a secured network. By using paypal we can complete our transaction with a very short period of time by following some minimal process.


About Paypal and its development environment

There was a day where to integrate any kind of Payment Gateway Service like Paypal is difficult for the developers into the application. Because may be application was ran on a development environment but to make a payment through gateway service need to do a real transaction with some minimal amount to test. But money is money, weather is small or big amount. And nobody wants to spend any single penny of them without any benefits or usefulness. But now this fear went so far from the developers because of the sandbox implementation. Where every transaction or activity perform looks real but in practical its just a dummy.Now a days Paypal make very easy by giving us both development and sandbox environment to use and integrate the service into our applications. We can able to make any number of dummy transaction and easily track as well through out the development and testing period  before go live with Paypal.


Steps to Enter into paypal development environment

  • Before moving to paypal development site first need to register on the official site http://www.paypal.com
  • if want to act as a seller then register as a business customer or else register as a personal or individual customer as a buyer.
  • Please remember registration is based on your country specific. So before register just validate your country from the bottom right corner of the site.
  • Once registration done you can login yourself with the development URL https://developer.paypal.com/ and sandbox URL https://www.sandbox.paypal.com as well.

The difference between Paypal sandbox and development

Paypal sandbox : Will give a test platform where you can manage your transaction activities and able to seen the summary and the detail list of transaction made through the application using Paypal service.
Paypal development : Will give the complete platform to the developer with the facility of documents, guidelines or instructions, APIs detail, Creation of test accounts and many more. 


Which Paypal option do I need to choose?

Currently Paypal provides the below options for business.

    PayPal Pro

    PayPal Express

    PayPal Adaptive Payments

    PayPal Payments Advanced

"If you chooseN PayPal as your  Payment Gateway one of the first things you"ll find is that PayPal offers a variety of options, and the differences aren"t well documented." So have look on this site which Paypal payment gateway and account type do i need to gain some more clarity.

If still have doubt which payment gateway best fit with your business just have a look into the site choose payment gateway ecommerce store


Paypal Adaptive Payment Implementation

Paypal supporting below Options of payment modes inside Adaptive payments i.e,

  • Simple Payment
  • Parallel Payment
  • Chained Payment
  • Delayed Chained Payments

Simple Payment : A simple payment is when a sender (whose account is debited) sends a payment (amount and currency) to a single receiver (whose account is credited).

Parallel Payment : Adaptive Payments provides a feature that is new to PayPal products: Parallel Payments. Parallel Payments lets a sender pay multiple receivers in a single payment request. The money is then transferred from the sender’s account to the receiver’s account. For more visit https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/pp_dev_Datasheet_APP_R3.pdf

Chained Payment : Chained Payments, provided by Adaptive Payments, is a feature that is new to PayPal. With Adaptive Payments, you can use a single payment call to make payments to a single primary receiver, and from that primary receiver to several other receivers, called secondary receivers. For more visit https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/pp_dev_Datasheet_APC_R3.pdf

Delayed Chained Payments : After customer authorization, the primary receiver is paid. Payments to secondary receivers can be delayed for up to 90 days.

Note : The above payment modes as a development point of view not so much of difference but if you think business upon the business point of view there a big difference you can find. So before start integration or selection please chose a suitable mode of payment method for your business.


A detail view of Paypal Adaptive Simple Payment Mode using Paypal Sandbox JSON API Implementation

The payment mode will complete into 3 basic simple steps. i.e

  1. Payment Initiation
  2. Payment approval
  3. Payment acknowledgement (Confirmation)

Before made any API call from service side add below headers for the authentication.

X-PAYPAL-SECURITY-USERID:

X-PAYPAL-SECURITY-PASSWORD:

X-PAYPAL-SECURITY-SIGNATURE:

X-PAYPAL-REQUEST-DATA-FORMAT: JSON

X-PAYPAL-RESPONSE-DATA-FORMAT: JSON

X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T

You can find the details how to fill those headers with required parameter from How to use Paypal API Credential into Request Header


1.Payment Initiation

In this just initiate the amount(How much you are expecting from a buyer for the purchased item) with Paypal by provided with the business email id as a receiver with the currency depends upon your country and two web-hook like URL which will invoke once the buyer will pay or cancel the transaction between the time of payment approval.


The request will validate and create a payment and return the payment key or else the exception message with id in case of any failure to create a payment on Paypal side.


Method : POST 

URL : https://svcs.sandbox.paypal.com/AdaptivePayments/Pay  

Request 

{   

    "returnUrl": "http://example.com/returnURL.htm",   

    "requestEnvelope": {     

        "errorLanguage": "en_US"   

    },   

    "currencyCode": "USD",   

    "receiverList": {     

    "receiver": [       

        {         

            "email": "receiver.test@example.com",         

            "amount": "100.00"       

        }

    ]   

    },   

    "cancelUrl": "http://example.com/cancelURL.htm",   

    "actionType": "PAY" 

 

Success response 

{   

    "responseEnvelope": {     

        "timestamp": "2016-06-13T01:57:36.818-07:00",     

        "ack": "Success",     

        "correlationId": "974ccdeaf1fef",     

        "build": "20420247"   

    },   

    "payKey": "AP-9A27425592457832L",   

    "paymentExecStatus": "CREATED" 

}  

Failure response 

{   

    "responseEnvelope": {     

        "timestamp": "2016-06-13T01:38:22.703-07:00",     

        "ack": "Failure",     

        "correlationId": "1674ebf2cb5fc",     

        "build": "20420247"   

    },   

    "error": [     

        {       

            "errorId": "580022",       

            "domain": "PLATFORM",       

            "subdomain": "Application",       

            "severity": "Error",       

            "category": "Application",       

            "message": "The receiver is based in a country that isn"t enabled to send payments using balance"     

        }   

    ] 

}                  


2.Payment approval

In this the user need to approve the payment amount from the Paypal site with the redirection URL. Here Paypal handle two options to approve the payment i.e, by using  web view and  mobile view.

Web View

If your application running from a desktop browser then you can append the response pay key into the following url and redirected to the buyer on the Paypal site to approve the payment.

https://www.sandbox.paypal.com/br/cgi-bin/webscr?cmd=_ap-payment&paykey=<"payKey">

Mobile View

If your application running from a mobile then use the below piece of code to generate a paypal Pay Now button which by clicking into this buyer can redirected to the paypal site with a mobile view to approve the payment.

<html>

    <head>

        <script src="https://www.paypalobjects.com/js/external/apdg.js" type="text/javascript"></script>

        <span id="lippButton"></span>

        <script src="https://www.paypalobjects.com/js/external/api.js"></script>

    </head>

    <body>

        <form action="https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay" target="PPDGFrame" class="standard">

            <input type="image" id="submitBtn" value="Pay with PayPal" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif">

            <input id="type" type="hidden" name="expType" value="mini">

            <input id="paykey" type="hidden" name="paykey" value="AP-8WX34205M4304871U">

        </form>

        <script type="text/javascript" charset="utf-8">

            var dgFlowMini = new PAYPAL.apps.DGFlowMini({trigger: "submitBtn"});

        </script>

    </body>

</html>

Here Buyer have a choice either to approve the payment by using pay button or cancel the payment after login into the official payment site of Paypal.



3.Payment acknowledgement

Request will be track the status of the payment by validation the Paykey and return with the status like CREATED or COMPLETED or EXPIRED etc. and some more additional info which will be use for offline tracking about the payment confirmation. And if you want can audit the transaction from sandbox site with the transactionId.


Method : POST

URL : https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails

Request

{"requestEnvelope":"en_US","payKey":"AP-9A27425592457832L"}

Response

{

  "responseEnvelope": {

    "timestamp": "2016-06-13T00:14:47.538-07:00",

    "ack": "Success",

    "correlationId": "f839f0f994b0f",

    "build": "20420247"

  },

  "cancelUrl": "http://example.com/cancelURL.htm",

  "currencyCode": "USD",

  "paymentInfoList": {

    "paymentInfo": [

      {

        "transactionId": "1BS46269F8657793J",

        "transactionStatus": "COMPLETED",

        "receiver": {

          "amount": "100.00",

          "email": "receiver.test@example.com",

          "primary": "false",

          "paymentType": "SERVICE",

          "accountId": "P22HTLKVBXVDA"

        },

        "refundedAmount": "0.00",

        "pendingRefund": "false",

        "senderTransactionId": "36A53818GA926630X",

        "senderTransactionStatus": "COMPLETED"

      }

    ]

  },

  "returnUrl": "http://example.com/returnURL.htm",

  "senderEmail": "buyer.test@example.com",

  "status": "COMPLETED",

  "payKey": "AP-2UX230673S920630N",

  "actionType": "PAY",

  "feesPayer": "EACHRECEIVER",

  "reverseAllParallelPaymentsOnError": "false",

  "sender": {

    "email": "buyer.test@example.com",

    "accountId": "NP983LWBZQTQN",

    "useCredentials": "false"

  }

}


Reference 

For more details please visit below links,


AT THE END 

I am pretty much sure that after reading this article you will be in a position to chose a better payment mode for your business using Paypal and able to integrate easily into your application with the adaptive payment API"s by following the given simple steps. Its no doubt you will get more in details by visiting the official Paypal development site where you can get clarity more than your expectation. I just assuming this article is a best fit for a beginner who work hard for searching a better solution or approach of the payment method for there business. If I miss any point or need more clarity into the subject please put a comment so that I will consider and try to give more clarity on your question. Have a good day! Thank you:)