# Payments

Source: https://developers.swell.is/backend-api/payments

When a store accepts payment of any kind, a record is kept along with its relation to an [order](https://developers.swell.is/backend-api/orders/the-order-model) or [invoice](https://developers.swell.is/backend-api/invoices/the-invoice-model). Related orders and invoices are automatically updated with payment totals. When a [refund](https://developers.swell.is/backend-api/refunds/the-refund-model) is issued, the `amount_refunded` is also updated.

## The payment model

### 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` (objectId, required): ID of the customer's account the payment was made for. Default: `{"$formula":"if(order_id, order.account_id, invoice.account_id)"}`.
- `amazon` (object): Amazon billing details used when `method=amazon`.
  - `access_token` (string): Amazon access token provided when a customer authorizes payment in a storefront.
  - `order_reference_id` (string): Amazon order reference ID created when a customer initiates payment in a storefront.
  - `checkout_session_id` (string)
- `amount` (currency, required): Payment amount denominated in `currency`. Minimum of 0.01
- `amount_refundable` (currency, auto): Remaining amount that can be refunded.
- `amount_refunded` (currency, auto): Amount of the payment that has been refunded.
- `app_id` (objectId): ID of the app that was used to process the payment, if applicable.
- `async` (boolean, auto): 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.
  - `token` (string, required): A temp token generated by Swell Checkout or Stripe.js, or a permanent card token assigned after submitting a temporary token (starting with `card_`).
  - `exp_month` (int): Two-digit number representing the credit card expiration month.
  - `exp_year` (int): Four-digit number representing the credit card expiration year.
  - `brand` (string): Credit card brand. Can be `American Express`, `Diners Club`, `Discover`, `JCB`, `MasterCard`, `UnionPay`, `Visa`, or `Unknown`.
  - `display_brand` (string): Brand of the card displayed to the customer, if different from the underlying brand (for example, co-branded cards).
  - `last4` (string): Last four digits of the card number.
  - `test` (boolean): Indicates this is a test card.
  - `address_check` (string): When used with a payment gateway that performs address checks and `address1` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
  - `zip_check` (string): When used with a payment gateway that performs address checks and `zip` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
  - `cvc_check` (string): When used with a payment gateway that performs CVC code checks and `cvc` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
- `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` (date, auto): Date and time the payment was created.
- `date_updated` (date, auto): 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.
  - `code` (string): Unique error code.
  - `message` (string): A message describing the error.
- `gateway` (string, auto): 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` (string, required): Method of payment. Can be `card`, `account`, `amazon`, `paypal` or any one of the manual methods defined in payment settings.
- `number` (string, auto): 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. Default: `{"$formula":"invoice.order_id"}`.
- `paypal` (object): PayPal billing details used when `billing.method=paypal`.
  - `payer_id` (string): PayPal payer ID provided when a customer authorizes payment in a storefront.
  - `payment_id` (string): PayPal payment ID created when a customer initiates payment in a storefront.
- `paypal_intent` (string): Intent of the PayPal payment, either `capture` or `authorize`. Populated automatically when processing PayPal payments.
- `recurring_first` (boolean): Indicates this is the first payment of a recurring subscription.
- `refunds` (array of Refunds): Expandable list of [refunds](https://developers.swell.is/backend-api/refunds) issued for the payment.
- `status` (enum, auto): Status of the payment. Can be `pending`, which is awaiting async processing, `void`, if the payment was voided, `error`, `success` or `authorized`. Possible values: `pending`, `void`, `error`, `success`, `authorized`. Default: `"pending"`.
- `subscription` (Subscription): Expandable link to the subscription the payment was applied to, if applicable.
- `subscription_id` (objectId, auto): ID of the subscription the payment was applied to, if applicable. Default: `{"$formula":"if(order_id, order.subscription_id, invoice.subscription_id)"}`.
- `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` (boolean, auto): Indicates the payment was made with a gateway in test mode.
- `transaction_id` (string, auto): External identifier returned by a payment gateway, if applicable.

### Example response

```json
{
  "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 payment

Create a new payment.

### Arguments

- `account_id` (objectId, required): ID of the customer's account the payment was made for. Default: `{"$formula":"if(order_id, order.account_id, invoice.account_id)"}`.
- `amount` (currency, required): Payment amount denominated in `currency`. Minimum of 0.01
- `method` (string, required): 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.
  - `token` (string, required): A temp token generated by Swell Checkout or [Stripe.js](https://stripe.com/docs/stripe-js/reference), or a permanent card token assigned after submitting a temporary token (starting with `card_`).
  - `exp_month` (int): Two-digit number representing the credit card expiration month.
  - `exp_year` (int): Four-digit number representing the credit card expiration year.
  - `brand` (string): Credit card brand. Can be `American Express`, `Diners Club`, `Discover`, `JCB`, `MasterCard`, `UnionPay`, `Visa`, or `Unknown`.
  - `last4` (string): Last four digits of the card number.
  - `test` (boolean): Indicates this is a test card.
  - `address_check` (string): When used with a payment gateway that performs address checks and `address1` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
  - `zip_check` (string): When used with a payment gateway that performs address checks and `zip` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
  - `cvc_check` (string): When used with a payment gateway that performs CVC code checks and `cvc` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
- `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. Default: `{"$formula":"invoice.order_id"}`.
- `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.
- `amazon` (object): Amazon billing details used when `method=amazon`.
  - `access_token` (string): Amazon access token provided when a customer authorizes payment in a storefront.
  - `order_reference_id` (string): Amazon order reference ID created when a customer initiates payment in a storefront.
  - `checkout_session_id` (string)
- `amount_refundable` (currency, auto): Remaining amount that can be refunded.
- `amount_refunded` (currency, auto): Amount of the payment that has been refunded.
- `async` (boolean, auto): 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.
- `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.
- `error` (object): An object describing an error that occurred while interacting with the payment gateway, if applicable.
  - `code` (string): Unique error code.
  - `message` (string): A message describing the error.
- `gateway` (string, auto): 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.
- `number` (string, auto): Unique incremental payment number assigned automatically.
- `order` (Order): Expandable link to the order the payment was applied to, if applicable.
- `paypal` (object): PayPal billing details used when `billing.method=paypal`.
  - `payer_id` (string): PayPal payer ID provided when a customer authorizes payment in a storefront.
  - `payment_id` (string): PayPal payment ID created when a customer initiates payment in a storefront.
- `refunds` (array of Refunds): Expandable list of [refunds](https://developers.swell.is/backend-api/refunds) issued for the payment.
- `status` (enum, auto): Status of the payment. Can be `pending`, which is awaiting async processing, `void`, if the payment was voided, `error`, `success` or `authorized`. Possible values: `pending`, `void`, `error`, `success`, `authorized`. Default: `"pending"`.
- `subscription` (Subscription): Expandable link to the subscription the payment was applied to, if applicable.
- `subscription_id` (objectId, auto): ID of the subscription the payment was applied to, if applicable. Default: `{"$formula":"if(order_id, order.subscription_id, invoice.subscription_id)"}`.
- `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` (boolean, auto): Indicates the payment was made with a gateway in test mode.
- `transaction_id` (string, auto): External identifier returned by a payment gateway, if applicable.

### Example request

`POST /payments`

**cURL**

```bash
$ curl https://api.swell.store/payments \
  -u store-id:secret-key \
  -d amount=50 \
  -d method=card \
  -d card[token]=card_XfqLq5nRdOdu7vTvoeKufafN \
  -d acocunt_id=5c899d4f7d7920749638dc4e
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.post('/payments', {
  amount: 50,
  method: 'card',
  card: { token: 'card_XfqLq5nRdOdu7vTvoeKufafN' },
  account_id: '5c899d4f7d7920749638dc4e',
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->post('/payments', [
  'amount' => 50,
  'method' => 'card',
  'card' => [ 'token' => 'card_XfqLq5nRdOdu7vTvoeKufafN' ],
  'account_id' => '5c899d4f7d7920749638dc4e',
  'order_id' => '5cae685b20a54174dd968077',
]);
```

### Example response

```json
{
  "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 a payment

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

### Arguments

- `id` (objectId, required): 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 ](https://developers.swell.is/backend-api/querying/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 ](https://developers.swell.is/backend-api/querying/including)for more details.

### Example request

`GET /payments/:id`

**cURL**

```bash
$ curl https://api.swell.store/payments/5cae685b20a54174dd968afa \
  -u store-id:secret-key
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.get('/payments/{id}', {
  id: '5cae685b20a54174dd968afa',
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->get('/payments/{id}', [
  'id' => '5cae685b20a54174dd968afa',
]);
```

### Example response

```json
{
  "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"
}
```


## Update a payment

Updating a payment with the Swell Backend API.

### Arguments

- `id` (objectId, required): Unique identifier for the payment.
- `account_id` (objectId, required): ID of the customer's account the payment was made for. Default: `{"$formula":"if(order_id, order.account_id, invoice.account_id)"}`.
- `amount` (currency, required): Payment amount denominated in `currency`. Minimum of 0.01
- `method` (string, required): Method of payment. Can be `card`, `account`, `amazon`, `paypal` or any one of the manual methods defined in payment settings.
- `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.
- `amazon` (object): Amazon billing details used when `method=amazon`.
  - `access_token` (string): Amazon access token provided when a customer authorizes payment in a storefront.
  - `order_reference_id` (string): Amazon order reference ID created when a customer initiates payment in a storefront.
  - `checkout_session_id` (string)
- `amount_refundable` (currency, auto): Remaining amount that can be refunded.
- `amount_refunded` (currency, auto): Amount of the payment that has been refunded.
- `async` (boolean, auto): 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.
  - `token` (string): A temp token generated by Swell Checkout or Stripe.js, or a permanent card token assigned after submitting a temporary token (starting with `card_`).
  - `exp_month` (int): Two-digit number representing the credit card expiration month.
  - `exp_year` (int): Four-digit number representing the credit card expiration year.
  - `brand` (string): Credit card brand. Can be `American Express`, `Diners Club`, `Discover`, `JCB`, `MasterCard`, `UnionPay`, `Visa`, or `Unknown`.
  - `last4` (string): Last four digits of the card number.
  - `test` (boolean): Indicates this is a test card.
  - `address_check` (string): When used with a payment gateway that performs address checks and `address1` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
  - `zip_check` (string): When used with a payment gateway that performs address checks and `zip` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
  - `cvc_check` (string): When used with a payment gateway that performs CVC code checks and `cvc` was provided, can be `pass`, `fail`, `unavailable`, or `unchecked`.
- `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.
- `error` (object): An object describing an error that occurred while interacting with the payment gateway, if applicable.
  - `code` (string): Unique error code.
  - `message` (string): A message describing the error.
- `gateway` (string, auto): 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.
- `number` (string, auto): 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. Default: `{"$formula":"invoice.order_id"}`.
- `paypal` (object): PayPal billing details used when `billing.method=paypal`.
  - `payer_id` (string): PayPal payer ID provided when a customer authorizes payment in a storefront.
  - `payment_id` (string): PayPal payment ID created when a customer initiates payment in a storefront.
- `refunds` (array of Refunds): Expandable list of [refunds](https://developers.swell.is/backend-api/refunds) issued for the payment.
- `status` (enum, auto): Status of the payment. Can be `pending`, which is awaiting async processing, `void`, if the payment was voided, `error`, `success` or `authorized`. Possible values: `pending`, `void`, `error`, `success`, `authorized`. Default: `"pending"`.
- `subscription` (Subscription): Expandable link to the subscription the payment was applied to, if applicable.
- `subscription_id` (objectId, auto): ID of the subscription the payment was applied to, if applicable. Default: `{"$formula":"if(order_id, order.subscription_id, invoice.subscription_id)"}`.
- `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` (boolean, auto): Indicates the payment was made with a gateway in test mode.
- `transaction_id` (string, auto): External identifier returned by a payment gateway, if applicable.

### Example request

`PUT /payments/:id`

**cURL**

```bash
$ curl https://api.swell.store/payments/5cae685b20a54174dd968afa \
  -u store-id:secret-key \
  -d captured=true \
  -d transaction_id=ch_1XNoXdEAeofUkt5SrbA6Swow \
  -X PUT
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.put('/payments/{id}', {
  id: '5cae685b20a54174dd968afa',
  captured: true,
  transaction_id: 'ch_1XNoXdEAeofUkt5SrbA6Swow',
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->put('/payments/{id}', [
  'id' => '5cae685b20a54174dd968afa',
  'captured' => true,
  'transaction_id' => 'ch_1XNoXdEAeofUkt5SrbA6Swow',
]);
```

### Example response

```json
{
  "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"
}
```


## Refund a payment

### Arguments

- `amount` (currency, required): 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.

### Example request

`POST /payments/:id/refunds`

**cURL**

```bash
$ curl https://api.swell.store/payments/5cae685b20a54174dd968afa/refunds \
  -u store-id:secret-key \
  -d amount=50
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.post('/payments/{id}/refunds', {
  id: '5cae685b20a54174dd968afa',
  amount: 50,
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->post('/payments/{id}/refunds', [
  'id' => '5cae685b20a54174dd968afa',
  'amount' => 50
]);
```

### Example response

```json
{
  "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"
}
```


## List all payments

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](https://developers.swell.is/backend-api/querying/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](https://developers.swell.is/backend-api/querying/including) for more details.
- `limit` (int): Limit the number of records returned, ranging between `1` and `1000`. Defaults to `15`. Default: `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](https://developers.swell.is/backend-api/querying/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](https://developers.swell.is/backend-api/querying/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](https://developers.swell.is/backend-api/querying) for more details.

### Example request

`GET /payments`

**cURL**

```bash
$ curl https://api.swell.store/payments?limit=25&page=1 \
  -u store-id:secret-key \
  -G
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.get('/payments', {
  limit: 25,
  page: 1
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->get('/payments', [
  'limit' => 25,
  'page' => 1
]);
```

### Example response

```json
{
  "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,
  "page_count": 3,
  "limit": 25,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "3": {
      "start": 51,
      "end": 51
    }
  }
}
```

