Storing customer card information securely using Point of Sale API.

You can use Square’s Point of Sale API to save payment information to a customer profile directly from the Square Point of Sale app. Once a card is stored, you can use the Transaction API to charge this card in the future, unlocking fast remote billing and a better experience for your customers.

Turn on Card on File

You can enable Card on File right from the Square Point of Sale app:

  1. Open the Square app and tap on the menu icon.
  2. Tap Settings > Customer Management.
  3. Toggle on Charge and Save Cards to Customer Profiles to save your customers’ payment card information from your in-app Customer Directory.
  4. To save a card after a sale, toggle on Show Save Card Button After Checkout.

Saving the card

Using the Point of Sale APIs with your app uses the same payment flows that the native Square Point of Sale app uses. That means that the flow for saving a Card on File for a customer after a transaction is the same as if you were using the Point of Sale app by itself. Since you have the Point of Sale app installed on the device, you are able to save customer’s cards directly through the Point of Sale app as well.

You can learn all about saving a Card on File in this article, but one of the easiest ways to add a Card on File for is after a transaction. If you pass in a customer_id when initiating a transaction then you’ll see a button for adding the Card on File on the confirmation screen in the top left. To pass the customer_id in with your transaction, you could add the following field to your iOS code:

or with your Android app:

ChargeRequest.Builder.customerId(java.lang.String customerId)

Then your confirmation screen would have the additional “Add Card” button.

Charging the Card on File

Now that you have that Card on File for a customer, you can use the Charge endpoint to bill the customer for follow-up services or any other type of subscription. There are existing guides that highlight the process with code, but at a high level, you’ll need to:

  • Find the customer you want to charge using the Retrieve/List Customers endpoints. The important things to take note of when you find the right customer are their customer_id and the customer_card_id of the card you attached earlier. Depending on your use case, it might be a good idea to independently store the customer_ids and cusomter_card_ids in your user database so that you can skip this step in the future.
  • Charge that customer by supplying the customer_id and customer_card_id to the charge endpoint (instead of the usual card_nonce).

See a complete example of charging a card on file in the Recurring Payments documentation and the Recurring Payments with PHP blog post. If you have any questions/comments on this post, or others, let us know by commenting or reaching out to @SquareDev on Twitter.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.