Backend API

When a store accepts payment of any kind, a record is kept along with its relation to an order or invoice. Related orders and invoices are automatically updated with payment totals. When a refund is issued, the amount_refunded is also updated.

Fields

id

objectId

Unique identifier for the payment.

account

Account

Expandable link to the customer's account that made the payment.

account_card

Account Card

Expandable link to the customer's credit card on file used to make the payment, if applicable.

account_card_id

objectId

ID of the customer's credit card on file used to make the payment, if applicable.

account_id

objectIdrequired

ID of the customer's account the payment was made for.

amazon

object

Amazon billing details used when method=amazon.

amount

currencyrequired

Payment amount denominated in currency. Minimum of 0.01

amount_refundable

currencyauto

Remaining amount that can be refunded.

amount_refunded

currencyauto

Amount of the payment that has been refunded.

async

booleanauto

Indicates the payment is processed asynchronously. The payment will be updated in the future while success is undefined.

authorized

boolean

Indicates the payment was authorized before being captured.

captured

boolean

Indicates the payment has been captured.

card

object

Credit card details used to make the payment, if applicable.

currency

string

Three-letter ISO currency code in uppercase. Defaults to the store's base currency.

currency_rate

float

Currency percentage used in calculating the fixed amount.

date_async_update

date

The date of the next time the payment status will be updated.

date_created

dateauto

Date and time the payment was created.

date_updated

dateauto

Date and time the payment was last updated.

error

object

An object describing an error that occurred while interacting with the payment gateway, if applicable.

gateway

stringauto

ID of the payment gateway that was used to process the payment.

giftcard

Gift Card

Expandable link to gift card used to make the payment, if applicable.

giftcard_id

objectId

ID of the gift card used to make the payment, if applicable.

intent

object

The intent of the external payment provider. See the external payment provider’s documentation for how intent is implemented.

invoice

Invoice

Expandable link to the invoice the payment was applied to, if applicable.

invoice_id

objectId

ID of the invoice the payment was applied to, if applicable.

method

stringrequired

Method of payment. Can be card, account, amazon, paypal or any one of the manual methods defined in payment settings.

number

stringauto

Unique incremental payment number assigned automatically.

order

Order

Expandable link to the order the payment was applied to, if applicable.

order_id

objectId

ID of the order the payment was applied to, if applicable.

paypal

object

PayPal billing details used when billing.method=paypal.

refunds

array of Refunds

Expandable list of refunds issued for the payment.

status

enumauto

Status of the payment. Can be pending, which is awaiting async processing, error, success or authorized.

Possible enum values:

pendingvoiderrorsuccessauthorized

subscription

Subscription

Expandable link to the subscription the payment was applied to, if applicable.

subscription_id

objectIdauto

ID of the subscription the payment was applied to, if applicable.

success

boolean

Indicates the payment was successful. When an error occurs with a payment gateway, this status will be false and error field will be populated.

test

booleanauto

Indicates the payment was made with a gateway in test mode.

transaction_id

stringauto

External identifier returned by a payment gateway, if applicable.

The payment model
{
  "id": "60f199509111e70000000056",
  "account_id": "60f199509111e7000000005a",
  "amount": 50,
  "method": "card",
  "account_card_id": "60f199509111e70000000058",
  "amount_refundable": 30,
  "amount_refunded": 20,
  "async": false,
  "authorized": true,
  "captured": true,
  "card": {
    "token": "card_1Ds1K7E30PFlZWil6Q7bJ1PD",
    "test": true,
    "last4": "4242",
    "brand": "Visa",
    "address_check": "unchecked",
    "zip_check": "unchecked",
    "cvc_check": "unchecked",
    "exp_month": 1,
    "exp_year": 2029
  },
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.313Z",
  "date_updated": "2021-07-16T14:36:00.313Z",
  "error": null,
  "gateway": "stripe",
  "number": 2973512,
  "order_id": "60f199509111e70000000059",
  "status": "success",
  "success": true,
  "test": true,
  "transaction_id": "ch_1XNoXdEAeofUkt5SrbA6Swow"
}

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

Arguments

account_id

objectIdrequired

ID of the customer's account the payment was made for.

amount

currencyrequired

Payment amount denominated in currency. Minimum of 0.01

method

stringrequired

Method of payment. Can be card, account, amazon, paypal or any one of the manual methods defined in payment settings.

card

object

Credit card details used to make the payment, if applicable.

invoice_id

objectId

ID of the invoice the payment was applied to, if applicable.

order_id

objectId

ID of the order the payment was applied to, if applicable.

POST/payments
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.post('/payments', {
  amount: 50,
  method: 'card',
  card: { token: 'card_XfqLq5nRdOdu7vTvoeKufafN' },
  account_id: '5c899d4f7d7920749638dc4e',
});
Response
{
  "id": "5cae685b20a54174dd968afa",
  "account_id": "5c899d4f7d7920749638dc4e",
  "amount": 50,
  "amount_refundable": 50,
  "authorized": true,
  "captured": true,
  "card": {
    "brand": "Visa",
    "last4": "4242",
    "exp_month": 10,
    "exp_year": 2029,
    "token": "card_XfqLq5nRdOdu7vTvoeKufafN",
    "cvc_check": "pass",
    "zip_check": "pass",
    "address_check": "pass"
  },
  "currency": "USD",
  "date_created": "2019-04-01T00:00:00.000Z",
  "date_updated": "2019-04-01T00:00:00.000Z",
  "gateway": "stripe",
  "method": "card",
  "number": "1947367",
  "order_id": "5cae685b20a54174dd968077",
  "status": "success",
  "success": true,
  "transaction_id": "ch_1XNoXdEAeofUkt5SrbA6Swow"
}

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

Arguments

id

objectIdrequired

The id of the payment 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 category 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/payments/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/payments/{id}', {
  id: '5cae685b20a54174dd968afa',
});
Response
{
  "id": "5cae685b20a54174dd968afa",
  "account_id": "5c899d4f7d7920749638dc4e",
  "amount": 50,
  "amount_refundable": 50,
  "authorized": true,
  "captured": true,
  "card": {
    "brand": "Visa",
    "last4": "4242",
    "exp_month": 10,
    "exp_year": 2029,
    "token": "card_XfqLq5nRdOdu7vTvoeKufafN",
    "cvc_check": "pass",
    "zip_check": "pass",
    "address_check": "pass"
  },
  "currency": "USD",
  "date_created": "2019-04-01T00:00:00.000Z",
  "date_updated": "2019-04-01T00:00:00.000Z",
  "gateway": "stripe",
  "method": "card",
  "number": "1947367",
  "order_id": "5cae685b20a54174dd968077",
  "status": "success",
  "success": true,
  "transaction_id": "ch_1XNoXdEAeofUkt5SrbA6Swow"
}

Updating a payment with the Swell Backend API.

Arguments

id

objectIdrequired

Unique identifier for the payment.

captured

boolean

Indicates the payment has been captured.

transaction_id

stringauto

External identifier returned by a payment gateway, if applicable.

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

await swell.post('/payments/{id}', {
  captured: true,
  transaction_id: ch_1XNoXdEAeofUkt5SrbA6Swow,
});
Arguments

amount

currencyrequired

Amount to refund up to payment amount_refundable.

method

string

Optionally refund the payment using a different method. Defaults to the original payment method.

reason

boolean

The reason of the refund.

reason_message

string

A brief message describing the reason for the refund.

POST/payments/:id/refunds
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.post('/payments/{id}/refunds', {
  id: '5cae685b20a54174dd968afa',
  amount: 50,
});
Response
{
  "id": "5cae042722984c53002096ab",
  "amount": 50,
  "card": {
    "brand": "Visa",
    "last4": "4242",
    "exp_month": 10,
    "exp_year": 2029,
    "token": "card_XfqLq5nRdOdu7vTvoeKufafN",
    "cvc_check": "pass",
    "zip_check": "pass",
    "address_check": "pass"
  },
  "currency": "USD",
  "date_created": "2019-04-01T00:00:00.000Z",
  "gateway": "stripe",
  "method": "card",
  "number": "103352",
  "order_id": "5cae685b20a54174dd968077",
  "parent_id": "5cae685b20a54174dd968afa",
  "status": "success",
  "success": true,
  "transaction_id": "re_1XNhqtFAeoMUkt5CitcnPNAa"
}

Return a list of payments.

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/payments
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/payments', {
  limit: 25,
  page: 1
});
Response
{
  "count": 51,
  "results": [
    {
      "id": "60f199509111e70000000056",
      "account_id": "60f199509111e7000000005e",
      "amount": 50,
      "method": "card",
      "account_card_id": "60f199509111e70000000058",
      "amount_refundable": 30,
      "amount_refunded": 20,
      "async": false,
      "authorized": true,
      "captured": true,
      "card": {
        "token": "card_1Ds1K7E30PFlZWil6Q7bJ1PD",
        "test": true,
        "last4": "4242",
        "brand": "Visa",
        "address_check": "unchecked",
        "zip_check": "unchecked",
        "cvc_check": "unchecked",
        "exp_month": 1,
        "exp_year": 2029
      },
      "currency": "USD",
      "date_created": "2021-07-16T14:36:00.313Z",
      "date_updated": "2021-07-16T14:36:00.313Z",
      "error": null,
      "gateway": "stripe",
      "number": 2973512,
      "order_id": "60f199509111e70000000059",
      "status": "success",
      "success": true,
      "test": true,
      "transaction_id": "ch_1XNoXdEAeofUkt5SrbA6Swow"
    },
    {...},
    {...}
  ],
  "page": 1,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "2": {
      "start": 51,
      "end": 51
    }
  }
}