# Update a payment

Source: https://developers.swell.is/backend-api/payments/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"
}
```
