更新记录

2.0.0(2024-07-11)

1、更新插件,支持谷歌V6支付

1.3.0(2023-07-22)

1、解决订阅异常问题

1.2.2(2023-06-25)

1、解决doPayAll方法支付成功没有回调问题 2、新增查询历史支付订单记录方法:doQueryPurchaseHistory

查看更多

平台兼容性

Android Android CPU类型 iOS
适用版本区间:4.4 - 14.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 ×

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


Google Pay V6 , 谷歌V6支付,谷歌支付

插件仅支持Android版本

插件提供的方法 -- 详情请参考demo

谷歌版本:6.0.1

  • doInit

    • 初始化
  • doQuerySku

    • 查询sku
  • doPay

    • 支付
  • doPayAll

    • 支付,支持更多参数
  • doConsume

    • 确认交易--消耗品
  • doAcknowledgePurchase

    • 确认交易--非消耗品(订阅商品)
  • doQueryPurchases

    • 查询当前购买交易
  • doQueryPurchaseHistory

    • 查询历史记录

引用插件

const GooglePayV6 = uni.requireNativePlugin('GT-GooglePay__PayModule');

使用插件代码如下,更多代码请参考Demo

/**
 * 初始化
 */
doInit() {
    let that = this;
    GooglePayV6.doInit({}, e => {
        if (e.code == 200) {
            // 初始化成功
            console.log('初始化成功');
            that.showToast('初始化成功');
        } else {
            // 初始化失败
            console.log('初始化失败');
            that.showToast('初始化失败');
        }
    });
},

/**
 * 查询sku
 */
doQuerySku() {
    let that = this;
    let params = {};
    if (this.isInapp) { //消耗商品
        params = {
            inapp: ['google_product_21', '20000'] // 与subs二选一
            // subs: ["10000"],
        }
    } else { //订阅商品
        params = {
            subs: ["10000"],
        }
    }
    GooglePayV6.doQuerySku(params, e => {
        console.log('查询结果:', e);
        that.showToast('查询结果:' + JSON.stringify(e));
        if (e.code == 200) {
            // 查询成功
            // e.list; // 查询结果, array
            that.prdList = e.list;
        } else {
            // 查询失败
            console.log('查询失败');
        }
    });
},

/**
 * 发起支付
 * 支付参数为查询sku结果的某一项
 */
doPay() {
    let that = this;
    console.log('do pay function.');
    if (that.prdList == null ||
        that.prdList.length == 0 ||
        !that.prdList[0].productId) {
        that.showToast('产品不能为空,不可支付');
        return;
    }
    GooglePayV6.doPay({
        productId: that.prdList[0].productId,
        offerToken: '', //可选,折扣token
    }, e => {
        console.log('支付结果:', e);
        that.showToast('支付结果:' + JSON.stringify(e));
        if (e.code == 200) {
            // 支付成功
            console.log('支付成功: ', e);
            if (e && e.data) {
                that.payList = e.data;
            }
        } else {
            // 支付失败
            console.log('支付失败: ', e);
        }
    });
},

/**
 * 发起支付2
 * 支付参数为查询sku结果的某一项
 */
doPayAll() {
    let that = this;
    console.log('do pay function.');
    if (that.prdList == null ||
        that.prdList.length == 0 ||
        !that.prdList[0].productId) {
        that.showToast('产品不能为空,不可支付');
        return;
    }
    GooglePayV6.doPayAll({
        productId: that.prdList[0].productId,
        offerToken: '', //可选,折扣token
        accountId: "", // 可选,用户Id
        profileId: "", // 可选,个人资料Id
    }, e => {
        console.log('支付结果:', e);
        that.showToast('支付结果:' + JSON.stringify(e));
        if (e.code == 200) {
            // 支付成功
            console.log('支付成功: ', e);
            if (e && e.data) {
                that.payList = e.data;
            }
        } else {
            // 支付失败
            console.log('支付失败: ', e);
        }
    });
},

/**
 * 确认交易,消耗品
 */
doConsume() {
    let that = this;
    console.log('do pay function.');
    if (that.payList == null ||
        that.payList.length == 0 ||
        !that.payList[0].purchaseToken) {
        that.showToast('支付信息不能为空');
        return;
    }
    //purchaseToken参数是支付结果中的purchaseToken字段或token字段
    GooglePayV6.doConsume({
        purchaseToken: that.payList[0].purchaseToken || that.payList[0].token
    }, e => {
        console.log('Consume结果:', e);
        that.showToast('Consume结果:' + JSON.stringify(e));
        if (e.code == 200) {
            console.log('Consume成功');
        } else {
            console.log('Consume失败');
        }
    });
},

/**
 * 确认交易,非消耗品
 */
doAcknowledgePurchase() {
    let that = this;
    console.log('do pay function.');
    if (that.payList == null ||
        that.payList.length == 0 ) {
        that.showToast('支付信息不能为空');
        return;
    }
    //original,signature两个参数不能为空,参数来自支付结果
    //original参数是支付结果中的original字段或originalJson字段
    GooglePayV6.doAcknowledgePurchase({
        original: that.payList[0].original || that.payList[0].originalJson || '',
        signature: that.payList[0].signature
    }, e => {
        console.log('acknowledgePurchase结果:', e);
        that.showToast('acknowledgePurchase结果:' + JSON.stringify(e));
        if (e.code == 200) {
            console.log('acknowledgePurchase成功');
        } else {
            console.log('acknowledgePurchase失败');
        }
    });
},
/**
 * 查询历史记录
 * 会返回用户针对每个商品发起的最近一笔购买记录,即使该购买交易已过期、已取消或已消耗,也仍会提取相关记录。
 */
doQueryPurchaseHistory() {
    let that = this;
    console.log('do doQueryPurchaseHistory function.');
    //参数inapp或subs
    GooglePayV6.doQueryPurchaseHistory(this.isInapp ? 'inapp' : 'subs', res => {
        console.log('doQueryPurchaseHistory result: ', res);
        that.showToast('queryPurchaseHistory结果:' + JSON.stringify(res));
    });
},

/**
 * 查询当前购买交易
 */
doQueryPurchases() {
    let that = this;
    console.log('do doQueryPurchases function.');
    //参数inapp或subs
    GooglePayV6.doQueryPurchases(this.isInapp ? 'inapp' : 'subs', e => {
        console.log('queryPurchases结果:', e);
        that.showToast('queryPurchases结果:' + JSON.stringify(e));
    });
},

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件支付功能使用Google SDK,参考其官方网站 https://policies.google.com/privacy

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问