Set up recurring payments

DocsLimited

Last updated: Apr 10th, 8:08pm

To set up recurring payments using Google Pay on the Web, integrate Google Pay as a payment method on the checkout page. Refer to the Google Pay Developer Documentation for guidance on adding Google Pay as a payment option.

After buyers authorize the payment, configure your client-side code to invoke the createOrder function in your server-side code to create an order and capture the payment.

For recurring payments, the customer initiates the first payment using the Create Order API. The merchant initiates subsequent transactions after obtaining the buyer's consent to charge them.

Create new order and capture payment

To indicate Google Pay as the payment method, include the google_pay object in the payment_source of the POST v2/checkout/orders request body.

Additionally, include stored_credential to provide details about recurring transactions that include payment_initiator, payment_type and usage.

The following code samples are applicable for Funding Primary Account Number (FPAN) and Tokenized Primary Account Number (TPAN) in Google Pay transactions. The 3D Secure (3DS) flow is initiated, if applicable, based on the request.

Customer-initiated transaction

API endpoint used: Create order

  1. Sample request
  2. Sample response
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 -H 'PayPal-Partner-Attribution-Id: <BN-Code>' \
5 d ' {
6 "intent": "CAPTURE",
7 "purchase_units": [
8 {
9 "reference_id": "REFID-000-1002",
10 "amount": {
11 "currency_code": "USD",
12 "value": "10.00"
13 },
14 "payee": {
15 "merchant_id": "QQCHDN9M6DR9E"
16 },
17 "shipping": {
18 "name": {
19 "full_name": "Firstname Lastname"
20 },
21 "email_address": "payer@example.com",
22 "address": {
23 "address_line_1": "123 Main St",
24 "admin_area_2": "Anytown",
25 "admin_area_1": "CA",
26 "postal_code": "12345",
27 "country_code": "US"
28 }
29 }
30 }
31 ],
32 "payment_source": {
33 "google_pay": {
34 "name": "Firstname Lastname",
35 "email_address": "payer@example.com",
36 "phone_number": {
37 "national_number": "5555555555",
38 "country_code": "1"
39 },
40 "decrypted_token": {
41 "message_id": "cJpaRj8xrSaDA0G37wP6VF9ZC",
42 "message_expiration": "2935761295444",
43 "payment_method": "CARD",
44 "card": {
45 "name": "John Doe",
46 "number": "376680816376962",
47 "expiry": "2027-12",
48 "brand": "AMEX",
49 "billing_address": {
50 "address_line_1": "2211 N 1st St",
51 "address_line_2": "Building 15",
52 "admin_area_2": "San Jose",
53 "admin_area_1": "CA",
54 "postal_code": "95131",
55 "country_code": "US"
56 }
57 },
58 "authentication_method": "CRYPTOGRAM_3DS",
59 "cryptogram": "SaDA0Gw9cR37j8xrZP6VFCJpa",
60 "eci_indicator": "07"
61 },
62 "assurance_details": {
63 "account_verified": true,
64 "card_holder_authenticated": false
65 },
66 "attributes": {
67 "verification": {
68 "method": "SCA_WHEN_REQUIRED"
69 }
70 },
71 "stored_credential": {
72 "payment_type": "RECURRING",
73 "payment_initiator": "CUSTOMER",
74 "usage": "FIRST"
75 }
76 }
77 }
78},

Copy the code snippet and modify the values for stored_credential as needed.

Step result

A successful request results in the following:

  • A return status code of HTTP 201 Created.
  • A JSON response body that contains the processor response.

Merchant-initiated transaction

API endpoint used: Create order

  1. Sample request
  2. Sample response
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 -H 'PayPal-Partner-Attribution-Id: <BN-Code>' \
5 d ' {
6 "intent": "CAPTURE",
7 "purchase_units": [
8 {
9 "reference_id": "REFID-000-1001",
10 "amount": {
11 "currency_code": "USD",
12 "value": "10.00"
13 },
14 "payee": {
15 "merchant_id": "QQCHDN9M6DR9E"
16 },
17 "shipping": {
18 "name": {
19 "full_name": "Firstname Lastname"
20 },
21 "email_address": "payer@example.com",
22 "address": {
23 "address_line_1": "123 Main St",
24 "admin_area_2": "Anytown",
25 "admin_area_1": "CA",
26 "postal_code": "12345",
27 "country_code": "US"
28 }
29 }
30 }
31 ],
32 "payment_source": {
33 "google_pay": {
34 "name": "Firstname Lastname",
35 "email_address": "payer@example.com",
36 "phone_number": {
37 "national_number": "5555555555",
38 "country_code": "1"
39 },
40 "decrypted_token": {
41 "message_id": "cJpaRj8xrSaDA0G37wP6VF9ZC",
42 "message_expiration": "2935761295444",
43 "payment_method": "CARD",
44 "card": {
45 "name": "John Doe",
46 "number": "376680816376962",
47 "expiry": "2027-12",
48 "brand": "AMEX",
49 "billing_address": {
50 "address_line_1": "2211 N 1st St",
51 "address_line_2": "Building 15",
52 "admin_area_2": "San Jose",
53 "admin_area_1": "CA",
54 "postal_code": "95131",
55 "country_code": "US"
56 }
57 }
58 },
59 "stored_credential": {
60 "payment_type": "RECURRING",
61 "payment_initiator": "MERCHANT",
62 "usage": "SUBSEQUENT",
63 "previous_transaction_reference": "0D026078A2978501F"
64 }
65 }
66 }
67},

Copy the code snippet and modify the values for stored_credential as needed.

Step result

A successful request results in the following:

  • A return status code of HTTP 201 Created.
  • A JSON response body that contains the processor response.

stored_credential input parameter

Input parameter Possible values
payment_initiator
(required)
  • CUSTOMER: Customer initiates the payment. Used for the initial transaction to sign up for the recurring charges.
  • MERCHANT: The merchant initiates the transaction. Used for subsequent transactions initiated by the merchant where the merchant has established consent to charge the buyer.
payment_type
(required)
  • UNSCHEDULED: Payments that the merchant initiates and are not on a specified schedule. For example, this includes preauthorized transactions where the merchant can charge the buyer after a balance falls within a specified range. These transactions are also called as top-ups.
  • RECURRING: The Merchant initiates a payment as part of recurring payments. The payment amounts can be variable and are on a fixed time interval.
  • ONE_TIME: Default when no stored_credential is sent.
usage
  • FIRST: Payment method information is used for the initial transaction to sign up for the recurring charges.
  • SUBSEQUENT: Payment method information was previously used in the transaction.
  • DERIVED: PayPal derives the value of FIRST or SUBSEQUENT based on data available to PayPal.
previous_transaction_reference PayPal transaction ID previously used to charge the buyer. Shows payment processors that you have established a contract with the buyer.
previous_network_transaction_reference
  • id (required): Transaction ID from a non-PayPal payment processor that you previously used to process the payment.
  • network: Name of the card network through which the transaction was routed.

Use cases

You can use these common scenarios to determine how you'll update your integration.


Recurring plan or subscriptions

Scenario Payment initiator Payment type Usage
Initial transaction to sign up for the recurring charges. Buyer has approved to save or has already saved their card with the merchant. CUSTOMER RECURRING FIRST
Merchant processes recurring charge with PayPal. MERCHANT RECURRING SUBSEQUENT


Unscheduled payments

Scenario Payment initiator Payment type Usage
Initial transaction to sign up for the unscheduled charges. Buyer has approved to save or has already saved their card with the merchant. CUSTOMER UNSCHEDULED FIRST
Merchant processes recurring charge with PayPal. MERCHANT UNSCHEDULED SUBSEQUENT