Skip to content

Save a Payment Method

Channels: Embedded · Direct Methods: Card · BECS

Saving a payment method means collecting details once, with the customer’s consent, and receiving a reusable token (pm_xxx) attached to a customer record. There are two paths.

Path A — Save without charging (Setup Intent)

Use this when no money should move yet: free trials, account setup, capturing details for future invoices.

Terminal window
curl -X POST https://api.elasticpay.co/api/v1/setup_intents \
-H "Authorization: Bearer sk_sandbox_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"customer_id": "cus_0abc123def456"}'

Pass the returned client_secret to the widget (card or BECS variant). The widget collects the details; when the flow completes, setup_intent.succeeded fires and the saved pm_xxx is available on the customer record.

For cards, ElasticPay verifies the card and establishes the stored credential with the card schemes behind the scenes — no charge appears for the customer. For BECS, completing the widget flow establishes the direct debit mandate.

Path B — Save during a first purchase

If the customer is paying now and opting to save their details, don’t run two flows — create the payment intent with a customer_id and the store_payment_method metadata flag, then let them pay through the widget as normal. The first purchase itself establishes the stored credential:

Terminal window
curl -X POST https://api.elasticpay.co/api/v1/payment_intents \
-H "Authorization: Bearer sk_sandbox_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"amount": 5000,
"currency": "AUD",
"customer_id": "cus_0abc123def456",
"metadata": {"store_payment_method": "true"}
}'

Both pieces matter: the metadata flag (the string "true") tells ElasticPay to store the credential when the purchase succeeds, and the customer_id is who the saved method is attached to. Set them at create time — the flag is not a confirm parameter.

What you must have first

Saving a method is a consent event. Before you save:

  • the customer must agree to their details being stored and to the charges you intend to make (one-off later, recurring, usage-based)
  • attach the method to a customer_id so future charges are traceable to that agreement

ElasticPay records the scheme- and mandate-level evidence automatically — see Stored Credentials & Recurring Charges.

Using the saved method

Managing saved methods

List a customer’s saved methods:

Terminal window
curl https://api.elasticpay.co/api/v1/customers/cus_0abc123def456/payment_methods \
-H "Authorization: Bearer sk_sandbox_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"