I am trying to verify google in app subscription on my server end.
It seems to me that I need to create a service account for that.
I already had a "OldProject" Linked to my google play account, so Now, i created a service account under the project "OldProject" with "owner role" on the entire project.
But for some reason, when I use this service account and attempt to verify a purchaseToken, i get the error "The current user has insufficient permissions to perform the requested operation".
I'm using the PHP validator from here https://github.com/aporat/store-receipt-validator
but i keep getting this error
got error = { "error": { "errors": [
{ "domain": "androidpublisher",
"reason": "permissionDenied",
"message": "The current user has insufficient permissions to perform the requested operation." } ],
"code": 401, "message": "The current user has insufficient permissions to perform the requested operation." } }
and Yes in API access i have granted this user permission as "Administrator" on all apps
and this is the PHP code
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
$root = realpath(dirname(dirname(__FILE__)));
$library = "$root/library";
$path = array($library, get_include_path());
set_include_path(implode(PATH_SEPARATOR, $path));
require_once $root . '/vendor/autoload.php';
use ReceiptValidator\GooglePlay\Validator as PlayValidator;
// google authencation
$applicationName = 'xxx-xxx';
$scope = ['https://www.googleapis.com/auth/androidpublisher'];
$configLocation = 'googleapi.json';
// receipt data
$packageName = 'com.xxxx.xxxx';
$productId = 'xxx';
$purchaseToken = 'xxxx';
$googleClient = new \Google_Client();
$googleClient->setScopes([\Google_Service_AndroidPublisher::ANDROIDPUBLISHER]);
$googleClient->setApplicationName($applicationName);
$googleClient->setAuthConfig($configLocation);
$googleAndroidPublisher = new \Google_Service_AndroidPublisher($googleClient);
$validator = new \ReceiptValidator\GooglePlay\Validator($googleAndroidPublisher);
try {
$response = $validator->setPackageName($packageName)
->setProductId($productId)
->setPurchaseToken($purchaseToken)
->validateSubscription();
} catch (\Exception $e){
var_dump($e->getMessage());
// example message: Error calling GET ....: (404) Product not found for this application.
}
// success