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.
Create a Shared Card on File and Make a Payment
Before saving a card on file, you need to get a valid single-use payment token that represents a buyer's payment card using the Web Payments SDK or In-App Payments SDK. 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.
Important
The postal code entered in the SDK's payment card form must match the postal code used in the CreateCard request.
You can use Sandbox test card information to generate a test payment token for the following steps. Be sure to enter the postal code 10003 in the payment card form so it matches the example values used.
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.
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
},
"creation_source": "THIRD_PARTY"
}
}
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:
Create card
The Cards API returns the following response:
{
"card": {
"id": "ccof:uIbfJXhXETSP197M3GB",
"billing_address": {
"address_line_1": "500 Electric Ave",
"address_line_2": "Suite 600",
"locality": "New York",
"administrative_district_level_1": "NY",
"postal_code": "10003",
"country": "US"
},
"bin": "411111",
"card_brand": "VISA",
"card_type": "CREDIT",
"cardholder_name": "Amelia Earhart",
"customer_id": "Q6VKKKGW8GWQNEYMDRMV01QMK8",
"enabled": true,
"exp_month": 11,
"exp_year": 2018,
"last_4": "1111",
"prepaid_type": "NOT_PREPAID",
"reference_id": "user-id-1",
"version": 1
}
}
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:
Create customer
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
.
Create payment