StorePurchaseStatus.NotPurchased immediately after RequestPurchaseAsync()

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:

var 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.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation