970_90

Saturday, 28 November 2015

PayPal Express Checkout Working Flow - In Simple Steps with Clean Example


PayPal Express Checkout Working Flow
PayPal Express Checkout is a powerful API-based solution that can be integrated into any merchant website. With PayPal Express Checkout API, customer leave the website and complete the transaction in http://paypal.com, where customer can pay with paypal.com account OR with credit card / Debit card. When start processing, Paypal gives a TOKEN key which is used to charge money from customer OR get the Payment Details OR Customer Shipping/Billing details. Developer should save this token key for future use.


Express Checkout have Simple Seven Steps. Start from initializing the token and end with success page after payment.


Customer makes their payment and completes their order on your website. This enables tighter integration with your website and order management processes. It can be more efficient for PayPal users and may facilitate sales.



Following are 7 Steps of express Checkout
Step 1: Get Token API In this case we need to send an API call to Paypal Server with item detail, receiver email etc.
Request Parameter Example
Array
(
    [USER] => PAYPAL_API_EMAIL
    [PWD] => PAYPAL_API_PASSWORD
    [SIGNATURE] => PAYPAL_API_SIGNATURE
    [VERSION] => 95
    [ip] => 127.0.0.1
    [METHOD] => SetExpressCheckout
    [returnUrl] => http://example.com/order/success //customer will return this URL, if paid
    [cancelUrl] => http://example.com/order/failed //customer will return this URL, if not paid
    [L_PAYMENTREQUEST_0_NAME0] => Om Belt - Black
    [L_PAYMENTREQUEST_0_DESC0] => Obscure Belts
    [L_PAYMENTREQUEST_0_AMT0] => 82.92
    [L_PAYMENTREQUEST_0_QTY0] => 1
    [PAYMENTREQUEST_0_CURRENCYCODE] => USD
    [PAYMENTREQUEST_0_SHIPPINGAMT] => 5.15
    [PAYMENTREQUEST_0_AMT] => 88.07
    [PAYMENTREQUEST_0_ITEMAMT] => 82.92
    [PAYMENTREQUEST_0_PAYMENTACTION] => Order
    [PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID] => receiver_email_address;//payment will receive by this paypal email
    [PAYMENTREQUEST_0_PAYMENTREQUESTID] => ORDER_UNIQUE_ID
)

Step 2: Get Token From API Response After calling above API, we will get below response
Array
(
    [TOKEN] => EC-06N33746DC1035058
    [TIMESTAMP] => 2014-08-11T11:40:52Z
    [CORRELATIONID] => dcda5dabca4a7
    [ACK] => Success
    [VERSION] => 95
    [BUILD] => 12301660
)
Now, Store the TOKEN will be used in future


Step 3: Send Customer to Paypal After getting success, we will send customer to following URL with appending token key
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-06N33746DC1035058
Here User will see Cart detail and can pay after login.

Step 4: Order Confirmation Page After login successfully, Customer will move to Order Confirmation page with "Pay Now" Button
(Here user will see the cart detail and can pay)

Step 5: Get Order Detail When Customer paid successfully, customer will return to returnUrl (see step1), In return URL, TOKEN and PayerID will be appended automatically.
From TOKEN, we will get to know for what order user return.
From PayerID, We will get to know user is ready to pay us and also we used this Id to charge him.

Call following API, to get the Order Detail From Paypal
Array
(
    [USER] => PAYPAL_API_EMAIL
    [PWD] => PAYPAL_API_PASSWORD
    [SIGNATURE] => PAYPAL_API_SIGNATURE
    [VERSION] => 95
    [url] => https://api-3t.sandbox.paypal.com/nvp
    [METHOD] => GetExpressCheckoutDetails
    [TOKEN] => EC-06N33746DC1035058
)

After calling above API, response will be return

Step 6: Charge Money From Customer We need to a new paypal method to charge the customer i.e DoExpressCheckoutPayment
Request Params Example
Array
(
    [USER] => PAYPAL_API_EMAIL
    [PWD] => PAYPAL_API_PASSWORD
    [SIGNATURE] => PAYPAL_API_SIGNATURE
    [VERSION] => 95
    [url] => https://api-3t.sandbox.paypal.com/nvp
    [METHOD] => DoExpressCheckoutPayment
    [TOKEN] => EC-06N33746DC1035058
    [PAYERID] => HS5JSKPGX4T2G
    [L_PAYMENTREQUEST_0_NAME0] => Om Belt - Black
    [L_PAYMENTREQUEST_0_DESC0] => Obscure Belts
    [L_PAYMENTREQUEST_0_AMT0] => 82.92
    [L_PAYMENTREQUEST_0_QTY0] => 1
    [PAYMENTREQUEST_0_CURRENCYCODE] => USD
    [PAYMENTREQUEST_0_SHIPPINGAMT] => 5.15
    [PAYMENTREQUEST_0_AMT] => 88.07
    [PAYMENTREQUEST_0_ITEMAMT] => 82.92
    [PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID] => receiver_email_address//payment will receive by this paypal email
   
)

When we call DoExpressCheckoutPayment, We will charge the payment from customer Account and an email will be sent to customer and receiver.

Step 7: Check Resonse
Array
(
    [TOKEN] => EC-06N33746DC1035058
    [SUCCESSPAGEREDIRECTREQUESTED] => false
    [TIMESTAMP] => 2014-08-11T12:41:32Z
    [CORRELATIONID] => e5d0b3a5e674a
    [ACK] => Success
    [VERSION] => 95
    [BUILD] => 12301660
    [INSURANCEOPTIONSELECTED] => false
    [SHIPPINGOPTIONISDEFAULT] => false
    [PAYMENTINFO_0_TRANSACTIONID] => 6HD429843V086060C
    [PAYMENTINFO_0_TRANSACTIONTYPE] => cart
    [PAYMENTINFO_0_PAYMENTTYPE] => instant
    [PAYMENTINFO_0_ORDERTIME] => 2014-08-11T12:41:32Z
    [PAYMENTINFO_0_AMT] => 88.07
    [PAYMENTINFO_0_FEEAMT] => 2.85
    [PAYMENTINFO_0_TAXAMT] => 0.00
    [PAYMENTINFO_0_CURRENCYCODE] => USD
    [PAYMENTINFO_0_PAYMENTSTATUS] => Completed
    [PAYMENTINFO_0_PENDINGREASON] => None
    [PAYMENTINFO_0_REASONCODE] => None
    [PAYMENTINFO_0_PROTECTIONELIGIBILITY] => Eligible
    [PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE] => ItemNotReceivedEligible,UnauthorizedPaymentEligible
    [PAYMENTINFO_0_SELLERPAYPALACCOUNTID] => receiver_email_address
    [PAYMENTINFO_0_SECUREMERCHANTACCOUNTID] => UFBX24KTUHJKU
    [PAYMENTINFO_0_ERRORCODE] => 0
    [PAYMENTINFO_0_ACK] => Success
)


Customer can pay with Credit card without Paypal Account

  1. Login to Paypal
  2. Go to Profile subtab
  3. Click on Website Payment Preferences under the Selling Preferences column
  4. Check the yes box under PayPal Account Optional


2 comments: