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.
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
.
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.
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With