Set up recurring payments

DocsLimited

Last updated: Apr 10th, 8:29pm

To set up recurring payments using Apple Pay on the Web, integrate Apple Pay as a payment method on the checkout page. Refer to the Apple Pay Developer Documentation for guidance on adding Apple 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 Apple Pay as the payment method, include the apple_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.

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 }
18 ],
19 "payment_source": {
20 "apple_pay": {
21 "id": "021338536138619246596C1DDF7025C3B349CF48E35BECFA8C4F879BE5AED13F",
22 "name": "John Doe",
23 "email_address": "johndoe@gmail.com",
24 "decrypted_token": {
25 "transaction_amount": {
26 "currency_code": "USD",
27 "value": "10.00"
28 },
29 "tokenized_card": {
30 "number": "5491281334659506",
31 "expiry": "2028-03",
32 "billing_address": {
33 "address_line_1": "2211 N 1st St",
34 "address_line_2": "Building 15",
35 "admin_area_2": "San Jose",
36 "admin_area_1": "CA",
37 "postal_code": "95131",
38 "country_code": "US"
39 }
40 },
41 "device_manufacturer_id": "050110030273",
42 "payment_data_type": "3DSECURE",
43 "payment_data": {
44 "cryptogram": "AECVdCK4YqjIABDuAaOCAoABFA==",
45 "emv_data": "emv_data"
46 },
47 "stored_credential": {
48 "payment_type": "RECURRING",
49 "payment_initiator": "CUSTOMER",
50 "usage": "FIRST"
51 }
52 }
53 }
54 }
55},

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-1002",
10 "amount": {
11 "currency_code": "USD",
12 "value": "10.00"
13 },
14 "payee": {
15 "merchant_id": "QQCHDN9M6DR9E"
16 }
17 }
18 ],
19 "payment_source": {
20 "apple_pay": {
21 "id": "021338536138619246596C1DDF7025C3B349CF48E35BECFA8C4F879BE5AED13F",
22 "name": "John Doe",
23 "email_address": "johndoe@gmail.com",
24 "decrypted_token": {
25 "transaction_amount": {
26 "currency_code": "USD",
27 "value": "10.00"
28 },
29 "tokenized_card": {
30 "number": "5491281334659506",
31 "expiry": "2028-03",
32 "billing_address": {
33 "address_line_1": "2211 N 1st St",
34 "address_line_2": "Building 15",
35 "admin_area_2": "San Jose",
36 "admin_area_1": "CA",
37 "postal_code": "95131",
38 "country_code": "US"
39 }
40 },
41 "stored_credential": {
42 "payment_type": "RECURRING",
43 "payment_initiator": "MERCHANT",
44 "usage": "SUBSEQUENT",
45 "previous_transaction_reference": "0D026078A2978501F"
46 }
47 }
48 }
49 }
50},

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