# Charge a customer token to create an order

> `POST https://api.kustom.co/customer-token/v1/tokens/{customerToken}/order`

Charges the customer's stored payment method for the given order and, on success, forwards the resulting order to Order Manager. Internally served by MerchantApiController's `/merchant/{merchantId}/v1/tokens/{tokenId}/order` route, reached through `MerchantRequestRewriteFilter`. Merchant log action: CHARGE_TOKEN.

## Parameters

- `customerToken` (string, path, required)

## Request body

`application/json`

- `attachment` (object)
  - `body` (string, required) — Extra merchant data (EMD), serialized to JSON and passed through as a string.
  - `content_type` (string, required) — The content type of the body.
- `auto_capture` (boolean) — Allow merchant to trigger auto capturing.
- `merchant_data` (string) — Pass through field (max 6000 characters).
- `merchant_reference1` (string) — Merchant's internal order number or other reference. Shown on the confirmation page as "order number" if set (max 255 characters).
- `merchant_reference2` (string)
- `merchant_urls` (object)
  - `confirmation` (string, required) — URL of merchant confirmation page (max 2000 characters).
  - `push` (string) — URL that will be requested when an order is completed. Should be different than checkout and confirmation URLs (max 2000 characters).
- `order_amount` (integer, required) — Non-negative minor units. Total amount of the order, including tax and discounts.
- `order_lines[]` (array<object>, required)
  - `image_url` (string)
  - `merchant_data` (string) — Pass through field (max 255 characters).
  - `name` (string, required) — Descriptive name of the order line item.
  - `product_identifiers` (object)
    - `brand` (string)
    - `category_path` (string)
    - `global_trade_item_number` (string)
    - `manufacturer_part_number` (string)
    - `color` (string)
    - `size` (string)
  - `product_url` (string)
  - `quantity` (integer, required) — Quantity of the order line item.
  - `quantity_unit` (string)
  - `reference` (string)
  - `tax_rate` (integer) — Non-negative. Two implicit decimals, e.g. 1900 = 19%.
  - `total_amount` (integer, required) — Non-negative minor units, includes tax and discount. value = (quantity x unit_price) - total_discount_amount.
  - `total_discount_amount` (integer) — Non-negative minor units, includes tax.
  - `total_tax_amount` (integer) — Total tax amount of the order line. Negative when type is discount.
  - `type` (string) Enum: `physical`, `discount`, `shipping_fee`, `sales_tax`, `digital`, `gift_card`, `store_credit`, `surcharge`.
  - `unit_price` (integer, required) — Non-negative minor units, includes tax, excludes discount.
  - `subscription` (object)
    - `name` (string, required) — The name of the subscription product.
    - `interval` (string, required) — The cadence unit for this subscription. Enum: `DAY`, `WEEK`, `MONTH`, `YEAR`.
    - `interval_count` (integer, required) — The number of intervals.
- `order_tax_amount` (integer) — Non-negative minor units. The total tax amount of the order.
- `purchase_currency` (string, required) — ISO 4217 purchase currency.
- `shipping_address` (object)
  - `attention` (string) — 'Attn.' - optional parameter.
  - `city` (string) — Customer's city.
  - `country` (string) — Customer's country. Should follow ISO 3166 alpha-2, e.g. GB, US, DE, SE.
  - `email` (string) — Customer's email address.
  - `family_name` (string) — Customer's family name.
  - `given_name` (string) — Customer's first name.
  - `organization_name` (string) — Organization name (if applicable). Only applicable for B2B customers.
  - `phone` (string) — Phone number. Preferably a mobile phone number.
  - `postal_code` (string) — Customer's postal code.
  - `region` (string) — Customer's region or state. Mandatory for US and AU market. ISO 3166-2 format.
  - `street_address` (string) — Customer's street address.
  - `street_address2` (string) — Customer's street address, second line.
  - `title` (string) — Customer's title.
- `usage` (string)

### Example request

```json
{
  "attachment": {
    "body": "<string>",
    "content_type": "application/vnd.klarna.internal.emd-v2+json"
  },
  "auto_capture": false,
  "merchant_data": "<string>",
  "merchant_reference1": "ON4711",
  "merchant_reference2": "ON4711",
  "merchant_urls": {
    "confirmation": "<string>",
    "push": "<string>"
  },
  "order_amount": 0,
  "order_lines": [
    {
      "image_url": "https://www.exampleobjects.com/logo.png",
      "merchant_data": "<string>",
      "name": "Running shoe",
      "product_identifiers": {
        "brand": "shoe-brand",
        "category_path": "Shoes > Running",
        "global_trade_item_number": "4912345678904",
        "manufacturer_part_number": "AD6654412-334.22",
        "color": "white",
        "size": "small"
      },
      "product_url": "https://.../AD6654412.html",
      "quantity": 1,
      "quantity_unit": "pcs",
      "reference": "AD6654412",
      "tax_rate": 1900,
      "total_amount": 2500,
      "total_discount_amount": 500,
      "total_tax_amount": 475,
      "type": "physical",
      "unit_price": 2500,
      "subscription": {
        "name": "<string>",
        "interval": "DAY",
        "interval_count": 0
      }
    }
  ],
  "order_tax_amount": 0,
  "purchase_currency": "GBP",
  "shipping_address": {
    "attention": "Attn",
    "city": "London",
    "country": "GB",
    "email": "test.sam@test.com",
    "family_name": "Andersson",
    "given_name": "Adam",
    "organization_name": "<string>",
    "phone": "+44795465131",
    "postal_code": "W1G 0PW",
    "region": "OH",
    "street_address": "33 Cavendish Square",
    "street_address2": "Floor 22 / Flat 2",
    "title": "Mr."
  },
  "usage": "<string>"
}
```

## Responses

### 200

Order was successfully created.

`application/json`

- `authorized_payment_method` (object)
  - `number_of_days` (integer)
  - `number_of_installments` (integer)
  - `type` (string, required) Enum: `invoice`, `fixed_amount`, `pix`, `base_account`, `deferred_interest`, `direct_debit`, `direct_bank_transfer`, `b2b_invoice`, `card`, `slice_it_by_card`, `pay_later_by_card`, `fixed_sum_credit`, `pay_by_card`, `wallet`.
- `fraud_status` (string, required) — Always ACCEPTED for token charges.
- `order_id` (string, required) — Unique order ID of the transaction.
- `redirect_url` (string) — URL to redirect the customer to after placing the order, taken from the request's merchant_urls.confirmation.

```json
{
  "authorized_payment_method": {
    "number_of_days": 0,
    "number_of_installments": 0,
    "type": "invoice"
  },
  "fraud_status": "ACCEPTED",
  "order_id": "<string>",
  "redirect_url": "<string>"
}
```

### 400

The request failed validation, the token is not active, the token has no email on file, or the merchant is not configured for recurring payments.

`application/json`

- `authorized_payment_method` (object)
  - `number_of_days` (integer)
  - `number_of_installments` (integer)
  - `type` (string, required) Enum: `invoice`, `fixed_amount`, `pix`, `base_account`, `deferred_interest`, `direct_debit`, `direct_bank_transfer`, `b2b_invoice`, `card`, `slice_it_by_card`, `pay_later_by_card`, `fixed_sum_credit`, `pay_by_card`, `wallet`.
- `correlation_id` (string)
- `error_code` (string)
- `error_messages[]` (array<string>)
- `fraud_status` (string)
- `reason` (string)

```json
{
  "authorized_payment_method": {
    "number_of_days": 0,
    "number_of_installments": 0,
    "type": "invoice"
  },
  "correlation_id": "<string>",
  "error_code": "BAD_VALUE",
  "error_messages": [
    "<string>"
  ],
  "fraud_status": "ACCEPTED",
  "reason": "Purchase for payment method failed"
}
```

### 403

The charge attempt was declined by the payment provider.

`application/json`

- `authorized_payment_method` (object)
  - `number_of_days` (integer)
  - `number_of_installments` (integer)
  - `type` (string, required) Enum: `invoice`, `fixed_amount`, `pix`, `base_account`, `deferred_interest`, `direct_debit`, `direct_bank_transfer`, `b2b_invoice`, `card`, `slice_it_by_card`, `pay_later_by_card`, `fixed_sum_credit`, `pay_by_card`, `wallet`.
- `correlation_id` (string)
- `error_code` (string)
- `error_messages[]` (array<string>)
- `fraud_status` (string)
- `reason` (string)

```json
{
  "authorized_payment_method": {
    "number_of_days": 0,
    "number_of_installments": 0,
    "type": "invoice"
  },
  "correlation_id": "<string>",
  "error_code": "BAD_VALUE",
  "error_messages": [
    "<string>"
  ],
  "fraud_status": "ACCEPTED",
  "reason": "Purchase for payment method failed"
}
```

### 404

The merchant is not migrated, or the token or merchant was not found.

### 500

An unexpected error occurred.
