用户发起商品购买监听

业务场景

用户发起商品购买监听的回调,用来处理不同渠道侧推送给用户礼包后,用户点击了购买之后,CP 侧需要在回调里面发起支付流程。

适用范围:微信 | 抖音

流程图

接口介绍

onBuyProduct(cb: (info: EworldSDK.BuyProductInfo) => void): void

调用示例

SDKManager.onBuyProduct((info) => {
  // 用户购买商品监听回调
  // 小额/直接支付
  info.payType === 2 &&
    SDKManager.pay({
      amount: (info.data.amount / 100).toFixed(2),
      productId: info.data.productId,
      extstr: JSON.stringify(info),
      productName: info.data.productName,
      ... // 其他支付参数
    });
});

参数说明

入参

BuyProductInfo info

参数名称类型说明最低版本
payTypeint支付类型,回传给支付 API 即可
dataBuyProductDataInfo需要支付的商品信息

int payType

枚举值说明
1虚拟支付(默认)
2小额/直接支付【抖音】
3礼包支付【抖音】
4商业组件【微信】

BuyProductDataInfo data

参数名称类型说明最低版本
amountint价格,单位:分
productIdstringCP 商品 ID
productNamestring商品名
giftIdstring礼包 ID(礼包支付的时候返回)

错误码

FAQ