Create a Shared Card on File and Make a Payment
This topic is useful for third-party applications. Store a card on file in your Square developer account and make payments with the card in other Square seller accounts. A customer and card are created in your developer account. A customer and payment are created in a seller account.
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.
Use the CreateCustomer
endpoint to create a new customer in your developer account. Use your personal access token or an OAuth token scoped to your developer account.
The Customers API
returns the following response:
The id
field in the response is used in the following step.
Call the CreateCard
endpoint with a payment card token and an idempotency key. Use your personal access token or an OAuth token scoped to your own developer account.
The following example uses your Square account personal access token to create a new card on file in your Square account:
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.
To make a payment with the card saved in step 2, your application must create a new customer in the Square seller account or find a matching customer in the seller account.
The required OAuth scope is CUSTOMERS_WRITE
.
The following example request uses a seller account OAuth access token and is run when a matching customer isn't found and then creates a new customer in the seller account:
Did you know?
The Customers API allows the creation of duplicate customers.
In production, a matching customer might have already been created in the seller account when the buyer made an earlier purchase from the seller. Your application should search for an existing customer that matches the customer information you want to create. If a match is found, use that customer instead of creating a new one.
Use a seller account OAuth access token to create a payment in the seller account, referencing the customer_id
from step 3 (the customer in the seller account) and the shared card on file as the source_id
value from step 2.
The required OAuth scope is PAYMENTS_WRITE
and PAYMENTS_WRITE_SHARED_ONFILE
.
If you need more assistance, contact Developer Support or ask for help in the Developer Forums.