Save PayPal with the Orders API

CurrentLast updated: November 7th 2023, @ 9:47:43 am


After customers save their PayPal Wallet, they can select it for faster checkout. Customers won't have to enter payment details for future transactions.

You can use the Orders API to create a transaction and save the payer's PayPal Wallet.

Use a direct integration with the Orders API if you:

  • Are PCI compliant when capturing and passing card information.
  • Have opted not to integrate with a PayPal client-side JavaScript SDK and want to make a purchase and save the instrument used.

To save a payment method outside of a purchase, use the Vault Payment Method API.

Availability

  • Australia
  • Austria
  • Belgium
  • Bulgaria
  • Canada
  • China
  • Cyprus
  • Czech Republic
  • Denmark
  • Estonia
  • Finland
  • France
  • Germany
  • Hong Kong
  • Hungary
  • Ireland
  • Italy
  • Japan
  • Latvia
  • Liechtenstein
  • Lithuania
  • Luxembourg
  • Malta
  • Netherlands
  • Norway
  • Poland
  • Portugal
  • Romania
  • Singapore
  • Slovakia
  • Slovenia
  • Spain
  • Sweden
  • United Kingdom
  • United States

Know before you code

  • The Orders API supports saving PayPal and card payment methods only.
  • You must be approved to enable a reference transaction if you want to save PayPal as a payment source. Contact your account manager for details.

How it works

When a payer on your website saves their payment method, PayPal creates a customer record. PayPal then encrypts the payment method information and stores it in a digital vault. The vault is accessible only by the billing agreement holder.

  1. The payer saves their payment method.
  2. For a first-time payer, PayPal creates a customer ID. Store this within your system for future use.
  3. Pass a call into the Orders API. Include the payment method, customer ID, and an indication that the payment method should be saved.
  4. If the order is processed and the payment method is saved, you receive a payment method token in the Orders API response.
  5. Pass the payment method token into the Orders API to populate the checkout page with the saved payment method.

The checkout process is now shorter because it uses saved payment information.

Check eligibility

  1. Go to paypal.com and sign in with your business account.
  2. Go to Account Settings > Payment Preferences > Save PayPal and Venmo payment methods.
  3. In the Save PayPal and Venmo payment methods section, select Get Started.
  4. When you submit profile details, PayPal reviews your eligibility to save PayPal Wallets and Venmo accounts.
  5. After PayPal reviews your eligibility, you'll see a status of Success, Need more information, or Denied.

Set up your account to save payments

Set up your sandbox and live business accounts to save payment methods:

  1. Log in to the Developer Dashboard.
  2. Under REST API apps, select your app name.
  3. Under Sandbox App Settings > App Feature Options, check Accept payments.
  4. Expand Advanced options. Confirm that Vault is selected.

Server side

Set up your server to call the Create Order API. The button that the payer selects determines the payment_source sent in the following sample. In the following sample, the payment_source is PayPal. The vault parameters in the request saves the payment_source for future use by the payer.

Request to create order and save PayPal

1curl -v -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders/ \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer ACCESS-TOKEN" \
4 -d '{
5 "intent": "CAPTURE",
6 "payment_source": {
7 "paypal": {
8 "attributes": {
9 "vault": {
10 "store_in_vault": "ON_SUCCESS",
11 "usage_type": "MERCHANT"
12 }
13 },
14 "experience_context": {
15 "return_url": "https://example.com/returnUrl",
16 "cancel_url": "https://example.com/cancelUrl"
17 }
18 }
19 },
20 "purchase_units": [
21 {
22 "amount": {
23 "currency_code": "USD",
24 "value": "100.00"
25 }
26 }
27 ]
28 }'

Response

Note the status of the response. Some payment sources need payer approval before payment. If so, return the id back to your client to redirect the payer to a flow where they approve the payment method.

1{
2 "id": "46299262185816041",
3 "status": "PAYER_ACTION_REQUIRED",
4 "payment_source": {
5 "paypal": {}
6 },
7 "links": [{
8 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/46299262185816041",
9 "rel": "self",
10 "method": "GET",
11 },
12 {
13 "href": "https://www.sandbox.paypal.com/checkoutnow?token=46299262185816041",
14 "rel": "approve",
15 "method": "GET",
16 }
17 ]
18}

Payer approval

After the control passes to the client SDK, the SDK calls the payer approval flow. The flow launches a window that takes the payer through PayPal checkout.

Authorize or capture order

After the payer approves, your server should call the following APIs:

  • Capture Order API if the intent passed was CAPTURE.
  • Authorize Order API if the intent passed was AUTHORIZE.

Request

  1. Authorize
  2. Capture
1curl -v -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders/5O190127TN364715T/authorize \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer ACCESS-TOKEN" \
4 -d '{}'

Response

The HTTP response codes HTTP 2xx or HTTP 200 are returned for a successful request.

The capture is successful if the purchase_units[0].payments.captures.status is COMPLETED. You can confirm with the payer that the payment has been captured.

1{
2 {
3 "id": "9YF83379T2523751N",
4 "status": "COMPLETED",
5 "payment_source": {
6 "paypal": {
7 "email_address": "email@example.com",
8 "account_id": "AJM9JTWQJCFTA",
9 "name": {
10 "given_name": "Firstname",
11 "surname": "Lastname"
12 },
13 "address": {
14 "country_code": "US"
15 },
16 "attributes": {
17 "vault": {
18 "id": "nkq2y9g",
19 "customer": {
20 "id" = "ROaPMoZUaV"
21 },
22 "status": "VAULTED",
23 "links": [{
24 "href": "https://api-m.sandbox.paypal.com/v3/vault/payment-tokens/64n9c42",
25 "rel": "self",
26 "method": "GET"
27 },
28 {
29 "href": "https://api-m.sandbox.paypal.com/v3/vault/payment-tokens/64n9c42",
30 "rel": "delete",
31 "method": "DELETE"
32 },
33 {
34 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/9YF83379T2523751N",
35 "rel": "up",
36 "method": "GET"
37 }
38 ]
39 }
40 }
41 }
42 },
43 "purchase_units": [{
44 "reference_id": "default",
45 "shipping": {
46 "name": {
47 "full_name": "Firstname Lastname"
48 },
49 "address": {
50 "address_line_1": "1 Main St",
51 "admin_area_2": "San Jose",
52 "admin_area_1": "CA",
53 "postal_code": "95131",
54 "country_code": "US"
55 }
56 },
57 "payments": {
58 "captures": [{
59 "id": "9LY87817BF120310A",
60 "status": "COMPLETED",
61 "amount": {
62 "currency_code": "USD",
63 "value": "100.00"
64 },
65 "final_capture": true,
66 "seller_protection": {
67 "status": "ELIGIBLE",
68 "dispute_categories": [
69 "ITEM_NOT_RECEIVED",
70 "UNAUTHORIZED_TRANSACTION"
71 ]
72 },
73 "seller_receivable_breakdown": {
74 "gross_amount": {
75 "currency_code": "USD",
76 "value": "100.00"
77 },
78 "paypal_fee": {
79 "currency_code": "USD",
80 "value": "3.98"
81 },
82 "net_amount": {
83 "currency_code": "USD",
84 "value": "96.02"
85 }
86 },
87 "links": [{
88 "href": "https://api-m.sandbox.paypal.com/v2/payments/captures/9LY87817BF120310A",
89 "rel": "self",
90 "method": "GET"
91 },
92 {
93 "href": "https://api-m.sandbox.paypal.com/v2/payments/captures/9LY87817BF120310A/refund",
94 "rel": "refund",
95 "method": "POST"
96 },
97 {
98 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/9YF83379T2523751N",
99 "rel": "up",
100 "method": "GET"
101 }
102 ],
103 "create_time": "2022-08-12T18:16:42Z",
104 "update_time": "2022-08-12T18:16:42Z"
105 }]
106 }
107 }],
108 "payer": {
109 "name": {
110 "given_name": "Firstname",
111 "surname": "Lastname"
112 },
113 "email_address": "email@example.com",
114 "payer_id": "AJM9JTWQJCFTA",
115 "address": {
116 "country_code": "US"
117 }
118 },
119 "links": [{
120 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/9YF83379T2523751N",
121 "rel": "self",
122 "method": "GET"
123 }]
124 }

In the response from the Authorize or Capture request, the Orders v2 API interacts with the Vault v3 API. The Vault v3 API allows a PayPal Wallet to be saved. The response from the Orders v2 API contains the:

  • vault.id.
  • vault.status.
  • links for the payment token of a recently vaulted PayPal Wallet.

Check Orders API response

Saving a payment source doesn't require the payer to be present after the payment has been authorized or captured. To keep checkout times as short as possible for payers, the Orders API returns a response as soon as a payment is captured.

Payment may be authorized or captured and a successful response returned from the Orders API without the provided payment_source being saved. In this scenario, the response returns the attributes.vault.status as "APPROVED", instead of "VAULTED".

An example of the attributes object from this scenario is included in the following sample:

1"attributes": {
2 "vault": {
3 "status": "APPROVED",
4 "links": [
5 {
6 "href": "https://api-m.sandbox.paypal.com/v2/checkout/orders/5O190127TN364715T",
7 "rel": "up",
8 "method": "GET"
9 }
10 ]
11 }
12 }

Webhooks for saving payment methods

You can configure and subscribe to the VAULT.PAYMENT-TOKEN.CREATED webhook, which is generated when saving payment methods with the Orders API.

You'll receive a vault_id when an APPROVED status is returned.

EventTriggerPayment methods
VAULT.PAYMENT-TOKEN.CREATEDA payment token is created to save a payment method.Cards and PayPal
VAULT.PAYMENT-TOKEN.DELETEDA payment token is deleted. The payer's payment method is no longer saved to the PayPal vault.Cards and PayPal
VAULT.PAYMENT-TOKEN.DELETION-INITIATEDA request to delete a payment token has been submitted to the Payment Method Tokens API.PayPal

For more information on webhooks, see webhooks.

Next step

Follow Use payment method token with checkout for subsequent or recurring transactions.

See also

Payment Method Token API errors