J3k0 cordova-plugin-购买沙箱模式无效?

时间:2017-05-21 18:21:09

标签: cordova in-app-purchase

好吧,我几乎完成了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();

            }

应用程式-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>

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

enter image description here

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

Object doesn't support property or method 'setTestMode'

使用的资源

我也试过dkarzon分叉,但对我来说也不起作用。

  

我即将完成任务的死胡同。 PL。有人帮忙   我出去它&#39;是至关重要的。

更新 - &gt; 1

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

更新 - &gt; 2

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

enter image description here

  

这是我更新的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>

更新 - &gt; 3

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

enter image description here

  

更新了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>

1 个答案:

答案 0 :(得分:1)

最后,事情正常,我得到了approved回调。感谢所有人的支持,特别是{/ 3}}在短暂的忙碌生活中找到时间。

我在LicenseInformation标记下添加了一个有效的产品。 更新 - &gt; 3 在查询中还有另一个步骤来摆脱这类问题,如果有任何一个面临困难的话,请将其视为一个参考,以使Windows沙箱模式在将来工作。

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

参考