Skip to Content
Docs

Retrieve saved payment methods

Retrieve a returning customer's saved payment methods or payout-capable sources in a Headless checkout integration.

The checkout.getExistingSources() method retrieves the customer's previously saved payment methods. Use it in a Headless checkout integration to let returning customers select a saved payment method and pay without re-entering their details.

This method also works for payouts. When the checkout is initialized with a clientSecret from a payout setup session (a setup session created with payout: true), getExistingSources() returns only payout-capable sources, the saved methods the customer can receive money to.

Headless checkout only. Universal checkout displays saved payment methods (or payout sources) automatically. You need this method only when you build your own checkout UI with Headless checkout.

const existingSources = await checkout.getExistingSources()

Returns

The method returns an array of saved payment source objects. The sources returned depend on the session type:

  • Payment session. Returns all saved payment methods the customer can pay with.
  • Payout setup session (payout: true). Returns only payout-capable sources the customer can receive funds to.

Each source object has these fields:

FieldTypeDescription
idstringUnique identifier. Pass this as the source argument to checkout.pay().
typestringPayment method type (for example, "card").
tokenstringToken identifier associated with this source.
cardobjectPresent when type is "card". See Card object.

Other source types carry their own details object instead of card, for example bankAccount for bank accounts or paypal for PayPal.

Card object

When the saved source is a card, the card object includes these fields:

FieldTypeDescription
binstringBank identification number, the leading digits of the card number.
brandstringCard brand (for example, "visa" or "mastercard").
cardholderCurrencystringCurrency associated with the cardholder.
countrystringCard issuing country code.
issuerNamestringName of the issuing bank.
cvvExistsbooleanWhether the CVV can be skipped for this source. When true, you can omit cvv in checkout.pay(). When false, collect the CVV and pass it.
expMonthstringTwo-digit expiration month.
expYearstringFour-digit expiration year.
last4stringLast four digits of the card number.
fingerprintstringUnique fingerprint identifying this card.
fundingstringCard funding type (for example, "credit" or "debit").
networkstringCard network (for example, "visa").
payoutstringPayout capability indicator.

Example

Use the same method in a payment session and in a payout setup session.

Payment example

When used with a payment session, retrieve saved cards and pay with one using checkout.pay():

const existingSources = await checkout.getExistingSources()

// Example response
// [
//   {
//     type: 'card',
//     id: 'pm_card_742346737426893824',
//     token: 'tok_card_685104577720095744',
//     card: {
//       bin: '424242',
//       brand: 'visa',
//       cardholderCurrency: 'usd',
//       country: 'US',
//       issuerName: 'Pay.com',
//       cvvExists: false,
//       expMonth: '12',
//       expYear: '2028',
//       last4: '4242',
//       fingerprint: 'bb29cee2a1d6...',
//       funding: 'debit',
//       network: 'visa',
//       payout: 'not_available'
//     }
//   }
// ]

// Display saved cards to the customer
existingSources.forEach(source => {
  if (source.card) {
    console.log(`${source.card.brand} ending in ${source.card.last4}`)
  }
})

// Pay with a saved card. Pass the CVV when cvvExists is false.
const result = await checkout.pay({
  source: existingSources[0].id,
  cvv: '123',
})

Payout example

When used with a payout setup session (payout: true), the same method returns only payout-capable sources. After the customer selects a saved source, call checkout.pay() to register the selection. In payout mode, checkout.pay() doesn't move money. It resolves with the result, whose paymentMethod is the selected payment method ID. It doesn't call onSuccess or onFailure. You then send that ID to your server and use it as the destination when calling the Create a payout API.

// Checkout initialized with a payout setup session clientSecret
const checkout = pay.checkout({ clientSecret })

// Only payout-capable sources are returned
const existingSources = await checkout.getExistingSources()

existingSources.forEach(source => {
  if (source.card) {
    console.log(`${source.card.brand} ending in ${source.card.last4}`)
  }
})

// Customer selects a source: register the selection
try {
  const result = await checkout.pay({ source: existingSources[0].id })

  // Send result.paymentMethod to your server and create the payout
  // (amount in minor units: 10000 is $100.00):
  // POST /v1/payouts
  // {
  //   "amount": 10000,
  //   "currency": "usd",
  //   "customer_reference_id": "user_10",
  //   "destination": result.paymentMethod
  // }
  await sendToServer(result.paymentMethod)
} catch (error) {
  console.error('Selection failed:', error.message)
}

Saved sources are available only for customers who have previously saved a payment method. The session must include a customer_reference_id that matches an existing customer with saved methods.

Next steps

Was this page helpful?