I am trying to implement in-app purchase into my WinRT appliation using desktop bridge and Windows App SDK with WinUI 3. I have simple method:
class TransactionService
{
void buyOrRestore() {
....
ComPtr<IAsyncOperation<StorePurchaseResult*>> purchaseOperation;
hr = storeContext->RequestPurchaseWithPurchasePropertiesAsync(HStringReference(kItemStoreId).Get(), purchaseProperties.Get(), &purchaseOperation);
CheckHr(hr);
}
}
Following code always print error into output:
info:StoreContextServer::Initialize: packageFullName = PurchaseTester, productStoreId = 123, isLicensed = true, isAppContainer = false [Windows::Services::Store::Internal::StoreContextServer::Initialize]
info:Windows::Services::Store::StoreContext::RequestPurchaseWithPurchasePropertiesAsync(abc) invoked. (CV:8glMygpFo0+UMRKk.2.3) [Windows::Services::Store::StoreContext::RequestPurchaseWithPurchasePropertiesAsync]
Exception thrown at 0x00007FFE7BB5474C (KernelBase.dll) in PurchaseTester.exe: WinRT originate error - 0x80070578 : 'This function must be called from a UI thread'.
buyOrRestore
method is called directly from MainWindow.xaml.cpp
after button click like:
void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
auto transactionService = new TransactionService();
transactionService->buyOrRestore();
}