> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/sdk/domains-api/promotion/promotion.grantreward.md).

# Promotion.grantReward

> 函数式 API `grantPromotionReward`也可以使用相同的功能。函数式 API 与 v2 相同 `{ params: { promotionCode, amount } }` 接收该形式的参数，如果是未支持的应用版本，则不是抛出错误，而是 `undefined`则返回。

### 功能说明

使用促销码向用户发放奖励（Toss 积分）。

Toss App **5.232.0** 可在以上版本中使用。调用前 `Promotion.grantReward.isSupported()`可通过它确认是否支持。若在不支持的版本中调用， `UNSUPPORTED_APP_VERSION` 会发生错误。

### 类型

```ts
Promotion.grantReward(params: { promotionCode: string; amount: number }): Promise<GrantPromotionRewardResponse>;
```

**Params**

```ts
{
  /** 这是促销码。 */
  promotionCode: string;
  /** 这是要发放的积分金额。 */
  amount: number;
}
```

**Response**

```ts
type GrantPromotionRewardResponse = {
  /** 这是奖励键。 */
  key: string;
};
```

* `{ key: string }`: 积分发放成功。 `key`是奖励键。

### 错误

如果积分发放失败，会抛出包含失败代码的错误。错误代码位于捕获到的错误的 `error.code` 值。

| 代码                        | 说明                                                                                                                   |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `UNSUPPORTED_APP_VERSION` | 如果当前运行的 Toss App 版本不支持此功能，调用后会立即发生。 `Promotion.grantReward.isSupported()`可通过它提前确认，发生时 `error.message`请向用户显示（更新提示文案）。 |
| `4100`                    | 无法找到促销信息时。                                                                                                           |
| `4104`                    | 促销已暂停时。                                                                                                              |
| `4105`                    | 促销已结束时。                                                                                                              |
| `4108`                    | 促销未获批准时。                                                                                                             |
| `4109`                    | 促销未处于进行中时。                                                                                                           |
| `4110`                    | 无法发放/回收奖励时。                                                                                                          |
| `4112`                    | 促销资金不足时。                                                                                                             |
| `4113`                    | 已经发放/回收过的记录时。                                                                                                        |
| `4114`                    | 超过促销中设置的单次发放金额时。                                                                                                     |
| `UNKNOWN_ERROR`           | 发生未知错误时。                                                                                                             |

函数式 API `grantPromotionReward`与 v2 相同，不会被 reject，而是将失败 `{ errorCode: string; message: string }` 值，或者 `'ERROR'` 以字符串返回。

### 示例代码

```js
import { Promotion } from "@apps-in-toss/web-framework";

async function handleGrantReward() {
  try {
    if (!Promotion.grantReward.isSupported()) {
      console.warn("该应用版本不受支持。");
      return;
    }

    const result = await Promotion.grantReward({
      promotionCode: "PROMOTION_CODE",
      amount: 1000,
    });

    console.log("积分发放成功！", result.key);
  } catch (error) {
    console.error("积分发放失败：", error.code, error.message);
  }
}

document
  .querySelector("#grant-reward")
  .addEventListener("click", handleGrantReward);
```


---

# 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://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/sdk/domains-api/promotion/promotion.grantreward.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.
