> 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/cu-xiao/promotion.grantreward.md).

# Promotion.grantReward

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

### 功能说明

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

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

### 类型

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

**参数**

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

**响应**

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

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

### 错误

如果积分发放失败，会抛出包含失败代码的错误。错误代码是 catch 到的错误的 `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/cu-xiao/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.
