Polyv Help Center

Help Center

Donation Feature

Updated: 2025-11-19 16:08:38

1. Get Channel Donation Configuration

Starting from v1.2.0, you can use PlvDonateModule.generateDefaultDonateConfig() to get the default configuration.

API Method: getDonateConfig(): DonateConfig

Return Value Description: Channel donation configuration, type DonateConfig. Detailed type description is as follows:

Property Name Description Type
donateCashMin Minimum cash donation limit number
donateCashQuickOptions Cash donation amount list number[]
donateCashEnabled Cash donation toggle boolean
donateGoodEnabled Item (cash) donation toggle boolean
donatePointEnabled Item (points) donation toggle boolean
donatePointUnit Points gift unit string
donateScoreUnit Points unit string

Example:

const donateConfig = watchCore.donate.getDonateConfig();
console.log('现金打赏开关', donateConfig.donateCashEnabled);
console.log('现金礼物打赏开关', donateConfig.donateGoodEnabled);
console.log('积分礼物打赏开关', donateConfig.donatePointEnabled);

2. Check Whether to Display Cash Donation

API Method: isShowDonateCash(): boolean

Return Value Description: Whether to display cash donation

Example:

const check = watchCore.donate.isShowDonateCash();
if (check) {
  // TODO:显示现金打赏
} else {
  // TODO:隐藏现金打赏
}

3. Check Whether to Display Cash Item Donation

API Method: isShowDonateCashGood(): boolean

Return Value Description: Whether to display cash item donation

Example:

const check = watchCore.donate.isShowDonateCashGood();
if (check) {
  // TODO:显示现金道具打赏
} else {
  // TODO:隐藏现金道具打赏
}

4. Check Whether to Display Points Item Donation

API Method: isShowDonatePointGood(): boolean

Return Value Description: Whether to display points item donation

Example:

const check = watchCore.donate.isShowDonatePointGood();
if (check) {
  // TODO:显示积分道具打赏
} else {
  // TODO:隐藏积分道具打赏
}

5. Check Whether It Is a Free Gift

Determine if a gift is free based on the donation item name and the donation settings configured in the admin panel. Returns false if the item is not in the configuration.

API Method: isFreeReward(rewardContent: string): boolean

Parameter Description:

  • rewardContent: Donation content (item name), type string, required

Example:

const check = watchCore.donate.isFreeReward('鲜花');
if (check) {
  console.log('礼物是免费的');
} else {
  console.log('礼物是收费的');
}

6. Get Donation Item Information

Retrieve donation item information set in the admin panel, such as points donation items and cash donation items.

API Method: getDonateGoods(): Object

Return Value Description: Type Object. Detailed type description is as follows:

Property Name Description Type
goods Currently supported donation items DonateGoodData[]
cashGoods Cash items DonateGoodData[]
pointGoods Points items DonateGoodData[]

Example:

const info = watchCore.donate.getDonateGoods();
console.log('当前支持显示的打赏道具', info.goods);
console.log('后台设置的现金道具', info.cashGoods);
console.log('后台设置的积分道具', info.pointGoods);

7. Pay Donation

When a viewer makes a donation, call payDonate to process it. After calling, you can query the payment status using the payment record ID logId.

API Method: payDonate(params: PayDonateParams): Promise<PayDonateData>

Parameter Description:

  • params: Donation content, type PayDonateParams, required. Detailed type description is as follows:
Parameter Name Description Type Required Default Value
donateType Donation type DonateType Yes -
goodId Item donation item ID string No -
goodCount Donation quantity number No -
amount Cash donation amount, unit: yuan string | number No -

Return Value Description: Donation payment data, type Promise<PayDonateData>. Detailed type description is as follows:

Property Name Description Type
donateType Donation type DonateType
isFree Whether it is a free gift boolean
logId Payment record ID string
goodId Donation item ID string
goodCount Donation quantity number
amount Cash donation amount string | number
codeUrl Payment URL string
qrCodeUrl Payment QR code URL, only exists for paid gifts string
wxPaySignData WeChat Pay signature data WxPaySignData

Example:

import { DonateType } from '@polyv/live-watch-sdk';

// 现金打赏
const payData = await watchCore.donate.payDonate({
  donateType: DonateType.Cash,
  amount: '1.2', // 1.2 元
});

// 道具打赏
const payData = await watchCore.donate.payDonate({
  donateType: DonateType.Good,
  goodId: 'xxx',
  goodCount: 2,
});

// 调用后的处理
if (payData.isFree) {
  // 免费道具,无需支付
  return;
}

if (isPC) {
  // PC 端使用扫码支付
  toast.success('显示支付二维码', payData.qrCodeUrl);
  return;
}

if (isMobile && isWeixin) {
  // 移动端微信环境下调用微信 JSSDK 支付接口
  const wxPaySignData = payData.wxPaySignData;
  wx.chooseWXPay({
    timestamp: wxPaySignData.timestamp,
    nonceStr: wxPaySignData.nonceStr,
    package: wxPaySignData.package,
    signType: wxPaySignData.signType,
    paySign: wxPaySignData.paySign,
    success: () => {
      toast.success('支付成功');
    },
    fail: () => {
      toast.success('支付失败');
    },
  });
  return;
}

toast.error('请使用微信客户端打开');

8. Check Donation Payment Status

API Method: checkDonatePayStatus(params: CheckDonatePayStatusParams): Promise<DonatePayStatusData>

Parameter Description:

  • params: Type CheckDonatePayStatusParams, required. Detailed type description is as follows:
Parameter Name Description Type Required Default Value
logId Record ID string Yes -
donateType Donation type DonateType Yes -

Return Value Description: Donation payment status data, type Promise<DonatePayStatusData>. Detailed type description is as follows:

Property Name Description Type
paySuccess Whether payment was successful boolean

9. Get Current User's Remaining Donation Points

API Method: getDonateSurplusPoint(): Promise<number>

Return Value Description: Type Promise<number>

10. Pay Points Donation

API Method: payDonatePoint(params: PayDonatePointParams): Promise<number>

Parameter Description:

  • params: Type PayDonatePointParams, required. Detailed type description is as follows:
Parameter Name Description Type Required Default Value
goodId Item donation item ID string Yes -
goodCount Donation quantity number Yes -

Return Value Description: Returns remaining points, type Promise<number>

11. Get Donation SVGA URL

API Method: getDonateSvgaUrl(gimg: string): undefined | string

Supported from v1.0.0

Parameter Description:

  • gimg: Donation image URL, type string, required

Return Value Description: Type undefined | string

联系客服,在线咨询