I'm making request to google Android Publisher api to check if the provided purchaseToken of an in-app purchase is correct. First problem is that the product id is ignored and I can type anything as the parameter. Only package name and purchaseToken needs to be correct. Secondly why productId and purchaseToken in ProductPurchase are null. I would like to check if provided purchaseToken matches productId. When productId can be anything and it's not returned in response how can I check if this is valid for particular in-app purchase productId?
private static Task<ProductPurchase> GetInAppPurchase(string packageName, string productId, string purchaseToken)
{
GoogleCredential credential;
using (Stream stream = new FileStream(@"api.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = GoogleCredential.FromStream(stream);
}
string[] scopes = {
AndroidPublisherService.Scope.Androidpublisher
};
credential = credential.CreateScoped(scopes);
BaseClientService.Initializer initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My Application"
};
AndroidPublisherService service = new AndroidPublisherService(initializer);
return service.Purchases.Products.Get(packageName, productId, purchaseToken).ExecuteAsync();
}
private static void TestGooglePlayPurchaseApi()
{
string packageName = "validPackageName";
string productId = "validOrInvalidProductName";
string purchaseToken = "validPurchaseToken";
ProductPurchase purchase = GetInAppPurchase(packageName, productId, purchaseToken).Result;
Console.WriteLine("Kind: " + purchase.Kind);
Console.WriteLine("Quantity: " + purchase.Quantity);
Console.WriteLine("AcknowledgementState: " + purchase.AcknowledgementState!);
Console.WriteLine("ConsumptionState: " + purchase.ConsumptionState!);
Console.WriteLine("DeveloperPayload: " + purchase.DeveloperPayload);
Console.WriteLine("ETag: " + purchase.ETag);
Console.WriteLine("OrderId: " + purchase.OrderId);
Console.WriteLine("ProductId: " + purchase.ProductId);
Console.WriteLine("PurchaseState: " + purchase.PurchaseState!);
Console.WriteLine("PurchaseToken: " + purchase.PurchaseToken);
Console.WriteLine("PurchaseType: " + purchase.PurchaseType!);
Console.WriteLine("RegionCode: " + purchase.RegionCode);
Console.WriteLine("PurchaseTimeMillis: " + purchase.PurchaseTimeMillis);
Console.WriteLine("ObfuscatedExternalAccountId: " + purchase.ObfuscatedExternalAccountId);
Console.WriteLine("ObfuscatedExternalProfileId: " + purchase.ObfuscatedExternalProfileId);
}
And this is what I'm reciving:
Kind: androidpublisher#productPurchase
Quantity:
AcknowledgementState: 1
ConsumptionState: 1
DeveloperPayload: {"developerPayload":"","is_free_trial":false,"has_introductory_price_trial":false,"is_updated":false,"accountId":""}
ETag:
OrderId: YYY.XXXX-XXXX-XXXX-XXXXX
ProductId:
PurchaseState: 0
PurchaseToken:
PurchaseType: 0
RegionCode: PL
PurchaseTimeMillis: 1601915754698
ObfuscatedExternalAccountId:
ObfuscatedExternalProfileId:
Why ProductId is empty?