TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chris Drosos
NA
39
654
Converting InAppBilling.Plugin to Amazon
Jun 2 2020 8:51 AM
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)
{
//Couldn't connect
return
false
;
}
//check purchases
var verify =
new
InAppBillingVerify();
var purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase, verify);
//check for null just incase
if
(purchases?.Any(p => p.ProductId == productId) ??
false
)
{
//Purchase restored
Preferences.Set(productId,
true
);
return
true
;
}
else
{
//no purchases found
//Toast.MakeText(this, GetString(Resource.String.Options_RestoreUnavailable), ToastLength.Long);
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
;
}
//Decide if it is an error we care about
if
(
string
.IsNullOrWhiteSpace(message))
return
false
;
//Display message to user
//Toast.MakeText(this, message, ToastLength.Long);
}
catch
(Exception exception)
{
Crashes.TrackError(exception);
//Something has gone wrong
RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
//Toast.MakeText(this, GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable), ToastLength.Long);
}
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)
{
//we are offline or can't connect, don't try to purchase
return
false
;
}
//check purchases
var verify =
new
InAppBillingVerify();
var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchase, payload, verify);
//possibility that a null came through.
if
(purchase ==
null
)
{
//did not purchase
}
else
if
(purchase.State == PurchaseState.Purchased)
{
//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
;
}
//Decide if it is an error we care about
if
(
string
.IsNullOrWhiteSpace(message))
return
false
;
//Display message to user
DisplayToast(message, ToastLength.Long);
}
catch
(Exception exception)
{
Crashes.TrackError(exception);
//Something else has gone wrong, log it
//Debug("Issue connecting: " + ex);
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)
{
//Couldn't connect
return
string
.Empty;
}
//check purchases
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
;
}
//Decide if it is an error we care about
if
(
string
.IsNullOrWhiteSpace(message))
return
string
.Empty;
//Display message to user
DisplayToast(message, ToastLength.Long);
}
catch
(Exception exception)
{
Crashes.TrackError(exception);
//Something has gone wrong
}
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?
Reply
Answers (
1
)
are transaction implemented success on this function or not
The remote name could not be resolved: '--cosmos.azure.com'