Skip to Content
Docs
Set up a new card

Save a payment method

Store a card for future charges with the API or Pay.com.js, and get a reusable payment method ID for subscriptions and off-session payments.

Saving a payment method stores a customer's card so you can charge it later without the customer being present. You can save a card with the API or with Pay.com.js. Both paths return a reusable payment method ID (pm_card_xxx) that works across charges, subscriptions, and off-session billing.

  • API: Validates the card directly with the issuer using a zero-amount transaction. Raw card data passes through your servers, so this requires PCI Level 1 or SAQ-D compliance.
  • Pay.com.js: Collects card details in a hosted checkout form, so raw card data never touches your servers. Use a payment session to charge and save in one step, or a setup session to save without charging.

These steps save cards. To save a US bank account for payouts, use the Plaid integration, which links the account through Pay.com.js.

Requirements

Check the prerequisites for the integration path you choose.

For API integrations:

  • Retrieve your API credentials from the Pay.com dashboard.
  • A customer_reference_id to associate the card with a customer record.
  • Browser metadata (IP address, user agent, and screen dimensions) if the issuer requires a 3DS challenge.

For Pay.com.js integrations:

  • Complete the Install and initialize guide. You'll need an initialized pay instance.
  • Choose your session type. Use a payment session to charge and save in one step, or a setup session to save without an immediate charge.

Save a card

Follow these steps to save a card with the API or with Pay.com.js. The API path adds two steps when the issuer requires a 3DS challenge.

  1. 1

    Store the card

    Save the card from your server with the API, or from your frontend with Pay.com.js.

    Call POST /v1/payment_methods with the card details and setup_future_usage: "off_session" to vault the card for future off-session charges.

    Raw card data passes through your servers. This flow requires PCI Level 1 or SAQ-D compliance.

    For setup_future_usage, use "off_session" when you plan to charge the card later without the customer present (subscriptions, recurring billing, and background charges). Use "on_session" when the customer will be present for future charges (a saved card at checkout). For most recurring billing, "off_session" is the correct value.

    The payment method's status tells you what happens next:

    • created: The card was verified and vaulted. No further steps needed.
    • requires_authentication: The issuer requires a 3DS challenge. Continue to the authentication session step.
    • requires_confirmation: Authentication is done, and the payment method waits for you to confirm it.
    • failed_authentication: The customer didn't pass 3DS. Ask for another card.

    If the issuer declines the verification, the request returns an error.

    For cards that don't require a 3DS challenge, pass the card details and billing information. The card is verified and vaulted in a single request.

    {
      "type": "card",
      "customer_reference_id": "cust-john-smith-001",
      "card": {
        "number": "4242424242424242",
        "expiry_month": "12",
        "expiry_year": "2028",
        "cvv": "123",
        "name": "John Smith"
      },
      "billing_details": {
        "name": "John Smith",
        "email": "john.smith@example.com",
        "phone": "+14155551234",
        "address": {
          "line1": "123 Main Street",
          "city": "San Francisco",
          "state": "CA",
          "postal_code": "94102",
          "country": "US"
        }
      },
      "setup_future_usage": "off_session"
    }

    status: "created" confirms the card is verified and vaulted. Store the id (pm_card_...) to use in future charges.

  2. 2

    Complete the checkout (Pay.com.js only)

    After creating the session, initialize Pay.com.js on your frontend with your merchant ID (from the Developers tab of the Pay.com dashboard), and create a checkout with the client_secret returned from your server. Pay.com.js renders a card form for the customer to enter their details. The flow is identical for both session types.

    const pay = await Pay.com({
      identifier: 'YOUR_MERCHANT_ID', // your merchant ID, not the session ID
    })
    
    const checkout = pay.checkout({
      clientSecret: '{client_secret}',
      onSuccess: (payment) => {
        // payment.paymentMethod: stored payment method ID (pm_card_xxx)
        // payment.amount: 0 for setup sessions, charged amount for payment sessions
        // payment.status: "succeeded"
        console.log('Payment method saved:', payment.paymentMethod)
      },
      onFailure: (error) => {
        console.log('Failed:', error.message)
      },
    })
    
    checkout.universal({ container: '#pay-com-checkout' })

    Once the customer submits the form, payment.paymentMethod in the onSuccess callback holds the stored payment method ID. Save this value in your database against the customer record.

    Pay.com can add a network token to the saved card, which keeps working when the issuer replaces the card. See Provision network tokens.

  3. 3

    Create an authentication session (API only, if required)

    You need this step only if the first step returned status: "requires_authentication".

    Call POST /v1/sessions/authentication/linked with the payment method ID in the resource field. With confirm set to false, as here, you confirm the payment method yourself in the next step. Leave confirm out, and Pay.com confirms the payment method when the challenge succeeds.

    {
      "resource": "pm_card_686169133447908352",
      "confirm": false,
      "return_url": "https://your-site.com/payment-method/complete"
    }

    amount: 0 confirms this is a zero-amount card verification, not a charge. Redirect the customer to the url to complete the bank challenge. Pay.com redirects them back to your return_url when the challenge finishes.

  4. 4

    Confirm the payment method (API only, if required)

    You need this step only if the first step returned status: "requires_authentication".

    After the customer completes the challenge and is redirected to your return_url, call POST /v1/payment_methods/{payment_method_id}/confirm.

    POST /v1/payment_methods/pm_card_686169133447908352/confirm

    {}

    A 201 with status: "created" confirms the card is verified and vaulted. The id is now ready to use in future charges. If the issuer declines the verification, ask the customer for another card.

Re-verify a saved payment method

After a card is saved, you can re-run a zero-amount verification at any time to confirm the card is still valid with the issuer. This is useful when:

  • A previous charge was declined and you want to check the card before retrying.
  • The card hasn't been used for a long time.
  • You want to validate the card before a high-value or recurring charge.

Call POST /v1/payment_methods/{payment_method_id}/verify with the stored payment method ID.

POST /v1/payment_methods/pm_card_685217824846643200/verify

{}

The request body is optional. You can pass additional options to customize the verification:

  • cvv: The card's CVV for a customer-initiated verification.
  • off_session: Set to true for a merchant-initiated verification (requires the card to have been saved with setup_future_usage: "off_session").
  • payment_method_options.card.security_checks: Enable AVS or CVV checks for this verification.

A 200 response confirms the issuer approved the verification. If the issuer declines, you receive a 400 with a decline_code explaining the reason (for example, authentication_required if 3DS is needed).

A declined verification doesn't change or delete the stored payment method, and it doesn't affect the customer's default payment method.

Listen for webhooks

Use webhooks to track the outcome of each verification on your backend.

Subscribe to these events:

  • payment_method.created: The card was verified and vaulted.
  • payment_method.requires_confirmation: Authentication is done, and the payment method waits for your confirm call.
  • payment_method.failed_authentication: The customer didn't pass 3DS.
  • payment_method.network_token.provisioned: The card network issued a network token for the card.
  • setup_session.completed and setup_session.failed: A setup session saved the card, or failed to.

Verify the Pay-Signature header before processing any webhook event. See Verify webhook signatures.

Payment method tokens are interchangeable across all Pay.com flows, including the API, the SDKs, and the orchestration layer.

Next steps

Was this page helpful?