Hello Guys,
I have create a Android application in Xamarin and i would like to also have in on Amazon store.
It uses in App purchases
Currently im implementing those purchases with this code:
- public async Task<bool> WasItemPurchased(string productId)
- {
- var billing = CrossInAppBilling.Current;
- var result = false;
- try
- {
- var connected = await billing.ConnectAsync(ItemType.InAppPurchase);
- if (!connected)
- {
-
- return false;
- }
-
- var verify = new InAppBillingVerify();
- var purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase, verify);
-
- if (purchases?.Any(p => p.ProductId == productId) ?? false)
- {
-
- Preferences.Set(productId, true);
- return true;
- }
- else
- {
-
-
- return false;
- }
- }
- catch (InAppBillingPurchaseException purchaseEx)
- {
- var message = string.Empty;
- switch (purchaseEx.PurchaseError)
- {
- case PurchaseError.AppStoreUnavailable:
- RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
- break;
- case PurchaseError.BillingUnavailable:
- RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorBillingUnavailable);
- break;
- case PurchaseError.PaymentInvalid:
- RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentInvalid);
- break;
- case PurchaseError.PaymentNotAllowed:
- RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentNotAllowed);
- break;
- case PurchaseError.AlreadyOwned:
- RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAlreadyOwned);
- Preferences.Set(productId, true);
- result = true;
- break;
- }
-
- if (string.IsNullOrWhiteSpace(message))
- return false;
-
-
- }
- catch (Exception exception)
- {
- Crashes.TrackError(exception);
-
- RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
-
- }
- finally
- {
- await billing.DisconnectAsync();
- }
- return result;
- }
- public async Task<bool> PurchaseItem(string productId, string payload)
- {
- var billing = CrossInAppBilling.Current;
- try
- {
- var connected = await billing.ConnectAsync(ItemType.InAppPurchase);
- if (!connected)
- {
-
- return false;
- }
-
- var verify = new InAppBillingVerify();
- var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchase, payload, verify);
-
- if (purchase == null)
- {
-
- }
- else if (purchase.State == PurchaseState.Purchased)
- {
-
- Preferences.Set(productId, true);
- }
- }
- catch (InAppBillingPurchaseException purchaseEx)
- {
- var message = string.Empty;
- switch (purchaseEx.PurchaseError)
- {
- case PurchaseError.AppStoreUnavailable:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
- break;
- case PurchaseError.BillingUnavailable:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorBillingUnavailable);
- break;
- case PurchaseError.PaymentInvalid:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentInvalid);
- break;
- case PurchaseError.PaymentNotAllowed:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentNotAllowed);
- break;
- case PurchaseError.AlreadyOwned:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorAlreadyOwned);
- Preferences.Set(productId, true);
- EnableOrDisableProFeatures();
- break;
- }
-
- if (string.IsNullOrWhiteSpace(message))
- return false;
-
- DisplayToast(message, ToastLength.Long);
- }
- catch (Exception exception)
- {
- Crashes.TrackError(exception);
-
-
- DisplayToast(GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable), ToastLength.Long);
- }
- finally
- {
- await billing.DisconnectAsync();
- }
- return false;
- }
- private async Task RestorePurchases()
- {
- var currentConnectivity = Connectivity.NetworkAccess;
- var restorePurchasesResults = new List<bool>();
- if (currentConnectivity == NetworkAccess.Internet)
- {
- restorePurchasesResults.Add(await WasItemPurchased(GetString(Resource.String.Options_PaidFunctions_PurchaseTemplatesAndMoreButtons)));
- restorePurchasesResults.Add(await WasItemPurchased(GetString(Resource.String.Options_PaidFunctions_PurchaseCustomResources)));
- restorePurchasesResults.Add(await WasItemPurchased(GetString(Resource.String.Options_PaidFunctions_PurchaseDisplayWebpageAfterVote)));
- if (restorePurchasesResults.Contains(true))
- {
- DisplayToast(GetString(Resource.String.Options_PaidFunctions_PurchasesRestored), ToastLength.Long);
- EnableOrDisableProFeatures();
- }
- else
- {
- if (string.IsNullOrEmpty(RestorePurchasesStatusMessage))
- RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_PurchasesNotFound);
- DisplayToast(RestorePurchasesStatusMessage, ToastLength.Long);
- }
- }
- else
- {
- DisplayToast(GetString(Resource.String.Options_InternetUnavailable), ToastLength.Long);
- }
- }
- private async Task<string> GetProductPrice(string productId)
- {
- var billing = CrossInAppBilling.Current;
- try
- {
- var connected = await billing.ConnectAsync(ItemType.InAppPurchase);
- if (!connected)
- {
-
- return string.Empty;
- }
-
- var item = await billing.GetProductInfoAsync(ItemType.InAppPurchase, productId);
- if (item != null)
- return item.ToList()[0].LocalizedPrice;
- }
- catch (InAppBillingPurchaseException purchaseEx)
- {
- var message = string.Empty;
- switch (purchaseEx.PurchaseError)
- {
- case PurchaseError.AppStoreUnavailable:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
- break;
- case PurchaseError.BillingUnavailable:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorBillingUnavailable);
- break;
- case PurchaseError.PaymentInvalid:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentInvalid);
- break;
- case PurchaseError.PaymentNotAllowed:
- message = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentNotAllowed);
- break;
- }
-
- if (string.IsNullOrWhiteSpace(message))
- return string.Empty;
-
- DisplayToast(message, ToastLength.Long);
- }
- catch (Exception exception)
- {
- Crashes.TrackError(exception);
-
- }
- finally
- {
- await billing.DisconnectAsync();
- }
- return string.Empty;
- }
And i have to do similar function for the Amazon store like the API details here:
https://developer.amazon.com/docs/cross-platform-plugins/cpp-use-the-iap-plugin-for-xamarin.html
However i dont even know where to start to convert those functions, Amazon API confuse me, can someone help me?