Create a Card on File from a Payment ID

Link to section

Get a payment token

Before saving a card on file, you need to get a valid single-use payment token, which represents a buyer's payment card. Use the Web Payments SDK or In-App Payments SDK to generate the payment token. You don't need to charge the buyer's card to save it. The payment token can be used to save a card on file, create a payment, or both.

The two Cards API examples in this topic require their own unique token.

Important

The postal code entered in the payment card form must match the postal code used in each CreateCard call in this topic.

When you enter card information from Sandbox Test Values, be sure to enter the postal code 10003 to match the values used in this topic.

Link to section

Step 1: Create a payment

Call the CreatePayments endpoint to request a new Payment object.

Create payment

If the payment succeeds, your application gets a response from the Payments API like the following example:

The Payment id field value is used in step 3.

Link to section

Step 2: Create a customer

Create a new customer to associate with the card you create in step 3.

The required OAuth scope is CUSTOMERS_WRITE.

Create customer

The Customers API returns the following response:

{ "customer": { "id": "Q6VKKKGW8GWQNEYMDRMV01QMK8", "created_at": "2021-03-31T18:27:07.803Z", "updated_at": "2021-03-31T18:27:07Z", "given_name": "Amelia", "family_name": "Earhart", "email_address": "[email protected]", "preferences": { "email_unsubscribed": false } } }

The id field in the response is used in the following step.

Link to section

Step 3: Create a card on file using the payment ID as the source

Call the CreateCard endpoint, setting the value of the source_id field to the payment ID in the step 1 Payment response object and the customer_id value from the step 2 Customer response object.

Create card

The Cards API returns the following response:

Important

Always ask customers for permission before saving their card information. For example, include a checkbox in your purchase flow that customers can select to specify that they want to save their card information for future purchases.

Linking cards on file without obtaining customer permission can result in your application being disabled without notice.

Link to section

See also