Closed kshitijsharma97 closed 4 years ago
I don't know the case and why you need to use OAuth, but suggest try it using service account (because it is only the way when you able to process the data in background).
I am also facing error in case of Play store using service account.
{ "error": { "code": 400, "message": "The purchase token is associated with a non-subscription purchase. Only subscription purchases are supported for this call.", "errors": [ { "message": "The purchase token is associated with a non-subscription purchase. Only subscription purchases are supported for this call.", "domain": "androidpublisher", "reason": "nonSubscriptionToken", "location": "token", "locationType": "parameter" } ] } }
Here is the code that I added in my controller:
$googleClient = new \Google_Client();
$googleClient->setScopes([\Google_Service_AndroidPublisher::ANDROIDPUBLISHER]);
$googleClient->setApplicationName('BulletForce');
$pathToServiceAccountJsonFile = json_decode(Storage::disk('local')->get('keys/bullet-force-288519-1e5e67d29fcf.json'), true);
$googleClient->setAuthConfig($pathToServiceAccountJsonFile);
$googleAndroidPublisher = new \Google_Service_AndroidPublisher($googleClient);
$validator = new \ReceiptValidator\GooglePlay\Validator($googleAndroidPublisher);
$validator = new PlayValidator(new \Google_Service_AndroidPublisher($googleClient));
try {
$response = $validator->setPackageName('com.blayzegames.iosfps')
->setProductId('com.blayzegames.iosfps.goldtierone')
->setPurchaseToken('afoejlfbjlgagoojbkgljmdk.AO-J1OzsDO_Nj2jVa1IWr_YWTWoEaQzJNi58RF6J9Tdz-ALHJ6f3XkJHwq2afTcBlbYs_2pnFPWDvm9XhtCnrDslNccMLRxzTG3B2Z9hnE0IKqkDg5SM8RLolz0YXDQGfnDPe-L5vIiEuZa-9ZcxMdb3nUrhri3nyg')
->validateSubscription();
} catch (\Exception $e){
var_dump($e->getMessage());
}
Please help me.
@Gameonn just read the error message. It clearly says that your token belong to in-app purchase not subscription.
So, you should validate it as purchase using validatePurchase()
instead of validateSubscription()
Thanks @Stafox. I already fixed this one.
When I tried to validate the purchase token for my application. I'm getting this response:
Here is code for which I'm getting this response
Also When I tried
I got invalid grant type error.
Please help me.