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 to retrieve your shopper's 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 step from the capture step. This is beneficial for businesses 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:
{
"amount": 100,
"vaultedShopperId": 12345678,
"softDescriptor": "ABC COMPANY",
"currency": "USD",
"paypalTransaction": {
"noShipping": 0,
"cancelUrl": "http://www.cancelURL.com",
"reqConfirmShipping": 1,
"returnUrl": "http://www.returnURL.com"
}
}
{
"merchantTransactionId": "testtransaction1",
"softDescriptor": "ABC COMPANY",
"amount": "100.00",
"currency": "USD",
"payerInfo": {
"firstName": "John",
"lastName": "Doe"
},
"paypalTransaction": {
"transactionType": "AUTH_ONLY",
"returnUrl": "http://www.returnURL.com",
"cancelUrl": "http://www.cancelURL.com",
"maxAmount": "120.00"
}
}
{
"merchantTransactionId": "testtransaction1",
"softDescriptor": "ABC COMPANY",
"amount": "100.00",
"currency": "USD",
"payerInfo": {
"firstName": "John",
"lastName": "Doe"
},
"paypalTransaction": {
"transactionType": "SET_ORDER",
"returnUrl": "http://www.returnURL.com",
"cancelUrl": "http://www.cancelURL.com",
"maxAmount": "120.00"
}
}
These are some important properties of the Create PayPal Transaction request:
PayPal URLs
Within the paypalTransaction object, you will need to specify two different URLs:
returnUrl
: URL where the shopper will be redirected upon completing the PayPal purchase (i.e. your "thank you" page)cancelUrl
: 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 payerInfo object and send the shopper's name, address or other details.
- A vaulted shopper ID: If you have already vaulted the shopper with BlueSnap, you can send the relevant
vaultedShopperId
within the altTransaction object. 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 paypalTransaction object, set the
noShipping
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
reqConfirmShipping
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 inContext
property in the paypalTransaction object 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 altTransaction resource with the request properties plus these additions:
paypalTransaction
is returned with the paypalUrl
and orderId
(see paypalTransaction)
processingInfo
{
"amount": 100,
"vaultedShopperId": 12345678,
"processingInfo": {"processingStatus": "PENDING"},
"softDescriptor": "ABC COMPANY",
"currency": "USD",
"paypalTransaction": {
"paypalUrl": "https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_express-checkout&token=EC-9GY47037JY601890L",
"orderId": 9876543
}
}
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 paypalUrl
field. This is the URL for the checkout page in PayPal where the shopper can complete the purchase. In the example response above, the paypalUrl
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 that he or she can finish 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://www.merchant-site.com/?ERROR=0&INVOICE_ID=1040698351&PAYPAL_TRANSACTION_ID=7D472473PR818573H&SELLER_ORDER_ID=><merchant-transaction-id> Note: In the event of an error from PayPal there will be an exception included as part of the URL |
|
Two-Step Flow | http://www.merchant-site.com/?ERROR=0&PAYPAL_TRANSACTION_ID=&ACCOUNT_ID=35714051&SELLER_ORDER_ID=><merchant-transaction-id> |
Note: You can then use the vaulted shopper ID to perform a Retrieve Vaulted Shopper call, to retrieve the shopper’s information and update the final price accordingly. |
Three-Step Flow | http://www.merchant-site.com/?ERROR=0&PAYPAL_TRANSACTION_ID=BWGL6VEKKCDLY&ACCOUNT_ID=35714091&SELLER_ORDER_ID=><merchant-transaction-id> Note: PAYPAL_TRANSACTION_ID will hold the PayPal payer ID value |
Note: You can then use the vaulted shopper ID to perform a Retrieve Vaulted Shopper call, to retrieve the shopper’s information and update the final price accordingly. |
Note
To secure and validate the PayPal transaction, assign a unique MERCHANT-TRANSACTION-ID to every transaction. Then choose one of the following and code the logic for your
return-url
page:
- Call the Retrieve PayPal Transaction API using the
merchantTransactionId
, and validate the date and amount of the transaction.- Or enable IPNs and code logic to check that an IPN is received for the PayPal transaction with the same
merchantTransactionId
, date, and amount.
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 orderId
from the original transaction, the new price (if applicable), and set the parameter transactionType
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 orderId
from the original transaction, the new price (if applicable), and set the parameter transactionType
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.
{
"amount": "105.00",
"currency": "USD",
"paypalTransaction": {
"orderId": "4006145",
"transactionType": "CAPTURE"
}
}
{
"amount": "105.00",
"currency": "USD",
"paypalTransaction": {
"orderId": "4006145",
"transactionType": "DO_ORDER"
}
}
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 transactionType
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.