Skip to content

Commit

Permalink
Merge pull request #232 from masterwok/fix-tcsPurchase
Browse files Browse the repository at this point in the history
Fix Issues Surrounding tcsPurchase
  • Loading branch information
jamesmontemagno authored Aug 17, 2019
2 parents 6d8d340 + 40051a3 commit db29a3b
Showing 1 changed file with 34 additions and 32 deletions.
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

0 comments on commit db29a3b

Please sign in to comment.