Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issues Surrounding tcsPurchase #232

Merged
merged 3 commits into from
Aug 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ async Task<Purchase> PurchaseAsync(string productSku, string itemType, string pa
public override Task<bool> ConnectAsync(ItemType itemType = ItemType.InAppPurchase)
{
serviceConnection = new InAppBillingServiceConnection(Context, itemType);
tcsPurchase?.TrySetCanceled();
tcsPurchase = null;
return serviceConnection.ConnectAsync();
}

Expand Down Expand Up @@ -522,38 +524,38 @@ public static void HandleActivityResult(int requestCode, Result resultCode, Inte

switch (responseCode)
{
case 0:
//Reponse returned OK
var purchaseData = data.GetStringExtra(RESPONSE_IAP_DATA);
var dataSignature = data.GetStringExtra(RESPONSE_IAP_DATA_SIGNATURE);

tcsPurchase?.TrySetResult(new PurchaseResponse
{
PurchaseData = purchaseData,
DataSignature = dataSignature
});
break;
case RESPONSE_CODE_RESULT_USER_CANCELED:
tcsPurchase.SetException(new InAppBillingPurchaseException(PurchaseError.UserCancelled));
break;
case RESPONSE_CODE_RESULT_SERVICE_UNAVAILABLE:
tcsPurchase.SetException(new InAppBillingPurchaseException(PurchaseError.ServiceUnavailable));
break;
case BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE:
tcsPurchase.SetException(new InAppBillingPurchaseException(PurchaseError.ItemUnavailable));
break;
case BILLING_RESPONSE_RESULT_DEVELOPER_ERROR:
tcsPurchase.SetException(new InAppBillingPurchaseException(PurchaseError.DeveloperError));
break;
case BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED:
tcsPurchase.SetException(new InAppBillingPurchaseException(PurchaseError.AlreadyOwned));
break;
case BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED:
tcsPurchase.SetException(new InAppBillingPurchaseException(PurchaseError.NotOwned));
break;
default:
tcsPurchase.SetException(new InAppBillingPurchaseException(PurchaseError.GeneralError, responseCode.ToString()));
break;
case 0:
//Reponse returned OK
var purchaseData = data.GetStringExtra(RESPONSE_IAP_DATA);
var dataSignature = data.GetStringExtra(RESPONSE_IAP_DATA_SIGNATURE);

tcsPurchase?.TrySetResult(new PurchaseResponse
{
PurchaseData = purchaseData, DataSignature = dataSignature
});
break;
case RESPONSE_CODE_RESULT_USER_CANCELED:
tcsPurchase?.TrySetException(new InAppBillingPurchaseException(PurchaseError.UserCancelled));
break;
case RESPONSE_CODE_RESULT_SERVICE_UNAVAILABLE:
tcsPurchase?.TrySetException(new InAppBillingPurchaseException(PurchaseError.ServiceUnavailable));
break;
case BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE:
tcsPurchase?.TrySetException(new InAppBillingPurchaseException(PurchaseError.ItemUnavailable));
break;
case BILLING_RESPONSE_RESULT_DEVELOPER_ERROR:
tcsPurchase?.TrySetException(new InAppBillingPurchaseException(PurchaseError.DeveloperError));
break;
case BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED:
tcsPurchase?.TrySetException(new InAppBillingPurchaseException(PurchaseError.AlreadyOwned));
break;
case BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED:
tcsPurchase?.TrySetException(new InAppBillingPurchaseException(PurchaseError.NotOwned));
break;
default:
tcsPurchase?.TrySetException(
new InAppBillingPurchaseException(PurchaseError.GeneralError, responseCode.ToString()));
break;
}
}

Expand Down