Can someone suggest a working method to purchase an add-on from within the app?
In my application, which is published in the Microsoft Store, I have a single add-on (a subscription). Since the official documentation states:
Selling subscriptions to customers directly via the Store is not supported at this time. Subscriptions are available for in-app purchases of digital products only.
I understand that I need to implement the purchase of this add-on manually within the app.
I found this sample as a starting point, but the author mentions it "generates an exception":
function TForm1.PurchaseItem(Item: string) : string;
begin
for var i := 0 to WindowsStore1.AppProducts.Count - 1 do
if TWindowsString.HStringToString(WindowsStore1.AppProducts[i].InAppOfferToken) = Item then begin
BuyProduct(WindowsStore1.AppProducts[i]);
exit;
end;
end;
procedure TForm1.BuyProduct(Product: IStoreProduct);
begin
try
var status := WindowsStore1.PurchaseProduct(Product);
if status = StorePurchaseStatus.Succeeded then
begin
EnableFullVersion;
end
else begin
//;
end;
except
On e : Exception do
//;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PurchaseItem('MyAddon');
end;
So, what is the correct way to let a user purchase my subscription add-on from within the app using the TWindowsStore component in Delphi (12.1)?