我需要一些关于Xamarin.Forms的InAppBillingPlugin的支持 . 首先,我根据documnetation进行了配置:https://jamesmontemagno.github.io/InAppBillingPlugin/
应用程序,Google控制台(被管理产品)和iTunes Connect网站 .
这是我的应用程序代码 .
private async Task TryInAppPurchace(string androidProductId, string iOSProductId="")
{
if (!CrossInAppBilling.IsSupported)
return;
//Android
var products = new string[] { androidProductId };
if(Device.RuntimePlatform == Device.iOS)
products = new string[] { iOSProductId };
var billing = CrossInAppBilling.Current;
//billing.InTestingMode = true;
try
{
var connected = await billing.ConnectAsync(ItemType.InAppPurchase);
if (!connected)
{
await Application.Current.MainPage.DisplayAlert("Connectivity Error", "Unable to connect to the internet.", "OK");
return;
}
var items = await billing.GetProductInfoAsync(ItemType.InAppPurchase, products);
var item = items.ToList().First();
//try to purchase item
var purchase = await billing.PurchaseAsync(item.ProductId, ItemType.InAppPurchase, item.ProductId);
//possibility that a null came through.
if (purchase == null)
{
await Application.Current.MainPage.DisplayAlert("Purchase Error", "You are unable to buy this product.", "OK");
return;
}
else
{
await _pageService.DisplayAlert("Purchased", "Consumable product.", "OK");
if (Device.RuntimePlatform == Device.iOS)
return;
var consumedItem = await CrossInAppBilling.Current.ConsumePurchaseAsync(purchase.ProductId, purchase.PurchaseToken);
if (consumedItem != null)
{
await Application.Current.MainPage.DisplayAlert("New Package added", "Successfully added new package", "OK");
}
}
}
catch (InAppBillingPurchaseException purchaseEx)
{
var message = string.Empty;
await Application.Current.MainPage.DisplayAlert("Exeption", purchaseEx.Message, "OK");
switch (purchaseEx.PurchaseError)
{
case PurchaseError.BillingUnavailable:
message = "BillingUnavailable";
break;
case PurchaseError.DeveloperError:
message = "DeveloperError";
break;
case PurchaseError.ItemUnavailable:
message = "ItemUnavailable";
break;
case PurchaseError.GeneralError:
message = "GeneralError";
break;
case PurchaseError.UserCancelled:
message = "UserCancelled.";
break;
case PurchaseError.AppStoreUnavailable:
message = "AppStoreUnavailable.";
break;
case PurchaseError.PaymentNotAllowed:
message = "PaymentNotAllowed.";
break;
case PurchaseError.PaymentInvalid:
message = "PaymentInvalid";
break;
case PurchaseError.InvalidProduct:
message = "InvalidProduct";
break;
case PurchaseError.ProductRequestFailed:
message = "ProductRequestFailed";
break;
case PurchaseError.RestoreFailed:
message = "RestoreFailed";
break;
case PurchaseError.ServiceUnavailable:
message = "ServiceUnavailable";
break;
}
}
catch (Exception ex)
{
//Something else has gone wrong, log it
await Application.Current.MainPage.DisplayAlert("Exeption", ex.Message, "OK");
}
finally
{
await billing.DisconnectAsync();
}
}
我的问题是我无法再次购买相同的产品而且我从Google Play获得了以下内容:
{Plugin.InAppBilling.Abstractions.InAppBillingPurchaseException:无法处理购买 . 在Plugin.InAppBilling.InAppBillingImplementation d__33.MoveNext()[0x00116]在C:\ projects \ inappbillingplugin \ src \ Plugin.InAppBilling.Android \ InAppBillingImplementation.cs:324 ---从先前位置抛出异常的堆栈跟踪结束 - - 在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000c] in:0中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x0003e] in:0在System.Runtime .CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x00028] in:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task task)[0x00008] in:0 at System .Runtime.CompilerServices.TaskAwaiter
1 [TResult] .GetResult()[0x00000] in:0 in Plugin.InAppBilling.InAppBillingImplementation d__32.MoveNext()[0x00090] in C:\ projects \ inappbillingplugin \ src \ Plugin.InAppBilling.Android \ InAppBillingImplementation.cs:264 ---来自prev的堆栈跟踪结束在抛出异常的位置---在System.Runtime.ExilerServices.ExceptionDispatchInfo.Throw()[0x0000c] in:0 in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task task)[0x0003e] in:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task)[0x00028] in:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task task)[ 0x00008] in:0中的System.Runtime.CompilerServices.TaskAwaiter
1 [TResult] .GetResult()[0x00000] in:0中的DrivingCourse_app.ViewModels.AccessPageViewModel d__18.MoveNext()[0x0025c] in C:\ Projects \ GIT- REPO \ DrivingCourse_DE \ DrivingCourse_app \ DrivingCourse_app \ DrivingCourse_app \ ViewModels \ AccessPageViewModel.cs:136}
我的代码有问题吗?此代码适用于每次购买产品,因此配置本身和一般过程都有效 .
有任何想法吗?