Set up recurring payments
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.
- Sample request
- 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.
- Sample request
- 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.
Note:
device_manufacturer_id,payment_data_type, andpayment_dataare not applicable for merchant-initiated transactions.previous_transaction_referenceorprevious_network_transaction_referenceis applicable only for merchant-initiated transactions and only one of these can be present in the request.
stored_credential input parameter
| Input parameter | Possible values |
|---|---|
payment_initiator(required) |
|
payment_type(required) |
|
usage |
|
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 |
|
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 |