9

Well, I'm almost done with Cordova in-app purchasing to get it work in windows sandbox mode. I have gone through this thread and tried in all possible way to make it but I couldn't. I have placed in-app-purchase.xml in www folder as per the instruction. Code follows.

 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>

And the screen shot below is my nightmare - Error.

enter image description here

I had tried store.inappbilling.setTestMode(); but it's logging the error

Object doesn't support property or method 'setTestMode'

Resources used

I also tried dkarzon forks that as well doesn't work for me.

I'm about to reach the dead end of the tasks. Pl. someone helps me out. It' vital.

Update -> 1

As per dkarzon's instruction I have used the library from main repo and registered store.inappbilling.setTestMode() with callback and it triggers the failure call back. It's giving an error missing command error when I declared function error call back with arg. Pl. note that I'm directly testing the app, not from the store. Here is the code snippet I used to do. Now, It skips the sandbox mode and showing the windows purchase dialog with selected add-ons directly likewise in production.

Update -> 2

I debugged and figured out that the folder.getFileAsync("in-app-purchase.xml") failing to executes and returns an error initially Input data not in expected format then I have edited the file by following the structure of WindowsStoreProxy.xml, now it's giving an error The parameter is incorrect.

enter image description here

Here is my updated 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>

Update -> 3

My bad, After a deep debug I found that I've given Package Identity instead of AppId in XML and that cause to the issue and this also helped me out. Generated app id using Windows.ApplicationModel.Store.CurrentApp.AppId and hence I'm able to see the purchase simulate pop up. all the error code is triggering callbacks but when I select S_OK it returns nothing. I have gone through this SO post but it doesn't work, unfortunately.

enter image description here

Updated 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>
Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
Stella
  • 1,817
  • 6
  • 30
  • 55
  • 2
    Have you tried using the plugin from the main repo instead of a fork? Windows fixed have been merged into master last I checked. `setTestMode` doesn't exist on that branch you are looking at. – dkarzon May 22 '17 at 05:48
  • Thanks for your kind consideration **@dkarzon**. Yes, I have tried the latest [version(6.1.2)](https://github.com/j3k0/cordova-plugin-purchase) from the main repo of `j3k0` and enabled sandbox mode using `store.inappbilling.setTestMode()` with callback and it triggers the failure call back. pl. note that I'm directly testing the app, not from the store. Here is the [code snippet](https://pastebin.com/UuRigSfN) I used to do. – Stella May 22 '17 at 12:05
  • It skips the sandbox mode and showing the windows purchase dialog with selected `add-ons` directly likewise in production. – Stella May 22 '17 at 12:53
  • It's giving an error `missing command error` when I declared function [error call back](https://pastebin.com/Qjb2QezX) with arg. – Stella May 22 '17 at 13:56
  • 1
    What do you mean by `windows edge simulator for testing`? – dkarzon May 24 '17 at 00:24
  • Sorry, my bad. I mean I used windows 10 desktop application/Local device for testing the app. – Stella May 24 '17 at 11:26
  • It's throwing the same error `missing command error` when testing in windows mobile simulator as well. when using `store.sandbox = true` as mentioned in the main repo [Documentation for Windows](https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/windows.md) it says `Init failed - undefined` :( – Stella May 24 '17 at 12:09
  • 1
    Are you able to debug the plugin js to see at what point it fails? – dkarzon May 25 '17 at 06:09
  • It's breaking here `return cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "setTestMode", [""]);` . there is no command `setTestMode`. – Stella May 25 '17 at 06:57
  • 2
    Ok, you need to set `store.sandbox = true;` to tell it to use the simulator instead of anything else you are trying to do. Make that call before your call to `store.refresh` and it will set it up for you. Then debug `InAppPurchaseProxy.js` to see what is failing in there. You also need to use the real package not one of the branches since this has changed a few times. – dkarzon May 26 '17 at 01:13
  • Yes, I have made the call to `store.sandbox=true` before `store.refresh` as you can see code snippet in the query. and I have cloned https://github.com/j3k0/cordova-plugin-purchase.git to ensure I'm in the latest revision. Even though I'm triggering `store.sandbox=true` it fails to find out the native method `init` at the line `cordova.exec(success, errorCb(fail), "InAppBillingPlugin", "init", [skus]);`. BTW, Let me debug it if you have any further idea on this pl. let me know. Thank u. – Stella May 26 '17 at 05:12
  • Pl. see the update in query *@dkarzon* – Stella May 26 '17 at 09:20
  • `approved` call back is not triggering. – Stella May 26 '17 at 09:33

1 Answers1

1

Finally, things are working fine now I got the approved callback. thanks to all for the support especially to @dkarzon who find time in b/w busy life.

I added one of the product as active under LicenseInformation tag as well. Update -> 3 in the query has the other step to get rid of these kind of issue, see that as a reference if any one face difficulty to make windows sandbox mode work in future.

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

References

Stella
  • 1,817
  • 6
  • 30
  • 55