Search code examples
javascriptin-app-purchasewin-universal-appwindows-dev-center

Windows Universal App - In App Purchases


I have been working (slowly) through the in app purchase example. I have created 2 in app purchases in the Store for my app. I have linked Visual Studio to that app. I finally have not got any errors when I enter the callback function from requesting my in app purchases.

The error: It says there are 0 products when there should be 2.

My Code:

var ProductsARR = [];

var storeContext = Windows.Services.Store.StoreContext.getDefault();
var productKinds = ["Consumable", "Durable", "UnmanagedConsumable"];
storeContext.getAssociatedStoreProductsAsync(productKinds).then(function (addOns) {
    var i;
    if (addOns.extendedError) {
        if (addOns.extendedError === (0x803f6107 | 0)) {
            alert("This sample has not been properly configured.");
        } else {
            // The user may be offline or there might be some other server failure.
            alert("ExtendedError: " + addOns.extendedError.toString());
        }
    } else if (addOns.products.size === 0) {
        alert("No configured Add-ons found for this Store Product.");
    } else {
        for (i = 0; i < addOns.products.size;i++){
            var item = {
                title: addOns.products[i].title,
                price: addOns.products[i].price.formattedPrice,
                inCollection: addOns.products[i].isInUserCollection,
                productKind: addOns.products[i].productKind,
                storeId: addOns.products[i].storeId
            };

            ProductsARR .push(item);
        }
    }
});

What could be causing it to think there are no in app purchases where there are 2?

The only thing I think could be causing confusion is I have not submitted the actual xapproduct to the store yet, but I do not want to do that until I have fleshed out the rest of the code. I am working on the in app purchase code right now. Could that be causing the problem?

If not, what else could be causing the problem. It says in my dashboard that the in app purchase is 'In Store'.


Solution

  • The only thing I think could be causing confusion is I have not submitted the actual xapproduct to the store yet, but I do not want to do that until I have fleshed out the rest of the code.

    You're using Windows.Services.Store namespace, which doesn't provide a class that you can use to simulate license info during testing, unlike Windows.ApplicationModel.Store provding the CurrentAppSimulator class . So you must publish the app and download it to your development device to use its license for testing.

    For testing purpose, this app doesn't need to be your real version but a basic app that meets minimum Windows App Certification Kit requirements. Also, you could choose to hide this app first to prevent customers from seeing your app during your test.

    For more details about testing guidance, you might refer to Test your in-app purchase or trial implementation.