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

idobjectId

Unique identifier for the payment.

account_idobjectIdrequired

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

amountcurrencyrequired

Payment amount denominated in currency. Minimum of 0.01

methodstringrequired

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

accountAccount

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

account_card_idobjectId

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

account_cardCard

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

amazonobject

Amazon billing details used when method=amazon.

amount_refundablecurrencyauto

Remaining amount that can be refunded.

amount_refundedcurrencyauto

Amount of the payment that has been refunded.

asyncbooleanauto

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

authorizedboolean

Indicates the payment was authorized before being captured.

capturedboolean

Indicates the payment has been captured.

cardobject

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

currencystring

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

currency_ratefloat

Currency percentage used in calculating the fixed amount.

date_createddateauto

Date and time the payment was created.

date_updateddateauto

Date and time the payment was last updated.

errorobject

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

gatewaystringauto

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

giftcardGift Card

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

giftcard_idobjectId

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

invoice_idobjectId

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

invoiceInvoice

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

numberstringauto

Unique incremental payment number assigned automatically.

order_idobjectId

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

orderOrder

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

paypalobject

PayPal billing details used when billing.method=paypal.

refundsarray of Refunds

Expandable list of refunds issued for the payment.

statusenumauto

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

subscription_idobjectIdauto

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

subscriptionSubscription

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

successboolean

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

testbooleanauto

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

transaction_idstringauto

External identifier returned by a payment gateway, if applicable.

date_async_updatedate

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

intentobject

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

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.

Arguments

account_idobjectIdrequired

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

amountcurrencyrequired

Payment amount denominated in currency. Minimum of 0.01

methodstringrequired

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

cardobject

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

invoice_idobjectId

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

order_idobjectId

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

idobjectIdrequired

The id of the payment to retrieve.

expandstring

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.

fieldsstring

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.
includestring

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"
}

Arguments

amountcurrencyrequired

Amount to refund up to payment amount_refundable.

methodstring

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

reasonboolean

The reason of the refund.

reason_messagestring

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

expandstring

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.

fieldsstring

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.
includeobject

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

See including for more details.

limitint

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

pageint

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

searchstring

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.

sortstring

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.

whereobject

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
    }
  }
}