Stack Overflow Asked by OrdiNeu on December 23, 2020
I’m trying to get the purchase/consumption status of a microtransaction that my user has bought via their app. The user authorizes it, and gives my server a token to know that the transaction has been processed, and now I need to double check that it’s actually been made. To do so, I think I’m supposed to use purchases.products.get, whose Rest API recommends I set up OAuth. For server-server communication, the docs recommend I use a Service Account, which recommend I use the Google API to handle JWT signing.
The problem is that I can’t figure out how to set up the purchases.products.get
request from my C# server. According to the docs, I need to create a service object for the API that I want to call (AndroidPublisherService). From browsing the API, it looks like I can create GetRequest which is an object with the right arguments… but how do I actually send it to Google and get a response?
var credential = GoogleCredential.FromFile(CRED_FILENAME);
var service = new AndroidPublisherService(
new Google.Apis.Services.BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "UnityIAPTransactionHandler"
});
// What do I do with this???
new PurchasesResource.ProductsResource.GetRequest(service, PACKAGE_NAME, @"com.appname.coin_12000", @"Test");
Found it: It's not a function on the Service, it's on the newly formed request object. My code now looks like this:
var credential = GoogleCredential.FromFile(CRED_FILENAME);
service = new AndroidPublisherService(
new Google.Apis.Services.BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "UnityIAPTransactionHandler"
});
var request = new PurchasesResource.ProductsResource.GetRequest(service, PACKAGE_NAME, @"com.astatos.coin_12000", @"Test");
var purchase = request.Execute();
And it executes! Although now I have to figure out other errors being thrown, I hope this helps somebody else too.
Answered by OrdiNeu on December 23, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP