WP8.1 Silverlight - Unexpected License info on LicenseChanged

46 views Asked by At

I am trying to detect In-App-Purchases made by a client app.

I am using the following code

public async Task InitializeInAppPurchase()
{
    CurrentApp.LicenseInformation.LicenseChanged += LicenseInformation_LicenseChanged;
    var listingInformationTask = CurrentApp.LoadListingInformationAsync();
    var listingInformation = await listingInformationTask;
    PurchaseProduct(listingInformation.ProductListings.First().Value.ProductId);
}

private void LicenseInformation_LicenseChanged()
{
    var receipt = CurrentApp.GetAppReceiptAsync().AsTask().Result;
    Console.Writeline(receipt);
}

async void PurchaseProduct(string productId)
{
    try
    {
        // Kick off purchase; don't ask for a receipt when it returns
        var result = await CurrentApp.RequestProductPurchaseAsync(productId);

        // Now that purchase is done, give the user the goods they paid for
        // (DoFulfillment is defined later)
        await DoFulfillment(result);
    }
    catch (Exception ex)
    {
        // When the user does not complete the purchase (e.g. cancels or navigates back from the Purchase Page), an exception with an HRESULT of E_FAIL is expected.
    }
}

//
// Fulfillment of consumable in-app products
public async Task DoFulfillment(PurchaseResults result)
{
    var productLicenses = CurrentApp.LicenseInformation.ProductLicenses;

    // Check fulfillment for consumable products with hard-coded asset counts
    await MaybeGiveMeGold(productLicenses["Test1"], 50, result);
}

// Count is passed in as a parameter
async Task MaybeGiveMeGold(ProductLicense license, int goldCount, PurchaseResults result)
{
    if (license.IsConsumable && license.IsActive)
    {
        await CurrentApp.ReportConsumableFulfillmentAsync(license.ProductId, result.TransactionId);
    }
}

When the event LicenseChanged is raised, I am surprised to see that the receipt does not include the transaction which just occurred. I get this

 <Receipt Version="1.0" ReceiptDate="2015-06-18T04:41:31.867Z" ReceiptDeviceId="4e362949-acc3-fe3a-e71b-89893eb4f528" CertificateId="FB3D3A6455095D2C4A841AA8B8E20661B10A6112" xmlns="http://schemas.microsoft.com/windows/2012/store/receipt">
    <AppReceipt Id="8ffa256d-eca8-712a-7cf8-cbf5522df24b" AppId="01e34c43-fdd8-47a6-a8ba-36ad5b880de9" PurchaseDate="2015-06-18T04:41:31.867Z" LicenseType="Full" />
</Receipt>

whereas the receipt should include a element as documented here

I am using the emulator and I am also using a mock server hosted locally in IIS to return my fake ProductListings from here

Can anyone tell me if there is something that I am doing wrong or if this simply what has been designed by Microsoft? I know that In App Purchases behave differently on emulators, does anyone know if I would have had the expected behavior if I were using a real device?

Thank you

1

There are 1 answers

0
Hamady C. On BEST ANSWER

That behavior was normal because the Marketplace mock hosted locally could not return receipts for any transactions.

To test my In-App-Purchases, I had to

  • Publish my app in beta mode

  • Create test IAPs at 0.00$

The code above worked perfectly and the LicenseChanged events is raised almost instantaneously depending on network conditions.