I am trying the in app purchase API (C++/CX) and RequestProductPurchaseAsync throws an Platform::InvalidArgumentException^
I have the following code:
// loading store
create_task(CurrentAppSimulator::LoadListingInformationAsync()).then([](ListingInformation^ listing)
{
auto product1 = listing->ProductListings->Lookup("product1");
auto product2 = listing->ProductListings->Lookup("product2");
});
//after that finishes I try to purchase product2
auto licenseInformation = CurrentAppSimulator::LicenseInformation;
if (!licenseInformation->ProductLicenses->Lookup("product2")->IsActive)
{
// this exact next line throws InvalidArgumentException
auto op = CurrentAppSimulator::RequestProductPurchaseAsync("product2", true); // throws !!!!!
auto purchaseTask = create_task(op);
purchaseTask.then([](task<Platform::String^> currentTask)
{
...
});
}
else ...
This exact same code works if it’s used in the Windows Store sample project, but it doesn’t work in my own project. (With the same fake products xml file obviously).
Can anyone have a look ? Thank you 🙂
I found the solution: all WinRT store functions have to be called on the UI thread, so obtain a CoreDispatcher from your UI thread and keep it to call those functions through that.