【问题标题】:In app purchases Cordova Plugin应用内购买 Cordova 插件
【发布时间】:2026-01-11 10:45:01
【问题描述】:

我为我的 IOS 应用 (https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#refresh) 使用 Cordova 插件应用内购买。

我完全按照他们的代码示例所示:

  store.register({
         id: 'credits_test',
          alias: 'credits_advance',
          type: store.CONSUMABLE
  });

  store.refresh();

 store.when("credits_test").approved(function (product) {
            product.finish();
            updateCreditsPurchased(p.token, 1, product ints[0]);
        });

    $(".btn").click(function()
    {
       store.order("credits_test");
    })

我在 store 对象上没有任何验证器,我使用我的沙盒帐户进行测试。

现在由于某种原因,产品状态始终为“有效”,即使在我触发“完成”事件之前的 APPROVED 事件中,我还在控制台日志中看到产品卡在队列中..

有什么想法吗?

【问题讨论】:

    标签: javascript ios cordova in-app-purchase cordova-plugins


    【解决方案1】:

    这是正确的行为,因为您选择了CONSUMABLE 的产品类型

    完成后,一个消耗品会回到 VALID 状态,而其他会进入 OWNED 状态。

    尝试使用NON-CONSUMABLE 产品类型。

    来源:https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md

    【讨论】:

    • 在我的情况下,我必须使用 CONSUMABLES,即使在我调用“product.finish()”之前的 APPROVED 事件中,“有效”状态也始终存在。
    • 您使用哪个工具进行调试?一些工具,如 Chome 调试器,在第一次打开数组/对象时会对其进行快照。也许尝试将 product.state 保存到变量中以进行调试?
    • 它是 Safari 调试器,因为它是一个 ios 应用程序