英文:
StorePurchaseStatus.NotPurchased immediately after RequestPurchaseAsync()
问题
以下是您要翻译的代码部分:
在我的使用桌面桥打包的 WPF 应用程序中,我发现一些用户无法通过应用内购买购买附加组件的问题。它显示我的 "已取消" 提示,表示 `StorePurchaseStatus.NotPurchased`,其中 `result.ExtendedError` 为 `null`。
目标框架是:
以下是简化的采购代码:
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("无法以管理员权限运行");
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("购买成功");
break;
case StorePurchaseStatus.AlreadyPurchased:
ShowAlert("已购买");
break;
case StorePurchaseStatus.NotPurchased:
var extendedError = result.ExtendedError;
if (extendedError != null)
{
ShowAlert(extendedError.Message);
}
else
{
ShowAlert("已取消");
}
break;
case StorePurchaseStatus.NetworkError:
ShowAlert("网络错误");
break;
case StorePurchaseStatus.ServerError:
ShowAlert("服务器错误");
break;
}
});
}
}
}
}
}
这段代码在我的设备上(Windows 11 和 Windows 10)的所有地方都正常工作。无法购买的用户使用的是 Windows 11。
英文:
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.
答案1
得分: 2
这可能是由客户所使用的帐户类型引起的。
首先,如果应用程序以管理员身份运行,商店购买将失败。
普通的“管理员”帐户(即管理员组中的用户,具有分离的令牌)将仅将您的桌面桥梁应用程序作为标准用户运行,除非他们明确右键单击并以提升方式启动某些内容。
但如果客户正在使用其设备上的系统内置帐户,则购买将失败,因为应用程序将以管理员身份运行。这是不允许的,适用于 Microsoft Store 购买 API。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论