Skip to main content

Manage Saved Payment Methods

This guide lists, reads, updates and deletes your saved payment methods, and attaches them to or detaches them from a customer. The same operations exist for cards, bank accounts, Apple Pay and Google Pay.

A saved payment method has an id that shows its type: card_ for a card, ba_ for a bank account, appl_ for Apple Pay and ggl_ for Google Pay. To save one, see Save Cards, Save Bank Accounts, Set Up Apple Pay or Set Up Google Pay.

Before you start​

Credova account
Sign up or sign in to the Credova Portal.
Secret Key
Authenticates requests from your server. Never send it to the browser.

All requests go to https://api.publicsquare.com and send your Secret Key in the X-API-KEY header.

Operations​

ActionCardsBank accountsApple PayGoogle Pay
ListGET /payment-methods/cardsGET /payment-methods/bank-accountsGET /payment-methods/apple-payGET /payment-methods/google-pay
UpdatePUT /payment-methods/cards/{id}PUT /payment-methods/bank-accounts/{id}PUT /payment-methods/apple-pay/{id}PUT /payment-methods/google-pay/{id}
Attach to a customerPUT /payment-methods/cards/{id}/attachPUT /payment-methods/bank-accounts/{id}/attachPUT /payment-methods/apple-pay/{id}/attachPUT /payment-methods/google-pay/{id}/attach
Detach from a customerPUT /payment-methods/cards/{id}/detachPUT /payment-methods/bank-accounts/{id}/detachPUT /payment-methods/apple-pay/{id}/detachPUT /payment-methods/google-pay/{id}/detach
DeleteDELETE /payment-methods/cards/{id}DELETE /payment-methods/bank-accounts/{id}DELETE /payment-methods/apple-pay/{id}DELETE /payment-methods/google-pay/{id}

Two endpoints work across all four types:

  • GET /payment-methods lists every saved payment method.
  • GET /payment-methods/{id} returns one payment method of any type.

Cards and bank accounts also have a typed read, GET /payment-methods/cards/{id} and GET /payment-methods/bank-accounts/{id}. To list the payment methods of one customer, call GET /customers/{customerId}/payment-methods. Each type also has its own customer route, for example GET /customers/{customerId}/payment-methods/cards.

For the full request and response of each operation, see the Financial API reference.

List Saved Payment Methods​

List endpoints take the page and size query parameters. See Pagination.

List all saved payment methods
curl 'https://api.publicsquare.com/payment-methods?page=1&size=20' \
-H 'X-API-KEY: <SECRET_API_KEY>'

To list one type, call its own endpoint, for example Get All Cards:

List saved cards
curl 'https://api.publicsquare.com/payment-methods/cards?page=1&size=20' \
-H 'X-API-KEY: <SECRET_API_KEY>'

To read one payment method of any type, call Get Payment Method by ID:

Get a payment method
curl 'https://api.publicsquare.com/payment-methods/card_AjkCFKAYiTsjghXWMzoXFPMxj' \
-H 'X-API-KEY: <SECRET_API_KEY>'

Update a Saved Payment Method​

An update changes the customer and the billing details of the payment method. It does not change the card number, the bank account number or the wallet token. Send only the fields you want to change to Update Card:

Update the billing details of a card
curl 'https://api.publicsquare.com/payment-methods/cards/card_AjkCFKAYiTsjghXWMzoXFPMxj' \
-X 'PUT' \
-H 'X-API-KEY: <SECRET_API_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"billing_details": {
"address_line_1": "111 Test St.",
"city": "Des Moines",
"state": "IA",
"postal_code": "51111",
"country": "US"
}
}'

Update Bank Account also accepts account_holder_name, account_holder_type and account_type.

To change the CVC of a saved card, see Recollect a CVC for a Saved Card.

Attach and Detach a Customer​

Attach a payment method to a customer to use it in payments and payouts for that customer. Send the customer id in customer_id to Attach Card to Customer:

Attach a card to a customer
curl 'https://api.publicsquare.com/payment-methods/cards/card_AjkCFKAYiTsjghXWMzoXFPMxj/attach' \
-X 'PUT' \
-H 'X-API-KEY: <SECRET_API_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"customer_id": "cus_7Ay5mcUXAxwrN6wQEQUVEHBCJ"
}'

Detach Card from Customer takes no request body:

Detach a card from its customer
curl 'https://api.publicsquare.com/payment-methods/cards/card_AjkCFKAYiTsjghXWMzoXFPMxj/detach' \
-X 'PUT' \
-H 'X-API-KEY: <SECRET_API_KEY>'

The attach and detach endpoints for bank accounts, Apple Pay and Google Pay work the same way.

Delete a Saved Payment Method​

Call Delete Card with the id of the payment method:

Delete a card
curl 'https://api.publicsquare.com/payment-methods/cards/card_AjkCFKAYiTsjghXWMzoXFPMxj' \
-X 'DELETE' \
-H 'X-API-KEY: <SECRET_API_KEY>'

Conclusion​

To use a saved payment method, follow these guides: