【问题标题】:J3k0 cordova-plugin-purchase sandbox mode not working?J3k0 cordova-plugin-purchase 沙盒模式不起作用?
【发布时间】:2017-05-21 18:21:08
【问题描述】:

好吧,我几乎完成了 Cordova 应用内购买,让它在 Windows 沙盒模式下工作。我已经通过this 线程并尝试了所有可能的方式来实现它,但我做不到。我已按照说明将in-app-purchase.xml 放在www 文件夹中。代码如下。

 store.verbosity = store.QUIET;
 store.sandbox=true;

                store.register({
                    id: productId,
                    type: store.PAID_SUBSCRIPTION
                });

                // Listen to the 'updated' event for individual product
                store.when(productId).updated(function (p) {
                    $ionicLoading.hide();
                });

                // Initiate a purchase
                store.order(productId);

                // When the purchase is approved, show an alert
                store.when(productId).approved(function (order) {
                    Store.subscribeWindows(month, order);
                    order.finish();
                });

                // When the purchase is approved, show an alert
                store.when(productId).cancelled(function (order) {
                    $ionicPopup.alert({
                        title: 'Subscribe was cancelled!',
                        template: 'Try again!'
                    });
                    order.finish();
                });

                // When the store is ready all products are loaded and in their "final" state.
                store.ready(function () {
                    console.log("The store is ready");
                });

                // Deal with errors:
                store.error(function (err) {
                    $ionicLoading.hide();
                    $ionicPopup.alert({
                        title: 'Something went wrong',
                        template: err.message
                    });
                })


                // This will contact the server to check all registered products validity and ownership status.
                // It's mostly fine to do this only at application startup but you can refresh it more often.
                store.refresh();

            }

in-app-purchase.xml

<?xml version="1.0" encoding="utf-8" ?>
<CurrentApp>
  <ListingInformation>
    <App>
      <AppId>CN=CB5BB00C-6A35-44A7-B46E-013721E959BD</AppId>
      <LinkUri>https://www.microsoft.com/store/apps/9nblggh3tvsk</LinkUri>
      <CurrentMarket>en-us</CurrentMarket>
      <AgeRating>12</AgeRating>
      <MarketData xml:lang="en-us">
        <Name>App Name</Name>
        <Description>App Description</Description>
        <Price>0</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
      </MarketData>
    </App>
    <Product ProductId="com.product.premium365" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>com.product.premium365</Name>
        <Price>59.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
      </MarketData>
    </Product>
    <Product ProductId="Product03" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>Product03</Name>
        <Price>14.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
        xmlfile.xml
      </MarketData>
    </Product>
    <Product ProductId="com.product.premium6" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>com.product.premium6</Name>
        <Price>29.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
      </MarketData>
    </Product>
    <Product ProductId="com.product.premium" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>com.product.premium</Name>
        <Price>4.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
      </MarketData>
    </Product>
  </ListingInformation>
  <LicenseInformation>
    <App>
      <IsActive>true</IsActive>
      <IsTrial>false</IsTrial>
    </App>
    <!-- Setting a prepurchased durable -->
    <Product ProductId="com.product.premium365">
      <IsActive>true</IsActive>
    </Product>
  </LicenseInformation>
</CurrentApp>

下面的屏幕截图是我的噩梦 - 错误。

我曾尝试过store.inappbilling.setTestMode();,但它正在记录错误

Object doesn't support property or method 'setTestMode'

使用的资源

我还尝试了 dkarzon 叉子,但对我也不起作用。

我即将到达任务的尽头。 PL。有人帮忙 我出去。这很重要。

更新 -> 1

根据 dkarzon 的 指令,我使用了主仓库中的库并注册了 store.inappbilling.setTestMode() 回调,它会触发失败回调。当我用 arg 声明函数 error call back 时,它给出了错误 missing command error。 PL。请注意,我是直接测试应用程序,而不是来自商店。这是我以前做的code snippet。现在,它跳过沙盒模式并直接在生产中显示带有选定add-ons 的 Windows 购买对话框。

更新 -> 2

我调试并发现folder.getFileAsync("in-app-purchase.xml") 无法执行并最初返回错误Input data not in expected format 然后我按照WindowsStoreProxy.xml 的结构编辑了文件,现在它给出了错误The parameter is incorrect

这是我更新的 XML

<?xml version="1.0" encoding="utf-16" ?>
<CurrentApp>
  <ListingInformation>
    <App>
      <AppId>CN=CB5BB00C-6A35-44A7-B46E-013721E959BD</AppId>
      <LinkUri>https://www.microsoft.com/store/apps/9nblggh3tvsk</LinkUri>
      <CurrentMarket>en-us</CurrentMarket>
      <AgeRating>12</AgeRating>
      <MarketData xml:lang="en-us">
        <Name>App Name</Name>
        <Description>App Decription</Description>
        <Price>0.00</Price>
        <CurrencySymbol>$</CurrencySymbol>
      </MarketData>
    </App>
    <Product ProductId="com.product.premium" LicenseDuration="10" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>com.product.premium</Name>
        <Price>4.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
      </MarketData>
    </Product>
    <Product ProductId="Product03" LicenseDuration="0" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>Product03</Name>
        <Price>14.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
      </MarketData>
    </Product>
  </ListingInformation>
  <LicenseInformation>
    <App>
      <IsActive>true</IsActive>
      <IsTrial>false</IsTrial>
    </App>
    <Product ProductId="com.product.premium">
      <IsActive>true</IsActive>
      <ExpirationDate>2018-01-19T00:00:00.00Z</ExpirationDate>
    </Product>
  </LicenseInformation>
</CurrentApp>

更新 -> 3

我的错,经过深入调试后,我发现我在 XML 中给出了包标识而不是 AppId,这导致了问题,this 也帮助了我。使用Windows.ApplicationModel.Store.CurrentApp.AppId 生成的应用程序ID,因此我可以看到购买模拟弹出。所有错误代码都在触发回调,但是当我选择 S_OK 时,它什么也不返回。我已经通过了这个SO post,但不幸的是它不起作用。

更新的 XML

<?xml version="1.0" encoding="utf-16" ?>
<CurrentApp>
  <ListingInformation>
    <App>
      <AppId>fb9ec87b-54b-46f-b1e6-87d857dfa730</AppId>
      <LinkUri>http://apps.windows.microsoft.com/app/988b90e4-5d4d-4dea-99d0-e423e414fbc</LinkUri>
      <CurrentMarket>en-us</CurrentMarket>
      <AgeRating>12</AgeRating>
      <MarketData xml:lang="en-us">
        <Name>App Name</Name>
        <Description>App Description</Description>
        <Price>0.00</Price>
        <CurrencySymbol>$</CurrencySymbol>
      </MarketData>
    </App>
    <Product ProductId="com.product.premium" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>com.product.premium</Name>
        <Price>4.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
      </MarketData>
    </Product>
    <Product ProductId="Product03" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>Product03</Name>
        <Price>14.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
      </MarketData>
    </Product>
    <Product ProductId="com.product.premium6" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>com.product.premium6</Name>
        <Price>29.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
      </MarketData>
    </Product>
    <Product ProductId="com.product.premium365" ProductType="Durable">
      <MarketData xml:lang="en-us">
        <Name>com.product.premium365</Name>
        <Price>59.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
        <CurrencyCode>USD</CurrencyCode>
      </MarketData>
    </Product>

  </ListingInformation>
  <LicenseInformation>
    <App>
      <IsActive>true</IsActive>
      <IsTrial>false</IsTrial>
    </App>
  </LicenseInformation>

</CurrentApp>

【问题讨论】:

  • 您是否尝试过使用主仓库中的插件而不是分叉?我上次检查的 Windows 已修复已合并到 master 中。 setTestMode 在您正在查看的那个分支上不存在。
  • 感谢您的关心@dkarzon。是的,我已经从j3k0 的主仓库中尝试了最新的version(6.1.2),并使用带有回调的store.inappbilling.setTestMode() 启用了沙盒模式,它会触发失败回调。 pl。请注意,我是直接测试应用程序,而不是来自商店。这是我以前做的code snippet
  • windows edge simulator for testing 是什么意思?
  • 能不能调试插件js看看什么时候失败?
  • 好的,你需要设置store.sandbox = true; 告诉它使用模拟器而不是你想要做的任何其他事情。在您致电store.refresh 之前拨打电话,它会为您设置好。然后调试InAppPurchaseProxy.js 看看那里有什么问题。您还需要使用真正的包而不是分支之一,因为这已经更改了几次。

标签: cordova in-app-purchase


【解决方案1】:

最后,现在我收到了approved 回调,一切正常。感谢大家的支持,尤其是@dkarzon,他们在忙碌的黑白生活中抽出时间。

我还在LicenseInformation 标签下添加了其中一款产品作为活动产品。查询中的 Update -> 3 有另一个步骤来摆脱这类问题,如果有人在将来难以使 windows 沙盒模式工作,请参阅作为参考。

<LicenseInformation>
    <App>
      <IsActive>true</IsActive>
      <IsTrial>false</IsTrial>
    </App>
    <Product ProductId="com.animecrave.premium">
      <IsActive>true</IsActive>
    </Product>
  </LicenseInformation>

参考文献

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 1970-01-01
    • 2019-04-03
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    相关资源
    最近更新 更多