'Verifying in-app purchase from Google Play
I'm working on an Azure Functions app that will make calls to Google to verify in-app purchases users make in my mobile app.
I'm using the Google.Apis.AndroidPublisher.v3 NuGet package with the following code to verify an in-app purchase.
public async Task<bool> IsValidPurchase(string bundleId, string receiptId, string purchaseToken, string developerPayload)
{
try
{
var isValidPurchase = true;
var request = _googleService.Purchases.Products.Get(bundleId, receiptId, purchaseToken);
var purchaseState = await request.ExecuteAsync();
if (purchaseState.DeveloperPayload != developerPayload)
isValidPurchase = false;
if (purchaseState.PurchaseState != 0)
isValidPurchase = false;
return isValidPurchase;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
I keep getting "Bad Request - Invalid Value" error.
My mobile users will be purchasing auto-renewing subscriptions and after a successful purchase on an Android phone, I get the following response -- see image below:
The verification method asks for bundleId, receiptId, purchaseToken and developerPayload.
The bundleId and purchaseToken are pretty clear so I'm thinking the error I get is either due to receiptId or developerPayload.
I tried using both Id and ProductId values from the response -- see image above -- but I keep getting the same error:
Bad request - Invalid Value
Any idea what's wrong here? Am I using the wrong values? I'd appreciate some pointers here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

