4

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?

2 Answers 2

1

Ok wild guess would be to add fields to the request. Fields lets you decide which fields are populated in the response some of the API methods dont return all the fields by default by saying fields = * you tell the api you want all the data.

var request = service.Purchases.Products.Get(packageName, productId, purchaseToken);
request.Fields = "*";
return request.ExecuteAsync();

If that doesnt work i am trying to track down an issue forum for that api. I will edit this if i find one.

9
  • Unfortunately the package id is still null after adding `service.Fields = "*"`` :(
    – Deusald
    Oct 9, 2020 at 9:04
  • Hang in there pinged a Google devrel we may get a response when they wake up. Oct 9, 2020 at 9:09
  • I found a way of pinging someone internally at google. Oct 12, 2020 at 9:50
  • ok, thank you for the information, hope we will have an answer soon
    – Deusald
    Oct 12, 2020 at 11:42
  • 1
    Seems like ignored productId is the intended behaviour. But I hope that null value in response is not. I've found thread on issueTracker: issuetracker.google.com/issues/169870112
    – Deusald
    Oct 20, 2020 at 17:11
0

It will be empty if you have only one item in your database. Weird, but it is as it is. Add second item, of the same category, and you'll start getting proper values in response.

1
  • I've added 2 new in-apps in google play console. Now I have 3 different In-Ap. I can purchase each one of them and still I'm getting ProductId as null and the productId argument is ignored.
    – Deusald
    Oct 7, 2020 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.