question

damichab avatar image
0 Votes"
damichab asked RoyLi-MSFT commented

In App Purchases Problems

I have written an app for the Microsoft Store. While I can see if license has been purchased or if still running under a trial period, I cannot for the life of me get the in-app purchase to work. I have followed various examples from both MS websites and elsewhere.

 private void testButton_Click(object sender, EventArgs e)
 {
     _ = SetStore();
 }



 [ComImport]
 [Guid("4AEEEC08-7C92-4456-A0D6-1B675C7AC005")]
 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
 private interface IInitializeWithWindow
 {
     void Initialize(IntPtr hwnd);
 }

 private async Task SetStore()
 {
     try
     {
         StoreContext theStore = StoreContext.GetDefault();

         // "Unable to cast object of type 'Windows.Services.Store.StoreContext' to type 'IInitializeWithWindow'."
         // IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)theStore;
         // initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);

         StoreProductResult app = await theStore.GetStoreProductForCurrentAppAsync();

         // This works...
         StoreProduct product = app.Product;
         string title = product.Title;
         string price = product.Price.FormattedPrice;

         // This works...
         StoreAppLicense license = await theStore.GetAppLicenseAsync();
         bool trial = license.IsTrial;
         bool full = license.IsActive;



         // "Invalid window handle.\r\n\r\nThis function must be called from a UI thread"
         //StorePurchaseResult result = await theStore.RequestPurchaseAsync("9NRFBVGVGW8K");

         // "Invalid window handle.\r\n\r\nThis function must be called from a UI thread" 
         // Windows.Foundation.IAsyncOperation<StorePurchaseResult> purchase = product.RequestPurchaseAsync();


     }
     catch (Exception e)
     {
         int a = 1;
     }

 }


The app is written in .NET with a UWP wrapper to create the MSIX package. The rem'ed lines indicate where I am having issues. Can anyone help me with these?

Otherwise, do I have to offer in app purchase for a trial program or can I just direct the user back to the Microsoft Store when they are ready to buy? As stated above, the code that checks for a valid license is working well.





windows-uwp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I need to confirm something first. You are developing a desktop bridge app, right? What product that you failed to purchase, the app itself, or an add-on product? Have you published your app and created the add-on produce in the partner center before you test your code? When you failed to purchase something, what's the return message you got? Could you please share the return message with me?

0 Votes 0 ·

0 Answers