Payment MethodsBeta

A Payment Method is a saved card. Created when a customer saves a card on the hosted checkout page — a Checkout Session in setup mode, or a payment with setup_future_usage: or when you confirm a SetupIntent from your server. A card saved for off-session use has an active Mandate; that is what lets you charge it with the customer absent.

Tokens never leave our vault. The PaymentMethod object exposes the metadata you need to render saved cards (brand, last4, expiry, status) and to know whether it can be charged off-session (mandate).

The Payment Method objectBeta

idstring
Unique identifier, prefixed pm_.
objectstring
Always "payment_method".
typeenum
Currently only "card".
statusenum
active, expired, compromised, detached, or purged. Charges fail unless status is active.
customerstring|null
ID of the customer this PM is attached to. Retained on both detach and purge for history; null only if the PM was never attached.
card.brandenum
visa, mastercard, amex, discover, jcb, diners_club, union_pay, unknown.
card.last4string
Last four digits.
card.exp_month / exp_yearinteger
Expiration date.
card.fundingenum
credit, debit, prepaid, or null when unknown.
card.raw_brandstring|null
Original network-reported brand string, when brand is unknown.
card.art_urlstring|null
HTTPS URL to a small SVG card-art asset suitable for displaying the brand. Hot-linkable.
mandatestring|null
ID of the active Mandate anchoring off-session use of this card, if any. Null until the customer consents to save.
latest_network_transaction_idstring|null
Network transaction id of the transaction that saved the card. Written once; later charges do not change it.
billing_detailsobject|null
Name, email, phone, and billing address captured at tokenization.
deletedboolean
True once purged (legacy flag; prefer status).
metadataobject
Up to 50 keys.
livemodeboolean
Test or live mode.
created_atstring
ISO-8601 timestamp.
THE PAYMENT METHOD OBJECT
JSON
1{
2 "id": "pm_01JQX...",
3 "object": "payment_method",
4 "type": "card",
5 "status": "active",
6 "customer": "cus_01JQX...",
7 "card": {
8 "brand": "visa",
9 "last4": "4242",
10 "exp_month": 12,
11 "exp_year": 2030,
12 "funding": "credit",
13 "art_url": "https://assets.cxpay.net/card-art/visa.svg"
14 },
15 "mandate": "mdt_01JQX...",
16 "latest_network_transaction_id": "024PPGFD75NYZ",
17 "deleted": false,
18 "billing_details": {
19 "name": "Avery Lin",
20 "email": "avery@example.com",
21 "phone": null,
22 "address": {
23 "line1": "123 Main St",
24 "line2": null,
25 "city": "Willemstad",
26 "state": null,
27 "postal_code": "0000",
28 "country": "CW"
29 }
30 },
31 "metadata": {},
32 "livemode": false,
33 "created_at": "2026-04-07T18:30:00.000Z"
34}
STATUS REFERENCE
active
ChargeableUse for on-session and off-session charges (subject to mandate state).
expired
Past expiryCard's exp_month/exp_year have passed. Charge attempts are refused with PAYMENT_METHOD_EXPIRED. Customer must re-enter to update.
compromised
FlaggedMarked compromised by you (suspected fraud) or by network notice. Charges are blocked. Detach + ask the customer to re-add.
detached
Customer-removedDetached from the customer; visible for audit but not chargeable. Permanent: it cannot be attached or charged again, so the customer saves the card again. The pm_ id is preserved.
purged
Token deletedDeleted via DELETE — stored card token discarded. The pm_ id remains as a tombstone with redacted card data.

Was this section helpful?

Retrieve a payment methodBeta

GET/v1/payment-methods/:id

Returns one PM by id. Use this to refresh card-art and check status right before initiating an off-session charge.

Path parameters

idstringRequired
The PM id, prefixed pm_.
REQUEST
1curl https://api.cxpay.net/v1/payment-methods/pm_01JQX... \
2 -H "X-Key-Id: ak_test_..." \
3 -H "X-Signature: <base64-hmac>" \
4 -H "X-Timestamp: 2026-04-07T18:30:00.000Z" \
5 -H "X-Nonce: 550e8400-..." \
6 -H "X-Body-Hash: <sha256-of-empty>"
TestGET /v1/payment-methods/pm_01JQX...
RESPONSE
JSON
1{
2 "data": {
3 "id": "pm_01JQX...",
4 "object": "payment_method",
5 "type": "card",
6 "status": "active",
7 "customer": "cus_01JQX...",
8 "card": {
9 "brand": "visa",
10 "last4": "4242",
11 "exp_month": 12,
12 "exp_year": 2030,
13 "funding": "credit",
14 "art_url": "https://assets.cxpay.net/card-art/visa.svg"
15 },
16 "mandate": "mdt_01JQX...",
17 "latest_network_transaction_id": "024PPGFD75NYZ",
18 "deleted": false,
19 "billing_details": {
20 "name": "Avery Lin",
21 "email": "avery@example.com",
22 "phone": null,
23 "address": {
24 "line1": "123 Main St",
25 "line2": null,
26 "city": "Willemstad",
27 "state": null,
28 "postal_code": "0000",
29 "country": "CW"
30 }
31 },
32 "metadata": {},
33 "livemode": false,
34 "created_at": "2026-04-07T18:30:00.000Z"
35 }
36}

Was this section helpful?

List payment methodsBeta

GET/v1/payment-methods

Returns PMs for a customer. Newest first.

Query parameters

customerstringRequired
Restrict to a single customer. The endpoint requires this filter — un-scoped lists are not supported.
limitinteger
1–100, default 10.
cursorstring
Pagination cursor.
REQUEST
1curl "https://api.cxpay.net/v1/payment-methods?customer=cus_01JQX..." \
2 -H "X-Key-Id: ak_test_..." \
3 -H "X-Signature: <base64-hmac>" \
4 -H "X-Timestamp: 2026-04-07T18:30:00.000Z" \
5 -H "X-Nonce: 550e8400-..." \
6 -H "X-Body-Hash: <sha256-of-empty>"
TestGET /v1/payment-methods?customer=cus_01JQX...
RESPONSE
JSON
1{
2 "data": [
3 {
4 "id": "pm_01JQX...",
5 "object": "payment_method",
6 "type": "card",
7 "status": "active",
8 "customer": "cus_01JQX...",
9 "card": {
10 "brand": "visa",
11 "last4": "4242",
12 "exp_month": 12,
13 "exp_year": 2030,
14 "funding": "credit",
15 "art_url": "https://assets.cxpay.net/card-art/visa.svg"
16 },
17 "mandate": "mdt_01JQX...",
18 "latest_network_transaction_id": "024PPGFD75NYZ",
19 "deleted": false,
20 "billing_details": {
21 "name": "Avery Lin",
22 "email": "avery@example.com",
23 "phone": null,
24 "address": {
25 "line1": "123 Main St",
26 "line2": null,
27 "city": "Willemstad",
28 "state": null,
29 "postal_code": "0000",
30 "country": "CW"
31 }
32 },
33 "metadata": {},
34 "livemode": false,
35 "created_at": "2026-04-07T18:30:00.000Z"
36 }
37 ],
38 "has_more": false,
39 "next_cursor": null
40}

Was this section helpful?

Attach to a customerBeta

POST/v1/payment-methods/:id/attach

Attaches a PM that has never had a customer to a Customer: sets the customer, makes the PM active and sends payment_method.attached. Attaching does not create a Mandate, so the card still cannot be charged off-session. Re-attaching to the same customer returns the PM unchanged; attaching to a different customer returns 409 PAYMENT_METHOD_ALREADY_ATTACHED.

A detached, expired, compromised or deleted PM is refused: 409 PAYMENT_METHOD_DETACHED, PAYMENT_METHOD_EXPIRED or PAYMENT_METHOD_COMPROMISED, or 410 PAYMENT_METHOD_DELETED. To use the card again, save it again with a new SetupIntent.

An Idempotency-Key header is required on this request — omitting it returns 400.

Body parameters

customerstringRequired
The customer id, prefixed cus_.
REQUEST
1curl -X POST https://api.cxpay.net/v1/payment-methods/pm_01JQX.../attach \
2 -H "X-Key-Id: ak_test_..." \
3 -H "Content-Type: application/json" \
4 -H "Idempotency-Key: 550e8400-..." \
5 -H "X-Signature: <base64-hmac>" \
6 -H "X-Timestamp: 2026-04-07T18:30:00.000Z" \
7 -H "X-Nonce: 550e8400-..." \
8 -H "X-Body-Hash: <sha256-of-body>" \
9 -d '{ "customer": "cus_01JQX..." }'
TestPOST /v1/payment-methods/pm_01JQX.../attach
RESPONSE
JSON
1{
2 "data": {
3 "id": "pm_01JQX...",
4 "object": "payment_method",
5 "type": "card",
6 "status": "active",
7 "customer": "cus_01JQX...",
8 "card": {
9 "brand": "visa",
10 "last4": "4242",
11 "exp_month": 12,
12 "exp_year": 2030,
13 "funding": "credit",
14 "art_url": "https://assets.cxpay.net/card-art/visa.svg"
15 },
16 "mandate": "mdt_01JQX...",
17 "latest_network_transaction_id": "024PPGFD75NYZ",
18 "deleted": false,
19 "billing_details": {
20 "name": "Avery Lin",
21 "email": "avery@example.com",
22 "phone": null,
23 "address": {
24 "line1": "123 Main St",
25 "line2": null,
26 "city": "Willemstad",
27 "state": null,
28 "postal_code": "0000",
29 "country": "CW"
30 }
31 },
32 "metadata": {},
33 "livemode": false,
34 "created_at": "2026-04-07T18:30:00.000Z"
35 }
36}

Was this section helpful?

Detach vs. deleteBeta

POST/v1/payment-methods/:id/detach

Detach when a customer wants to "remove this card from my account." The PM transitions to detached; subsequent charges fail. The audit trail and last4/brand stay readable so dashboards keep rendering historical payments correctly. Active mandates are revoked as a side effect, and payment_method.detached and mandate.revoked are sent. An Idempotency-Key header is required.

Detach is permanent. A detached card cannot be attached or charged again. To use it again, the customer saves the card again.

Delete when you want the underlying card token destroyed (e.g., GDPR/CCPA right-to-delete). See Delete a payment method. Detach is the right default — most "remove card" flows want detach, not delete.

Not idempotent — re-detaching an already-detached PM returns 409 (invalid status transition).

REQUEST
1curl -X POST https://api.cxpay.net/v1/payment-methods/pm_01JQX.../detach \
2 -H "X-Key-Id: ak_test_..." \
3 -H "Idempotency-Key: 550e8400-..." \
4 -H "X-Signature: <base64-hmac>" \
5 -H "X-Timestamp: 2026-04-07T18:30:00.000Z" \
6 -H "X-Nonce: 550e8400-..." \
7 -H "X-Body-Hash: <sha256-of-empty>"
TestPOST /v1/payment-methods/pm_01JQX.../detach
RESPONSE
JSON
1{
2 "data": {
3 "id": "pm_01JQX...",
4 "object": "payment_method",
5 "type": "card",
6 "status": "detached",
7 "customer": "cus_01JQX...",
8 "card": {
9 "brand": "visa",
10 "last4": "4242",
11 "exp_month": 12,
12 "exp_year": 2030,
13 "funding": "credit",
14 "art_url": "https://assets.cxpay.net/card-art/visa.svg"
15 },
16 "mandate": "mdt_01JQX...",
17 "latest_network_transaction_id": "024PPGFD75NYZ",
18 "deleted": false,
19 "billing_details": {
20 "name": "Avery Lin",
21 "email": "avery@example.com",
22 "phone": null,
23 "address": {
24 "line1": "123 Main St",
25 "line2": null,
26 "city": "Willemstad",
27 "state": null,
28 "postal_code": "0000",
29 "country": "CW"
30 }
31 },
32 "metadata": {},
33 "livemode": false,
34 "created_at": "2026-04-07T18:30:00.000Z"
35 }
36}

Was this section helpful?

Delete a payment methodBeta

DELETE/v1/payment-methods/:id

Permanently destroys the stored card token and redacts cardholder data, and revokes every Mandate on the card. An Idempotency-Key header is required. The PM transitions to purged as a tombstone — the pm_ id stays so historical PaymentIntents continue to resolve, but the card details are wiped and no further charges are possible.

Use this for compliance deletion requests. For ordinary "remove this card" UX, use detach instead.

Irreversible. There is no restore.

REQUEST
1curl -X DELETE https://api.cxpay.net/v1/payment-methods/pm_01JQX... \
2 -H "X-Key-Id: ak_test_..." \
3 -H "Idempotency-Key: 550e8400-..." \
4 -H "X-Signature: <base64-hmac>" \
5 -H "X-Timestamp: 2026-04-07T18:30:00.000Z" \
6 -H "X-Nonce: 550e8400-..." \
7 -H "X-Body-Hash: <sha256-of-empty>"
TestDELETE /v1/payment-methods/pm_01JQX...
RESPONSE
JSON
1{
2 "data": {
3 "id": "pm_01JQX...",
4 "object": "payment_method",
5 "type": "card",
6 "status": "purged",
7 "customer": "cus_01JQX...",
8 "card": {
9 "brand": "visa",
10 "raw_brand": null,
11 "last4": "",
12 "exp_month": 0,
13 "exp_year": 0,
14 "funding": "credit",
15 "art_url": null
16 },
17 "mandate": "mdt_01JQX...",
18 "latest_network_transaction_id": "024PPGFD75NYZ",
19 "deleted": true,
20 "billing_details": {
21 "name": "Avery Lin",
22 "email": "avery@example.com",
23 "phone": null,
24 "address": {
25 "line1": "123 Main St",
26 "line2": null,
27 "city": "Willemstad",
28 "state": null,
29 "postal_code": "0000",
30 "country": "CW"
31 }
32 },
33 "metadata": {},
34 "livemode": false,
35 "created_at": "2026-04-07T18:30:00.000Z"
36 }
37}

Was this section helpful?

Charging a saved card (MIT)Beta

To charge a saved card off-session, create a PaymentIntent with customer and payment_method set, off_session: true, and confirm: true. We replay the saved card's latest_network_transaction_id and the active mandate as stored-credential evidence.

Outcomes:

  • 200, succeeded: money captured. Fulfill. (requires_capture with manual capture.)
  • 402: the card refused the charge. error.code and error.meta.payment_intent.last_payment_error tell you why; retryable and advice_code say whether a retry is worth attempting. authentication_required means the bank wants the customer: they pay again while present.
  • 200, processing: the outcome is not yet known. Retry with the same Idempotency-Key, never a new one.

An off-session charge never returns requires_action. See Charging saved cards for end-to-end examples and the retry rules.

REQUEST
1curl -X POST https://api.cxpay.net/v1/payment-intents \
2 -H "X-Key-Id: ak_test_..." \
3 -H "Content-Type: application/json" \
4 -H "Idempotency-Key: renewal-2026-11-sub_8841" \
5 -H "X-Signature: <base64-hmac>" \
6 -H "X-Timestamp: 2026-04-07T18:30:00.000Z" \
7 -H "X-Nonce: 550e8400-..." \
8 -H "X-Body-Hash: <sha256-of-body>" \
9 -d '{
10 "amount": 4900,
11 "currency": "USD",
12 "customer": "cus_01JQX...",
13 "payment_method": "pm_01JQX...",
14 "off_session": true,
15 "confirm": true,
16 "payment_method_options": { "card": { "stored_credential_usage": "recurring" } }
17 }'
TestPOST /v1/payment-intents

Was this section helpful?

Powered by CX Pay