Methods to manage and update credit cards stored on a customer's account. The following examples assume an account is assigned to the session by either logging in or creating an account.

Use to get a list of credit cards on file for the account. These are stored automatically when a non-guest user checks out and chooses to save their information for later.

Returns all addresses, with offset pagination using limit and page.

List saved credit cards
await swell.account.listCards()

Use to save a tokenized credit card to the account for future use. Swell accepts Stripe card tokens and payment methods from Stripe, as well as payment methods from Braintree.

Create an account card with a Stripe payment method.

Stripe payment method token
await swell.account.createCard({
  gateway: 'stripe',
  token: 'pm_...',
  // If the payment method is not already attached to a customer in Stripe,
  // passing `gateway_customer` will automatically attach it to the customer.
  stripe_customer: 'cus_MuTOALQlOD1SKv',
  billing: {
    name: 'Julia Sanchez',
    address1: 'Apartment 16B',
    address2: '2602 Pinewood Drive',
    city: 'Jacksonville',
    state: 'FL',
    zip: '32216',
    country: 'US',
    phone: '904-504-4760'
  },
});

Create an account card with a Stripe card token.

Stripe card token
await swell.account.createCard({
  gateway: 'stripe',
  token: 'card_...',
  stripe_token: 'card_1Nuc0kJWwXLFlFUJZfG6yD9f',
  stripe_customer: 'cus_MuTOALQlOD1SKv', // Required if this card is attached to a Stripe customer.
  billing: {
    name: 'Julia Sanchez',
    address1: 'Apartment 16B',
    address2: '2602 Pinewood Drive',
    city: 'Jacksonville',
    state: 'FL',
    zip: '32216',
    country: 'US',
    phone: '904-504-4760'
  },
});

Create an account card with a Braintree payment method.

Braintree payment method token
await swell.account.createCard({
  gateway: 'braintree',
  token: 'ftvymsam',
  // If not passed, the Swell account ID will be used instead.
  gateway_customer: '63b3fdfed87db42c15d878bf',
  billing: {
    name: 'Julia Sanchez',
    address1: 'Apartment 16B',
    address2: '2602 Pinewood Drive',
    city: 'Jacksonville',
    state: 'FL',
    zip: '32216',
    country: 'US',
    phone: '904-504-4760'
  },
  // Required for Braintree
  $vault: true,
});

When creating a card with a token, `brand`, `last4`, `exp_month`, and `exp_year` are set automatically by the gateway.

Used to update information on an existing card on file by ID.

Update an existing card
await swell.account.updateCard('5c15505200c7d14d851e510f'){
  exp_month: 11,
  exp_year: 2050
})

Use to remove a saved credit card from the account by ID.

Delete a credit card
await swell.account.deleteCard('5c15505200c7d14d851e510f')

When fetching an account, the default payment method is listed account.billing.account_card_id. The account's default card can be updated by passing the desired card ID to account.billing.account_card_id

Update the default card
import swell from 'swell-js'
swell.init('my-store', 'public-key')

account = await swell.account.get()

Swell supports deleting the default card. If the default card that is deleted is associated with an active subscription, it will remain associated with the subscription unless the subscription itself is modified.