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.

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) 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 this topic. Be sure to enter the postal code 10003 in the payment card form so it matches the example values used in this topic.

Link to section

Step 1: Create customer in your developer account

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.

Link to section

Step 2: Create a shared card in your Developer account

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:

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

Step 3: Create a customer in the seller account

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.

Link to section

Step 4: Create a payment in the seller account using the shared card

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

Link to section

See also