For the complete documentation index, see llms.txt. This page is also available as Markdown.

Promotion.grantReward

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

功能说明

使用促销码向用户发放奖励(Toss 积分)。

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

类型

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

Params

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

Response

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' 以字符串返回。

示例代码

这有帮助吗?