> For the complete documentation index, see [llms.txt](https://docs.coda.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coda.co/https-coda-payments.gitbook.io-zhong-wen-coda-private-technical-documentation/codapay/tokenization-api-2.0/ji-cheng-zhi-nan/charge.md).

# Charge

## Charge 对象

<table><thead><tr><th width="274">参数名称</th><th width="178">类型</th><th>描述</th></tr></thead><tbody><tr><td>id</td><td>String</td><td>Coda生成的token ID</td></tr><tr><td>created_at</td><td>String</td><td>合作伙伴将用于识别其客户并链接token ID 的 ID</td></tr><tr><td>status_code</td><td>String</td><td>Token的状态码</td></tr><tr><td>token_id</td><td>String</td><td>连结的token ID</td></tr><tr><td>partner_reference</td><td>String</td><td>合作伙伴参考 ID<br>长度必须介于 4 到 64 之间，并且必须遵循模式 <code>^[a-zA-Z0-9-_]+$</code></td></tr><tr><td>item_code</td><td>String</td><td>被扣款商品的代码</td></tr><tr><td>item_name</td><td>String</td><td>被扣款商品的名称</td></tr><tr><td>amount_value</td><td>String</td><td>商品的扣款金额</td></tr><tr><td>amount_currency</td><td>String</td><td>收取金额的货币</td></tr><tr><td>subscription_id</td><td>String</td><td>订阅 ID（如果选择加入订阅）</td></tr><tr><td>shopper_action</td><td>String</td><td>Shopper 扣款流程操作</td></tr><tr><td>shopper_action.id</td><td>String</td><td>Shopper 扣款操作 ID</td></tr><tr><td>shopper_action.type</td><td>String</td><td>Shopper 扣款操作类型（例如：重定向）</td></tr><tr><td>shopper_action.redirection</td><td>String</td><td>Shopper 扣款重定向实体</td></tr><tr><td>shopper_action.redirection.id</td><td>String</td><td>Shopper 扣款重定向 ID</td></tr><tr><td>shopper_action.redirection.method</td><td>String</td><td>Shopper 扣款重定向 URL 方法类型（例如：GET/POST）</td></tr><tr><td>shopper_action.redirection.url</td><td>String</td><td>Shopper 扣款重定向 URL</td></tr></tbody></table>

## 接口

{% tabs %}
{% tab title="接口" %}

```
POST /v1/charges 
GET /v1/charges/{charge.id}
```

{% endtab %}
{% endtabs %}

## 创建带有 Shopper 操作的扣款

### POST /charges

{% tabs %}
{% tab title="Charges" %}

```json
curl --location '{baseUrl}/v1/charges' \
--header 'X-Partner-Id: par_sg1882402279a0000' \
--header 'X-Api-Key: sdirugnvsiguhsirghsekjhgh' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXJ0bmVyX2lkIjoicGFyX3NnMTg4MjQwMjI3OWEwMDAwIiwiaWF0IjoxNzAxMjMzNTM0fQ.o_tcEJUEwEms49J0MXwvRuCGbsBx3rHugfgKsXVgj9I' \
--data '{
  "token_id": "tkn_sg18bffd6a3ae0003",
  "item_code": "item-code-28",
  "item_name": "item-name-28",
  "amount_value": "28",
  "amount_currency": "SAR",
 "partner_reference": "partner-reference-123",
 "token" : {
    "payment_method": {
      "card": {
        "security_code": "xxx"      
      }
    }
  }
}'
```

{% endtab %}
{% endtabs %}

### 带有 Shopper 操作的[扣款响应对象](#charge-dui-xiang)

{% tabs %}
{% tab title="Charge" %}

```json
{
    "id": "chg_sg18bffdcebd30018",
    "created_at": "2023-11-24T05:45:50.291546075Z",
    "status_code": "waiting_for_shopper_action",
    "token_id": "tkn_sg18bffd6a3ae0003",
    "partner_reference":"partner-reference-123",
    "item_code": "item-code-28",
    "item_name": "item-name-28",
    "amount_value": "28",
    "amount_currency": "SAR",
    "subscription_id": null,
    "shopper_action": {
        "id": "csa_sg18bffdcf7700007",
        "type": "redirection",
        "redirection": {
            "id": "car_sg18bffdcf82d0007",
            "method": "GET",
            "url": "https://cdn1.codapayments.com/W/pub/tc/mada/authenticate-payer.html?action=https%3A%2F%2Fap.gateway.mastercard.com%2Facs%2Fmastercard%2Fv2%2Fprompt&creq=eyJ0aHJlZURTU2VydmVyVHJhbnNJRCI6IjZjMzViOTNjLTYwN2QtNGQ1MC1iZWRmLWFlOWJjZDg1M2I3YiJ9"
        }
    }
}
```

{% endtab %}
{% endtabs %}

## 创建无需 Shopper 操作的扣款

### POST /charges

{% tabs %}
{% tab title="Charge" %}

```json
curl --location '{baseUrl}/v1/charges' \
--header 'X-Partner-Id: par_sg1882402279a0000' \
--header 'X-Api-Key: sdirugnvsiguhsirghsekjhgh' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXJ0bmVyX2lkIjoicGFyX3NnMTg4MjQwMjI3OWEwMDAwIiwiaWF0IjoxNzAxMjMzNTM0fQ.o_tcEJUEwEms49J0MXwvRuCGbsBx3rHugfgKsXVgj9I' \
--data '{
  "token_id": "tkn_sg18c23a062a90007",
  "item_code": "item-code-585",
  "item_name": "item-name-585",
  "amount_value": "585",
  "amount_currency": "IDR",
  "partner_reference": 123456789
}'
```

{% endtab %}
{% endtabs %}

### [响应Charge对象](#charge-dui-xiang)

{% tabs %}
{% tab title="Charge" %}

```json
{
    "id": "chg_sg18c23a11fff0008",
    "created_at": "2023-12-01T04:26:51.263110116Z",
    "status_code": "succeeded",
    "token_id": "tkn_sg18c23a062a90007",
    "partner_reference": "123456789",
    "item_code": "item-code-585",
    "item_name": "item-name-585",
    "amount_value": "585",
    "amount_currency": "IDR",
    "subscription_id": null,
    "shopper_action": null
}
```

{% endtab %}
{% endtabs %}

## 取消Charge

### GET /charges/{id}

{% tabs %}
{% tab title="Request" %}

```json
curl --location '{baseUrl}/v1/charges/chg_sg18bffe4bd460001' \
--header 'X-Partner-Id: par_sg1882402279a0000' \
--header 'X-Api-Key: sdirugnvsiguhsirghsekjhgh' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXJ0bmVyX2lkIjoicGFyX3NnMTg4MjQwMjI3OWEwMDAwIiwiaWF0IjoxNzAxMjMzNTM0fQ.o_tcEJUEwEms49J0MXwvRuCGbsBx3rHugfgKsXVgj9I' \
--data ''
```

{% endtab %}
{% endtabs %}

### [响应收费对象](#charge-dui-xiang)

{% tabs %}
{% tab title="Charge" %}

```json
{
    "id": "chg_sg18bffe4bd460001",
    "created_at": "2023-11-24T05:54:22.662466Z",
    "status_code": "succeeded",
    "token_id": "tkn_sg18bffd6a3ae0003",
    "partner_reference": null,
    "item_code": "item-code-160",
    "item_name": "item-name-160",
    "amount_value": "120",
    "amount_currency": "SAR",
    "subscription_id": null,
    "shopper_action": null
}
```

{% endtab %}
{% endtabs %}

## 请求参数

<table><thead><tr><th>参数名称</th><th width="107">类型</th><th width="84">必填？</th><th>描述</th><th>验证</th></tr></thead><tbody><tr><td>token_id</td><td>String</td><td>是</td><td>Coda生成的token ID</td><td>Token ID 长度必须介于 20 到 32 之间 并且必须遵循模式<code>“[A-Za-z]+_[A-Za-z0-9]+”</code></td></tr><tr><td>item_code</td><td>String</td><td>是</td><td>收费项目代码</td><td>不能为空</td></tr><tr><td>item_name</td><td>String</td><td>是</td><td>收费项目名称</td><td>不能为空</td></tr><tr><td>amount_value</td><td>String</td><td>是</td><td>商品的收费数值</td><td><p>不不能为空</p><p>必须匹配<code>“^\d+(.\d{1,2})?$”</code></p></td></tr><tr><td>amount_currency</td><td>String</td><td>是</td><td>收取金额的货币</td><td><p>不能为空</p><p>大小必须为 3</p></td></tr><tr><td>partner_reference</td><td>String</td><td>是</td><td>合作伙伴参考 ID</td><td>合作伙伴参考号不能为空，长度必须介于 4 到 64 之间，并且必须遵循模式 <code>^[a-zA-Z0-9-_]+$</code></td></tr><tr><td>token.payment_method.card.security_code</td><td>String</td><td>否</td><td>卡安全代码 (CSC/CVV) 是卡付款方式成功创建费用的必填字段。其他付款方式（例如 GoPay）可选填</td><td>安全码长度必须为 3</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.coda.co/https-coda-payments.gitbook.io-zhong-wen-coda-private-technical-documentation/codapay/tokenization-api-2.0/ji-cheng-zhi-nan/charge.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
