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
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
| Action | Cards | Bank accounts | Apple Pay | Google Pay |
|---|---|---|---|---|
| List | GET /payment-methods/cards | GET /payment-methods/bank-accounts | GET /payment-methods/apple-pay | GET /payment-methods/google-pay |
| Update | PUT /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 customer | PUT /payment-methods/cards/{id}/attach | PUT /payment-methods/bank-accounts/{id}/attach | PUT /payment-methods/apple-pay/{id}/attach | PUT /payment-methods/google-pay/{id}/attach |
| Detach from a customer | PUT /payment-methods/cards/{id}/detach | PUT /payment-methods/bank-accounts/{id}/detach | PUT /payment-methods/apple-pay/{id}/detach | PUT /payment-methods/google-pay/{id}/detach |
| Delete | DELETE /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-methodslists 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.
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:
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:
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:
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:
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:
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:
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: