---
# System prepended metadata

title: ApplePay recurring merchant integration

---

# ApplePay recurring merchant integration

ApplePay one time payment devdoc -> https://hackmd.io/RVV4eSn-Sse_sUFOS_YD2w

Changes to enable "**vault with purchase**".
## Customer Initiated Transaction (CIT)
### Create Order Request
```json
{
  "intent": "AUTHORIZE",
  "purchase_units": [
    {
      "reference_id": "d9f80740-38f0-11e8-b467-0ed5f89f718b",
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ],
  "payment_source": {
    "apple_pay": {
      "attributes": {
        "customer": {
          "id": "wxj1234"
        },
        "vault": {
          "store_in_vault": "ON_SUCCESS"
        }
      },
      "stored_credential": {
        "payment_initiator": "CUSTOMER",
        "payment_type": "RECURRING",
        "usage": "FIRST"
      }
    }
  }
}
```

### Create ApplePay Session
``` javascript
// Note: the `applepayConfig` object in this request is the response from `paypal.Applepay().config()`.
const paymentRequest = {
  countryCode: applepayConfig.countryCode, 
  merchantCapabilities: applepayConfig.merchantCapabilities,
  supportedNetworks: applepayConfig.supportedNetworks,
  currencyCode: "USD",
  requiredShippingContactFields: ["name", "phone", "email", "postalAddress"],
  requiredBillingContactFields: ["name", "phone", "email", "postalAddress"],
    
  recurringPaymentRequest: {
      paymentDescription: "A description of the recurring payment to display to the user in the payment sheet.",
      regularBilling: {
          label: "Recurring",
          amount: "4.99",
          paymentTiming: "recurring",
          recurringPaymentStartDate: "2022-08-03T07:56:44.582Z"   
      },
      trialBilling: {
          label: "7 Day Trial",
          amount: "1.99",
          paymentTiming: "recurring",
          recurringPaymentEndDate: "2022-08-03T07:56:44.582Z"
      },
      billingAgreement: "A localized billing agreement displayed to the user in the payment sheet prior to the payment authorization.",
      managementURL: "https://merchant.com/billingagreement1234",
      tokenNotificationURL: applepayConfig.tokenNotificationURL
  },
 
  total: {
      label: "Demo",
      type: "final",
      amount: "1.99"
  }  
};

const session = new ApplePaySession(4, paymentRequest);
```

### Authorize Order Response
```json
{
  "id": "5O190127TN364715T",
  "status": "COMPLETED",
  "payment_source": {
    "apple_pay": {
      "name": "John Doe",
      "card": {
        "name": "John Doe",
        "last_digits": "5421",
        "brand": "VISA",
        "type": "DEBIT",
        "billing_address": {
          "address_line_1": "2211 N First Street",
          "admin_area_2": "San Jose",
          "admin_area_1": "CA",
          "postal_code": "95131",
          "country_code": "US"
        }
      },
      "attributes": {
        "vault": {
          "id": "nkq2y9g",
          "status": "VAULTED",
          "links": [
            {
              "href": "https://api-m.paypal.com/v3/vault/payment-tokens/nkq2y9g",
              "rel": "self",
              "method": "GET"
            },
            {
              "href": "https://api-m.paypal.com/v3/vault/payment-tokens/nkq2y9g",
              "rel": "delete",
              "method": "DELETE"
            },
            {
              "href": "https://api-m.paypal.com/v2/checkout/orders/5O190127TN364715T",
              "rel": "up",
              "method": "GET"
            }
          ]
        }
      }
    }
  },
  "purchase_units": [
    {
      "reference_id": "d9f80740-38f0-11e8-b467-0ed5f89f718b",
      "payments": {
        "authorizations": [
          {
            "id": "3C679366HH908993F",
            "status": "CREATED",
            "amount": {
              "currency_code": "USD",
              "value": "100.00"
            },
            "seller_protection": {
              "status": "NOT_ELIGIBLE"
            },
            "expiration_time": "2022-12-08T18:11:02Z",
            "create_time": "2022-12-08T18:11:02Z",
            "update_time": "2022-12-08T18:11:02Z",
            "links": [
              {
                "href": "https://api-m.paypal.com/v2/payments/authorizations/5O190127TN364715T",
                "rel": "self",
                "method": "GET"
              },
              {
                "href": "https://api-m.paypal.com/v2/payments/authorizations/5O190127TN364715T/capture",
                "rel": "capture",
                "method": "POST"
              },
              {
                "href": "https://api-m.paypal.com/v2/payments/authorizations/5O190127TN364715T/void",
                "rel": "void",
                "method": "POST"
              },
              {
                "href": "https://api-m.paypal.com/v2/checkout/orders/5O190127TN364715T",
                "rel": "up",
                "method": "GET"
              }
            ]
          }
        ]
      }
    }
  ],
  "links": [
    {
      "href": "https://api-m.paypal.com/v2/checkout/orders/5O190127TN364715T",
      "rel": "self",
      "method": "GET"
    }
  ]
}
```

## Merchant Initiated Transaction (MIT)

### Create Order
#### Request
```json
{
  "intent": "AUTHORIZE",
  "purchase_units": [
    {
      "reference_id": "d9f80740-38f0-11e8-b467-0ed5f89f718b",
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ],
  "payment_source": {
    "apple_pay": {
      "vault_id": "8kk845",
      "stored_credential": {
        "payment_initiator": "MERCHANT",
        "payment_type": "RECURRING",
        "usage": "SUBSEQUENT"
      }
    }
  }
}
```

#### Response
```json
{
  "id": "5O190127TN364715T",
  "status": "COMPLETED",
  "payment_source": {
    "apple_pay": {
      "name": "John Doe",
      "card": {
        "name": "John Doe",
        "last_digits": "5421",
        "brand": "VISA",
        "type": "DEBIT",
        "billing_address": {
          "address_line_1": "2211 N First Street",
          "admin_area_2": "San Jose",
          "admin_area_1": "CA",
          "postal_code": "95131",
          "country_code": "US"
        }
      }
    }
  },
  "purchase_units": [
    {
      "reference_id": "d9f80740-38f0-11e8-b467-0ed5f89f718b",
      "payments": {
        "authorizations": [
          {
            "id": "0AW2184448108334S",
            "status": "CREATED",
            "amount": {
              "currency_code": "USD",
              "value": "100.00"
            },
            "seller_protection": {
              "status": "NOT_ELIGIBLE"
            },
            "expiration_time": "2022-03-22T21:20:49Z",
            "create_time": "2022-12-20T21:20:49Z",
            "update_time": "2022-12-20T21:20:49Z",
            "links": [
              {
                "href": "https://api-m.paypal.com/v2/payments/authorizations/0AW2184448108334S",
                "rel": "self",
                "method": "GET"
              },
              {
                "href": "https://api-m.paypal.com/v2/payments/authorizations/0AW2184448108334S/capture",
                "rel": "capture",
                "method": "POST"
              },
              {
                "href": "https://api-m.paypal.com/v2/payments/authorizations/0AW2184448108334S/void",
                "rel": "void",
                "method": "POST"
              },
              {
                "href": "https://api-m.paypal.com/v2/payments/authorizations/0AW2184448108334S/reauthorize",
                "rel": "reauthorize",
                "method": "POST"
              },
              {
                "href": "https://api-m.paypal.com/v2/checkout/orders/5O190127TN364715T",
                "rel": "up",
                "method": "GET"
              }
            ]
          }
        ]
      }
    }
  ],
  "links": [
    {
      "href": "https://api-m.paypal.com/v2/checkout/orders/5O190127TN364715T",
      "rel": "self",
      "method": "GET"
    }
  ]
}
```