5

In my WPF application which is packaged via Desktop Bridge I found a problem that some users can't buy addon via in-app purchase. It displays my "Canceled" alert which represents StorePurchaseStatus.NotPurchased where result.ExtendedError is null.

Target framework is:

<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>

Here is the simplified code that procures the purchase:

namespace MyApp {


    public partial class MainWindow: Window {
        private readonly StoreContext context;


         public MainWindow(){
            context = StoreContext.GetDefault();
         }
    

        private bool IsAdministrator()
        {
            var identity = WindowsIdentity.GetCurrent();
            var principal = new WindowsPrincipal(identity);
            return principal.IsInRole(WindowsBuiltInRole.Administrator);
        }

        private async void BuyButtonClick(object sender, RoutedEventArgs e) {

            if (IsAdministrator())
            {
                ShowAlert("Cannot run under administrator rights");
                return;
            }


            if (sender is Button button)
            {
                StoreProduct? storeProduct = ((Product)dataContext).storeProduct;

                if (storeProduct != null)
                {
                     Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(async delegate
                     {
                        var hwnd = new WindowInteropHelper(this).Handle;
                        WinRT.Interop.InitializeWithWindow.Initialize(context, hwnd);
                        var result = await context.RequestPurchaseAsync(storeProduct.StoreId);


                        switch (result.Status)
                        {
                            case StorePurchaseStatus.Succeeded:
                                ShowAlert("Succeeded");
                                break;
                            case StorePurchaseStatus.AlreadyPurchased:
                                ShowAlert("AlreadyPurchased");
                                break;
                            case StorePurchaseStatus.NotPurchased:
                                var extendedError = result.ExtendedError;

                                if (extendedError != null)
                                {
                                    ShowAlert(extendedError.Message);
                                }
                                else
                                {
                                    ShowAlert("Canceled");
                                }
                                break;
                            case StorePurchaseStatus.NetworkError:
                                ShowAlert("NetworkError");
                                break;
                            case StorePurchaseStatus.ServerError:
                                ShowAlert("ServerError");
                                break;
                        }

                     }
                }

            }

        }

    }

It works everywhere on my devices (Windows 11 and Windows 10). The user who cannot buy has Windows 11.

JaSHin
  • 211
  • 2
  • 16
  • 43

1 Answers1

2

This might be caused by the account type that the customer is using.

First of all, the store purchase will fail if the app is running as administrator.

Normal “admin” accounts (people in the administrators group with a split token) will just run your desktop bridge app as a standard user, unless they right-click and launch something elevated explicitly.

But if the customer is using the system built-in account on their device, the purchase will be failed as the app will be running as administrator. This is not allowed for Microsoft Store purchase API.

Roy Li - MSFT
  • 8,043
  • 1
  • 7
  • 13
  • I was added `bool IsAdministrator()` method which show Alert "Cannot run under administrator rights". Will it work for both the mentioned cases (normal admin with right click and system build-in admin) ? – JaSHin Feb 10 '23 at 10:25
  • And we have checked in the task manager, that the user is not running with elevated rights. – JaSHin Feb 10 '23 at 10:28
  • @JaSHin Are you checking the `Elevated` column in the `Details` Tab in Task Manager? The system built-in account will always run things as elevated. – Roy Li - MSFT Feb 13 '23 at 03:03
  • yes. Elevated was "NO". – JaSHin Feb 13 '23 at 07:50
  • Can the user login to Microsoft store app correctly on the same device and purchase other things successfully? – Roy Li - MSFT Feb 13 '23 at 08:03
  • User can successfully "purchase" main application which is free. But addon purchase always fails. – JaSHin Feb 14 '23 at 11:30
  • @JaSHin Please make sure these customers could successfully purchase other things that are not free on that device. Also, switching to another will solve the issue? – Roy Li - MSFT Feb 15 '23 at 02:30
  • No, I can't ask customers to try buy something else in a random app. – JaSHin Feb 24 '23 at 09:35
  • Some user sent me error: App-AuthenticationTokenInvalid KsLbC8LteUegnqsa.2.5.1.2.1.9.1 Sat, 25 Feb 2023 14:01:57 GMT – JaSHin Feb 25 '23 at 17:41
  • @JaSHin It's hard to troubleshoot this if you can't reproduce this on your side. Try to suggest the customer to use another device to check if the issue is related to the specific device. Since the result of the purchase is `cancelled`, the behavior is probably related to the local environment. – Roy Li - MSFT Feb 27 '23 at 07:48
  • Here is the link to the app. Maybe you can figure out what it could be. https://apps.microsoft.com/store/detail/raw-convertor/9NSWB4KMD8JL – JaSHin Feb 28 '23 at 07:32
  • @JaSHin We can't download app from store due to some reason. That's why I'm asking if you could reproduce this on your side. – Roy Li - MSFT Feb 28 '23 at 08:21
  • I have tried. But I cannot reproduce it :( – JaSHin Feb 28 '23 at 08:49
  • @JaSHin Did you find a solution for this? I have the same issue with an app I develop , but I can't find any way out of it. – StrAbZ May 03 '23 at 20:37
  • Unfortunately, no :( – JaSHin May 10 '23 at 10:03