Backend API

The account cards collection houses a customer's card information used for payments and transactions—allowing for storing multiple cards on a customer account.

Fields

id

objectIdauto

The unique identifier for the card.

parent_id

objectIdrequired

The ID of the parent account.

token

stringrequired

Link to the associated payment token.

active

boolean

Indicated whether this card is active and available for use.

address_check

string

Indicates results of the address check for the card: unchecked, pass, or fail.

billing

object

The customer's billing details. Defaults to account.billing. Updating billing will also update the corresponding account billing object.

brand

string

Name of card issuer. E.g., "visa".

cvc_check

string

Indicates results of the CVC check for the card: unchecked, pass, or fail.

date_created

dateauto

The date the card entry was created.

date_updated

dateauto

Date the card entry was last updated.

exp_month

int

The expiration month on the card, 1 through 12.

exp_year

int

Four-digit card expiration year.

fingerprint

string

A hashed fingerprint generated using client_id, brand, and last4.

gateway

string

Name of the payment gateway.

last4

string

The last four digits of the card number.

parent

Account

Link to the parent account.

test

boolean

Indicated the card is for testing purposes.

zip_check

string

Indicates results of the zip check for the card: unchecked, pass, or fail.

The account card model
{
  "parent_id": "627308bc32db26001276f091",
  "billing": {
    "name": "Glarthir",
    "first_name": "Glarthir",
    "last_name": null,
    "address1": "Glarthir's House",
    "address2": null,
    "city": "Skingrad",
    "state": "CA",
    "zip": "95051",
    "country": "US",
    "phone": null,
    "company": null
    },
  "brand": "Visa",
  "last4": "4242",
  "exp_month": 2,
  "exp_year": 2024,
  "token": "card_mgLMIJrqdFKjapNnKQXzbGSg",
  "address_check": "pass",
  "zip_check": "pass",
  "cvc_check": "pass",
  "fingerprint": "011778e5080632a4701cb5628266007d",
  "date_created": "2022-05-19T17:17:31.167Z",
  "active": true,
  "id": "62867bab67e544001a6a3218"
},

Create a new customer account card. If you wish to generate your own unique ID for the record, it must use BSON ObjectID format for compatibility.

Arguments

id

objectIdauto

The unique identifier for the card.

parent_id

objectIdrequired

The ID of the parent account.

token

linkrequired

Link to the associated payment token.

active

boolean

Indicates whether this card is active and available for use.

address_check

enum

Indicates results of the address check for the card: unchecked, pass, or fail.

Possible enum values:

"unchecked""pass""fail"

billing

object

The customer's billing details. Defaults to account.billing. Updating billing will also update the corresponding account billing object.

brand

string

Name of card issuer. E.g., "visa".

cvc_check

enum

Indicates results of the CVC check for the card: unchecked, pass, or fail.

Possible enum values:

"unchecked""pass""fail"

date_created

dateauto

The date the card entry was created.

date_updated

dateauto

Date the card entry was last updated.

exp_month

int

The expiration month on the card, 1 through 12.

exp_year

int

Four-digit card expiration year.

fingerprint

string

A hashed fingerprint generated using client_id, brand, and last4.

gateway

string

Name of the payment gateway.

last4

string

The last four digits of the card number.

parent

Account

Link to the parent account.

test

boolean

Indicated the card is for testing purposes.

zip_check

enum

Indicates results of the zip check for the card: unchecked, pass, or fail.

Possible enum values:

"unchecked""pass""fail"
POST/accounts:cards
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.post('/accounts:cards', {
  first_name: 'Jarl',
  last_name: 'Balgruff',
  address1: '543 Castle Way',
  city: 'Whiterun',
  state: 'CA',
  country: 'US',
  brand: 'Visa',
  last4: '1234',
  exp_month: 10,
  exp_year: 2023,
});
Response
{
      "parent_id": "621e53a6213eaf013d1fa6b2",
      "billing": {
        "name": "Jarl Balgruff",
        "first_name": "Jarl",
        "last_name": "Balgruff",
        "address1": "543 Castle Way",
        "address2": null,
        "city": "Whiterun",
        "state": "CA",
        "zip": null,
        "country": "US",
        "phone": null,
        "company": null
      },
      "brand": "Visa",
      "last4": "1234",
      "exp_month": 10,
      "exp_year": 2023,
      "token": "card_QD5rOXP3I4bOmUCKlmLo7AzC",
      "address_check": "unchecked",
      "zip_check": "unchecked",
      "cvc_check": "unchecked",
      "fingerprint": "3628a7581fec797682e06740213c08f1",
      "date_created": "2022-07-13T15:52:53.253Z",
      "active": true,
      "id": "64ceea552fa37600132711f4"
    }

Retrieve an existing account card using the ID that was returned when created.

Arguments

id

objectIdrequired

ID of the customer account card to retrieve.

expand

string

Expanding link fields and child collections is performed using the expand argument.

  • For example, expand=account would return a related customer account if one exists.

When the field represents a collection, you can specify the query limit,

  • For example, expand=variants:10 would return up to 10 records of the variants collection.

See expanding for more details.

fields

string

Return only the specified fields in the result. For example fields=name,slug would return only the fields name and slug in the response. Supports nested object and array fields using dot-notation, for example items.product_id. The customer account card id is always returned.

include

string

Include one or more arbitrary queries in the response, possibly related to the main query.

See including for more details.

GET/accounts:cards/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/accounts:cards/{id}', {
});
Response
{
      "parent_id": "621e53a6213eaf013d1fa6b2",
      "billing": {
        "name": "Jarl Balgruff",
        "first_name": "Jarl",
        "last_name": "Balgruff",
        "address1": "543 Castle Way",
        "address2": null,
        "city": "Whiterun",
        "state": "CA",
        "zip": null,
        "country": "US",
        "phone": null,
        "company": null
      },
      "brand": "Visa",
      "last4": "1234",
      "exp_month": 10,
      "exp_year": 2023,
      "token": "card_QD5rOXP3I4bOmUCKlmLo7BzC",
      "address_check": "unchecked",
      "zip_check": "unchecked",
      "cvc_check": "unchecked",
      "fingerprint": "3628a7581fec797682e06740213c08f1",
      "date_created": "2022-07-13T15:52:53.253Z",
      "active": true,
      "id": "64ceea552fa37600131711f3"
    }

Update an existing account card using the ID that was returned when created.

Arguments

id

objectIdrequired

Unique identifier for the account card.

name

string

Full name of the customer. If first_name or last_name are updated, then name will be automatically updated as a combination of first/last.

first_name

string

Customer's first name. If name is updated, then first_name will be automatically updated as the first word of the name.

last_name

string

If name is updated, then last_name will be automatically updated as the last words of the name.

address1

string

Billing address line 1: street address/PO box/company name.

address2

string

Billing address line 2: apartment/suite/unit/building.

city

string

Billing city/district/suburb/town/village.

state

string

Billing state/county/province/region.

zip

string

Billing zip/postal code.

country

string

Two-letter ISO country code.

brand

string

Credit card brand. Can be American Express, Diners Club, Discover, JCB, MasterCard, UnionPay, Visa, or Unknown.

exp_month

int

Two-digit number representing the credit card expiration month.

exp_year

int

Four-digit number representing the credit card expiration year.

last4

string

Last four digits of the card number.

PUT/accounts:cards/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.put('/accounts:cards/{id}', {
  email: 'sheogorath@shiveringisles.com'
});
Response
{
  "parent_id": "621e53a6213eaf013d1fa6b2",
  "billing": {
    "name": "Jarl Balgruff",
    "first_name": "Jarl",
    "last_name": "Balgruff",
    "address1": "543 Castle Way",
    "address2": null,
    "city": "Whiterun",
    "state": "CA",
    "zip": null,
    "country": "US",
    "phone": null,
    "company": null
  },
  "brand": "Visa",
  "last4": "1234",
  "exp_month": 10,
  "exp_year": 2023,
  "token": "card_QD4rOXP3I5bOmUCKlmLo8AzC",
  "address_check": "unchecked",
  "zip_check": "unchecked",
  "cvc_check": "unchecked",
  "fingerprint": "3618a9581fec797682e06740212c08f3",
  "date_created": "2022-07-13T15:52:53.253Z",
  "active": true,
  "date_updated": "2022-07-18T20:00:49.662Z",
  "email": "sheogorath@shiveringisles.com",
  "id": "62ceea552fa37600132911f6"
}

Return a list of customer account cards.

Arguments

expand

string

Expand link fields and child collections by using the expand argument.

  • For example, expand=account would return a related customer account if one exists.

When the field represents a collection, you can specify the query limit.

  • For example, expand=variants:10 would return up to 10 records of the variants collection.

See expanding for more details.

fields

string

Returns only the specified fields in the result.

  • For example fields=name,slug would return only the fields name and slug in the response.

Supports nested object and array fields using dot-notation.

  • For example, items.product_id. The product id is always returned.

include

object

Include one or more arbitrary queries in the response which are potentially related to the main query.

See including for more details.

limit

int

Limit the number of records returned, ranging between 1 and 1000. Defaults to 15.

page

int

The page number of results to return given the specified or default limit.

search

string

A text search is performed using the search argument. Searchable fields are defined by the model.

  • For example, search=red would return records containing the word "red" anywhere in the defined text fields.

See searching for more details.

sort

string

Expression to sort results by using a format similar to a SQL sort statement.

  • For example, sort=name asc would return records sorted by name ascending.

See sorting for more details.

where

object

An object with criteria to filter the result.

  • For example, active=true would return records containing a field active with the value true.

It's also possible to use query operators, for example, $eq, $ne, $gt, and more.

See querying for more details.

GET/accounts:cards
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/accounts:cards', {
  where: {
    order_count: {
      $gt: 1
    }
  },
  limit: 25,
  page: 1
});
Response
{
      "parent_id": "621e53a6213eaf013d1fa6b2",
      "billing": {
        "name": "Jarl Balgruff",
        "first_name": "Jarl",
        "last_name": "Balgruff",
        "address1": "543 Castle Way",
        "address2": null,
        "city": "Whiterun",
        "state": "CA",
        "zip": null,
        "country": "US",
        "phone": null,
        "company": null
      },
      "brand": "Visa",
      "last4": "1234",
      "exp_month": 10,
      "exp_year": 2023,
      "token": "card_QD5rOXP3I4bOmUCKlmLo7BzC",
      "address_check": "unchecked",
      "zip_check": "unchecked",
      "cvc_check": "unchecked",
      "fingerprint": "3628a7581fec797682e06740213c08f1",
      "date_created": "2022-07-13T15:52:53.253Z",
      "active": true,
      "id": "64ceea552fa37600131711f3"

},
    {...},
    {...}
  ],
  "page": 1,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "2": {
      "start": 51,
      "end": 51
    }
  }
}

Delete a customer account card.

Arguments

id

objectIdrequired

The ID of the account card to delete.

DELETE/accounts:cards/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.delete('/accounts:cards/{id}', {
  id: '62ceea552fa37600132911f6'
});