Harry
Harry

Reputation: 3106

In-App Purchases Development Testing with CurrentAppSimulator

I have set up in-app purchasing with the CurrentAppSimulator, and set up the functionality to get the in-app purchase. I have also (possibly) configured my WindowsStoreProxy.xml file to handle this.

However, when I purchase the addon and give it an S_OK value to return, it still says the IAP is inactive. The only way I can get it active is to manually edit the WindowsStoreProxy.xml file and set the Active property to Active. This appears to be quite odd as the Store sample from Microsoft works fine. I couldn't see anything different on their part though - they still use the CurrentAppSimulator.RequestProductPurchaseAsync() method. Where am I going wrong here...?

Upvotes: 4

Views: 1693

Answers (1)

Martin Suchan
Martin Suchan

Reputation: 10620

First I use my own class CurrentAppProxy, that uses CurrentAppSimulator in Debug mode and CurrentApp in Release. Then I use this code for buying the InApp purchase, it works just fine:

try
{
    await CurrentAppProxy.RequestProductPurchaseAsync(PremiumName, false);

    // after closing the inApp purchase dialog, test, if it was bought
    if (licenseInformation.ProductLicenses[PremiumName].IsActive)
    {
        // set the local flag
        IsPremium = true;

        dialog = new MessageDialog(resourceLoader.GetString("ThanksForPremium"));
        await dialog.ShowAsync();
    }
    // else do not show anything
}
catch (Exception)
{
    // failed buying the premium
    dialog = new MessageDialog(resourceLoader.GetString("ErrorBuyingPremium"));
    dialog.ShowAsync();
}

edit: before accessing these properties, I initialize the CurrentAppSimulator in Debug mode using this:

StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
StorageFile proxyFile = await proxyDataFolder.GetFileAsync("test-purchase.xml");
await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

and at the bottom of test-purchase.xml I got:

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

Upvotes: 6

Related Questions