29 NEXT
Search…
PayPal Admin API Guide
Implement PayPal on custom checkouts via the API
PayPal is a fully integrated payment app that is supported both in the storefront checkout, and via the Admin API. PayPal transactions send the customer through a PayPal redirect flow, with the resulting order information provided back to your application. Below are the steps needed to get PayPal set up and working on the Admin API.
Important - PayPal custom checkouts require the use of the PayPal NVP/SOAP (Legacy) APIs. Please ensure that your valid NVP/SOAP credentials are configured in the Paypal Extension prior to attempting custom checkouts with PayPal over the Admin API.
For custom PayPal checkouts, there are two checkout flows available -- the standard method where a user enters their shipping address, chooses products, and then checks out via PayPal; and the "One-Click" method, where the user is not required to enter shipping information before being redirected to PayPal checkout.

Standard PayPal Checkout Flow

Step 1 - Create Order on Admin API with PayPal as Payment Method

When creating a new order using PayPal using the orders_create API method, you must specify the payment_method=paypal as well as provide a payment_return_url. The payment_return_url is your endpoint that will receive a POST request containing the final order data (in Step 3).
1
{
2
"payment_method": "paypal",
3
"payment_details": {
4
"payment_return_url": "<YOUR APPLICATION ENDPOINT>"
5
}
Copied!

Step 2 - Redirect Customer to PayPal

The response from Step 1 will provide a payment_complete_url. Your application should redirect the customer to this URL for completing the payment on PayPal.
1
{
2
"reference_transaction_id": "<Unique Transactions ID>",
3
"payment_complete_url": "https://www.paypal.com/checkoutnow?token=PAYPALTOKEN"
4
}
Copied!

Step 3 - Receive Order Data

After the customer has completed their purchase on PayPal, they will be redirected to your application with a POST request containing data in the response key of all the order information as a string. See examples below. Example parsing the data
1
""""
2
Order json data is stored in a variable called response.
3
If the order data is an empty dictionary {}, it means
4
payment collection was unsuccessful and order was not created.
5
"""
6
import json
7
8
def my_view(request):
9
data = json.loads(request.POST.get("response"))
10
...
11
return HttpResponse(status=201)
Copied!
Example Order data
1
{
2
"number": "109405",
3
"status": "Confirmed",
4
"lines": [
5
{
6
"product": {
7
"id": 22,
8
"categories": [
9
10
],
11
"product_class": null,
12
"images": [
13
{
14
"id": 27,
15
"original": "https://mystore.net/media/images/products/2020/02/product_image.png",
16
"caption": "",
17
"display_order": 0,
18
"date_created": "2019-05-14T12:56:24.991823+07:00"
19
}
20
],
21
"title": "Skin Care Cream",
22
"upc": ""
23
},
24
"stockrecord": {
25
"id": 23,
26
"partner_sku": "TESTSKU23",
27
"price_currency": "USD",
28
"points_price": null,
29
"price_excl_tax": "56.00",
30
"price_retail": "89.00",
31
"cost_price": "10.00",
32
"num_in_stock": 1000,
33
"low_stock_threshold": 100
34
},
35
"quantity": 1,
36
"price_currency": "USD",
37
"price_excl_tax": "19.99",
38
"price_incl_tax": "19.99",
39
"price_incl_tax_excl_discounts": "19.99",
40
"price_excl_tax_excl_discounts": "19.99"
41
}
42
],
43
"shipping_incl_tax": "5.00",
44
"shipping_method": "Default shipping",
45
"shipping_code": "default-shipping",
46
"total_incl_tax": "69.99",
47
"currency": "USD",
48
"total_excl_tax": "69.99",
49
"shipping_excl_tax": "5.00",
50
"user": {
51
"id": 577,
52
"email": "[email protected]",
53
"first_name": "John",
54
"last_name": "Smith",
55
"phone_number": null
56
},
57
"shipping_address": {
58
"id": 9658,
59
"country": "US",
60
"title": "",
61
"first_name": "John",
62
"last_name": "Smith",
63
"line1": "2200 Testing Lane",
64
"line2": "PO Box 404",
65
"line3": "",
66
"line4": "Hoptown",
67
"postcode": "33635",
68
"phone_number": "+1937567889",
69
"notes": "",
70
"state": "FL"
71
},
72
"billing_address": null,
73
"date_placed": "2020-10-01T16:00:25.238490+07:00",
74
"payment_sources": [
75
{
76
"source_type": {
77
"name": "Paypal",
78
"code": "paypal"
79
}
80
}
81
],
82
"offer_discounts": [
83
84
],
85
"voucher_discounts": [
86
87
],
88
"attribution": null,
89
"tags": [
90
91
],
92
"subscriptions": [
93
94
],
95
"metadata": {
96
97
},
98
"transactions": [
99
{
100
"partner_transaction_id": "<Unique Transaction ID>",
101
"txn_type": "Debit",
102
"currency": "USD",
103
"amount": "69.99"
104
}
105
]
106
}
Copied!
Important - To use the add-line-items API to add additional items to an order after the initial purchase (one-click upsells), you must have Reference Transactions enabled in your PayPal account and PayPal extension settings
Reference Transactions must be enabled by a request to your PayPal account manager. They cannot be enabled without PayPal's direct approval.

"One Click" PayPal Checkout Flow

The One Click PayPal flow sends customers from your custom checkout directly to PayPal, without having to collect shipping address or other customer details first.
When creating a One Click PayPal checkout over the Admin API with the orders_create method, you do not need to specify the user (customer), the billing or shipping addresses, the shipping method, or other details -- these will be posted back from PayPal upon the completion of the checkout.

Step 1 - Create Order on Admin API with PayPal as Payment Method

You are required to specify the product, price, and set the payment_method=paypal as well as provide a payment_return_url. The payment_return_url is your endpoint that will receive a POST request containing the final order data.
Below is an example of the minimum required data to initiate a PayPal One Click checkout.
1
{
2
"lines": [
3
{
4
"sku": "TESTSKU23",
5
"quantity": 1,
6
"currency": "USD",
7
"price": "22.55"
8
}
9
],
10
"payment_method": "paypal",
11
"payment_details": {
12
"payment_return_url": "<YOUR APPLICATION ENDPOINT>"
13
}
14
}
Copied!

Step 2 - Redirect Customer to PayPal

The response from Step 1 will provide a payment_complete_url. Your application should redirect the customer to this URL for completing their payment on PayPal.
1
{
2
"reference_transaction_id": "<Unique Transactions ID>",
3
"payment_complete_url": "https://www.paypal.com/checkoutnow?token=PAYPALTOKEN"
4
}
Copied!
Once redirected to PayPal, the Customer will be prompted to select from their existing billing methods, specify shipping address, and preferred shipping method according to your store's available options. The selected values will be returned in Step 3 order data upon completion of the purchase.
Sales Tax Calculation The PayPal One Click checkout does not require the customer to specify a shipping address before being redirected. Therefore, when they select their preferred shipping address from their PayPal account (usually used for sales tax calculation), PayPal will automatically callback to 29 Next to calculate applicable taxes in real-time.
This is applicable only for stores with Sales Tax or AvaTax enabled.

Step 3 - Receive Order Data

After the customer has completed their purchase on PayPal, they will be redirected to your application with a POST request containing data in the response key of all the order information as a string. See examples below. Example parsing the data
1
""""
2
Order json data is stored in a variable called response.
3
If the order data is an empty dictionary {}, it means
4
payment collection was unsuccessful and order was not created.
5
"""
6
import json
7
8
def my_view(request):
9
data = json.loads(request.POST.get("response"))
10
...
11
return HttpResponse(status=201)
Copied!
Important - To use the add-line-items API to add additional items to an order after the initial purchase (one-click upsells), you must have Reference Transactions enabled in your PayPal account and PayPal extension settings.
Reference Transactions must be enabled by a request to your PayPal account manager. They cannot be enabled without PayPal's direct approval.
Last modified 1mo ago