Learn how to work with PayPal in BlueSnap's Payment API
This guide describes how to use the Payment API to process PayPal transactions. For a general overview of our PayPal offering go here.
See:
Using PayPal for merchant-managed subscriptions
If you are managing subscriptions yourself (or through a third party) and want to offer the PayPal payment method for recurring subscription payments, this option is also available via the Payment API. For a tutorial, see Processing merchant-managed PayPal subscription payments.
Prerequisites
PayPal account
To offer PayPal as a payment option for your shoppers, you must have a PayPal Business or Premier account. If you do not yet have a PayPal account, you can sign up for one on the PayPal website.
Connecting your PayPal account with BlueSnap
To use PayPal with BlueSnap, begin by connecting your PayPal and BlueSnap accounts. For instructions, see Connecting PayPal and BlueSnap.
Processing PayPal transactions
PayPal checkout options
Standard Re-direct/One-Step flow: This is the standard PayPal flow that directs your shopper to a PayPal page to confirm the purchase.
Two-Step Flow: The objective of the two-step flow is to provide the ability retrieve your shoppers address from their PayPal wallet and then include any necessary taxes and/or fees based on their location.
Three-Step Flow: The objective of the three-step flow is to separate the authorization from the capture step. This is beneficial for business who may not have the goods on hand at the time of the sale.
- Step 1:Build and send the Create PayPal Transaction request
- Step 2: Response to the Create PayPal Transaction request & possible errors
- Step 3: Redirect the shopper to the PayPal URL
- Step 4: Shopper is redirected to a confirmation page
- Step 5: Complete the process or create pending authorization
- Step 6: Complete the transaction by sending capture with final amount
Step 1: Build and send the Create PayPal Transaction request
When the shopper selects the PayPal checkout option, you will use the Create PayPal Transaction request to process the PayPal payment. The transaction-type
should be AUTH/CAPTURE or omitted for the standard re-direct, AUTH_ONLY for the two-step flow, and SET_ORDER for the three step flow.
The request should be sent to the services/2/alt-transactions
endpoint. Following is an example request:
<?xml version="1.0" encoding="UTF-8"?>
<alt-transaction xmlns="http://ws.plimus.com">
<merchant-transaction-id>testtransaction1</merchant-transaction-id>
<soft-descriptor>ABC COMPANY</soft-descriptor>
<amount>100.00</amount>
<currency>USD</currency>
<payer-info>
<first-name>John</first-name>
<last-name>Doe</last-name>
</payer-info>
<paypal-transaction>
<transaction-type>AUTH/CAPTURE</transaction-type>
<return-url>http://www.returnURL.com</return-url>
<cancel-url>http://www.cancelURL.com</cancel-url>
<max-amount>120.00</max-amount>
</paypal-transaction>
</alt-transaction>
<?xml version="1.0" encoding="UTF-8"?>
<alt-transaction xmlns="http://ws.plimus.com">
<merchant-transaction-id>testtransaction1</merchant-transaction-id>
<soft-descriptor>ABC COMPANY</soft-descriptor>
<amount>100.00</amount>
<currency>USD</currency>
<payer-info>
<first-name>John</first-name>
<last-name>Doe</last-name>
</payer-info>
<paypal-transaction>
<transaction-type>AUTH_ONLY</transaction-type>
<return-url>http://www.returnURL.com</return-url>
<cancel-url>http://www.cancelURL.com</cancel-url>
<max-amount>120.00</max-amount>
</paypal-transaction>
</alt-transaction>
<?xml version="1.0" encoding="UTF-8"?>
<alt-transaction xmlns="http://ws.plimus.com">
<merchant-transaction-id>testtransaction1</merchant-transaction-id>
<soft-descriptor>ABC COMPANY</soft-descriptor>
<amount>100.00</amount>
<currency>USD</currency>
<payer-info>
<first-name>John</first-name>
<last-name>Doe</last-name>
</payer-info>
<paypal-transaction>
<transaction-type>SET_ORDER</transaction-type>
<return-url>http://www.returnURL.com</return-url>
<cancel-url>http://www.cancelURL.com</cancel-url>
<max-amount>120.00</max-amount>
</paypal-transaction>
</alt-transaction>
These are some important properties of the Create PayPal Transaction request:
PayPal URLs
Within the paypal-transaction resource, you will need to specify two different URLs:
return-url
: URL where the shopper will be redirected upon completing the PayPal purchase (i.e. your "thank you" page)cancel-url
: URL where the shopper will be redirected if cancelling the PayPal purchase.
Shopper information
You can send the request with any of the following:
- No information about the shopper: For example, if it is a new or guest shopper, you can keep the request simple and not include any shopper details.
- Some information about the shopper: For example, if you would like to use some of the shopper's info in order to customize the thank you page, then you can include the payer-info resource and send the shopper's name, address or other details in that resource.
- A vaulted shopper ID: If you have already vaulted the shopper with BlueSnap, you can send the relevant
vaulted-shopper-id
within the alt-transaction resource. If you collect the shipping info from PayPal, then this will also be automatically updated in the vaulted shopper's profile in BlueSnap.
See Create PayPal Transaction for examples of each of the above options.
Shipping details from PayPal (for vaulted shoppers)
If you send a vaulted shopper in your Create PayPal Transaction request, you can retrieve the shopper's shipping details from PayPal. If you do so, then the vaulted shopper's record in BlueSnap will be automatically updated with the new shipping details from PayPal. To retrieve shipping info from PayPal for a vaulted shopper:
-
In the paypal-transaction resource, set the
no-shipping
property to 0 -
If you only want the shipping info to be retrieved if it has been specifically confirmed by the shopper in PayPal, then you should also include the
req-confirm-shipping
property, with the value set to 1. -
Note: This feature is not available if BlueSnap collects US sales tax or EU VAT for you.
Retrieving the shopper's phone number
The shopper’s phone number will not be automatically retrieved. If you are specifically interested in retrieving the phone number, please ensure you configure the Contact Telephone Number setting to Off. This setting is in your PayPal account under My Account > Profile > My selling tools > Website Preferences.
In-Context checkout
If you would like to enable In-Context PayPal checkout, set the in-context
property in the paypal-transaction resource to true.
For more information about the shopper experience with PayPal, click here.
Step 2: Response to the Create PayPal Transaction request & possible errors
If successful, the response HTTP status code is 200 OK.
The response contains an alt-transaction resource with the request properties plus these additions:
paypal-transaction
is returned with the paypal-url
and order-id
(see paypal-transaction)
processing-info
HTTP/ 1.1 200 OK
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<alt-transaction xmlns="http://ws.plimus.com">
<soft-descriptor>ABC COMPANY</soft-descriptor>
<amount>100.00</amount>
<currency>USD</currency>
<vaulted-shopper-id>12345678</vaulted-shopper-id>
<paypal-transaction>
<paypal-url>https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_express-checkout&token=EC-9GY47037JY601890L</paypal-url>
<order-id>9876543</order-id>
</paypal-transaction>
<processing-info>
<processing-status>PENDING</processing-status>
</processing-info>
</alt-transaction>
Otherwise, any of the Alt Transaction Errors related to PayPal may occur.
Step 3: Redirect the shopper to the PayPal URL
The response includes a paypal-url
field. This is the URL for the checkout page in PayPal where the shopper can complete the purchase. In the example response above, the paypal-url
is:
https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_express-checkout&token=EC-9GY47037JY601890L
When you receive the response, you should redirect the shopper to this URL so they can continue the checkout process in PayPal.
Step 4: Shopper is redirected to a confirmation page
Standard Checkout Flow: Upon completing checkout in PayPal, the shopper is automatically sent to the "thank you" page you indicated in the return-url
field in the Create PayPal Transaction request. On this page, you may wish to display the PayPal order number and other details about the purchase.
Two & Three Step Flows: Upon completion in PayPal, the shopper is automatically sent to the final confirmation page indicated in the return-url
field in the Create PayPal Transaction request.
The return URL will contain additional parameters that you can use to display to your shoppers.
PayPal flow | URL example | Parameters included |
---|---|---|
Standard redirect | http://merchant-site.com/paypal-success?ERROR=0&INVOICE_ID=987654&PAYPAL_TRANSACTION_ID=9M8R7X6LYE7P4&MERCHANT-TRANSACTION-ID=null Note: In the event of an error from PayPal there will be an exception included as part of the URL | PayPal error (success or error code), Invoice_ID (BlueSnap’s Invoice-ID), PayPal Transaction ID, and merchant-transaction-id (your own transaction ID) |
Two-step flow & Three-step flow | http://merchant-site.com/paypal-success?ERROR=0&PAYPAL_TRANSACTION_ID=9M8R7X6LYE7P4&VAULTED-SHOPPER-ID=19598172&MERCHANT-TRANSACTION-ID=null | PayPal (success or error code), vaulted-shopper-id (BlueSnap’s Shopper ID), and merchant-transaction-id (your own transaction ID) Note: You can then do a Retrieve Vaulted Shopper call, with the vaulted shopper ID, to retrieve the shopper’s information and to update the final price accordingly. |
Step 5: Complete the process or Create Pending Authorization
Standard Checkout Flow: Step 5 is not applicable when using the PayPal standard flow.
Two-Step Flow: To finalize this order and have the payment processed, you must send an Update PayPal Transaction request with the order-id
from the original transaction, the new price (if applicable), and set the parameter transaction-type
to capture.
You can now redirect your shopper to a final thank you page confirming transaction details.
Three-Step flow: In the previous step you presented your shopper with the final amount including any additional charges. You now need to create an Update PayPal Transaction request, with the order-id
from the original transaction, the new price (if applicable), and set the parameter transaction-type
to DO_ORDER. This will create a pending authorization on your shopper's PayPal account for the actual amount including a new charges.
Later on, when you are ready to deliver the goods/services, you will need to create a new Update PayPal Transaction request to complete the order.
Note: A pending authorization can be left open several weeks.
If there were additional charges, you will need to modify the amount
parameter with the final amount you wish to charge.
<?xml version="1.0" encoding="UTF-8"?>
<alt-transaction xmlns="http://ws.plimus.com">
<amount>105.00</amount>
<currency>USD</currency>
<paypal-transaction>
<order-id>4006145</order-id>
<transaction-type>CAPTURE</transaction-type>
</paypal-transaction>
</alt-transaction>
<?xml version="1.0" encoding="UTF-8"?>
<alt-transaction xmlns="http://ws.plimus.com">
<amount>105.00</amount>
<currency>USD</currency>
<paypal-transaction>
<order-id>4006145</order-id>
<transaction-type>DO_ORDER</transaction-type>
</paypal-transaction>
</alt-transaction>
Step 6: Complete the transaction by sending capture with final amount
Three-Step flow: When the goods/services are ready to be delivered and you have informed your customer you will debiting the final amount from their PayPal account. You now need to send a final Update PayPal Transaction request to complete the transaction and move it from a pending authorization to a captured charge.
To accomplish this you will need to change the value of the transaction-type
parameter from DO_ORDER to CAPTURE.
It is still possible to modify this final amount once more, but please make sure the shopper is aware of the final amount being charged and that they have received an updated receipt/invoice.
<?xml version="1.0" encoding="UTF-8"?>
<alt-transaction xmlns="http://ws.plimus.com">
<amount>104.00</amount>
<currency>USD</currency>
<paypal-transaction>
<order-id>4006145</order-id>
<transaction-type>CAPTURE</transaction-type>
</paypal-transaction>
</alt-transaction>