Reputation: 16045
I'd like to validate my in-app purchases.
I'm using this receipt validator which by looking at the source code is calling https://www.googleapis.com/androidpublisher/v3/applications/<appId>/purchases/products/<productId>/tokens/<token>
, here's my code basically copied from the readme
$googleClient = new Google_Client();
$googleClient->setScopes([Google_Service_AndroidPublisher::ANDROIDPUBLISHER]);
$googleClient->setApplicationName('my project name');
$googleClient->setAuthConfig('files/googleauthconfig.json');
$validator = new Validator(new Google_Service_AndroidPublisher($googleClient));
try {
$response = $validator->setPackageName('my.app.id')
->setProductId('my.product.id')
->setPurchaseToken('token i got from my app when purchasing')
->validatePurchase();
} catch (Exception $e) {
var_dump($e->getMessage());
exit;
}
var_dump($response);
exit;
I've hardcoded a lot of stuff because I'm just trying to get it to work at this point. googleauthconfig.json
is the JSON file dev console gave me for my service account which contains a bunch of IDs for the account as well as a private key. I went in my play console and made my service account an administrator and then waited about 24 hours as suggested in other questions for the same problem. I've configured my products, which are consumable and active and I successfully purchase them through my signed release app with the test credit card.
The error I keep getting is
The current user has insufficient permissions to perform the requested operation.
Upvotes: 2
Views: 1084
Reputation: 116978
The current user has insufficient permissions to perform the requested operation.
Means exactly that the user you are authenticating with does not have the permissions to do what you are trying to do. You are using a service account. A service account is not you. Service accounts are preauthorized.
Go over to google pay probably the admin section take the Service account email address and grant it permissions to access the data. You probably do this like you would any other user.
As mentioned in the comment it can take time normally under an hour for a service account to kick in. After you grant it access.
I think you should try the pure code rather that using your validator to ensure that its not thats the problem.
$client = new Google_Client();
$client->setScopes([Google_Service_AndroidPublisher::ANDROIDPUBLISHER]);
$client->setApplicationName('my project name');
$client->setAuthConfig('files/googleauthconfig.json');
$service = new Google_Service_AndroidPublisher($client);
try {
$response = $service->purchases_products->get(package_name, product_id, purchase_token);
} catch (Exception $e) {
var_dump($e->getMessage());
exit;
}
var_dump($response);
exit;
Upvotes: 2
Reputation: 16045
Well, oddly enough, as suggested in other answers as well, I just needed to wait in my case about 30 hours before the permission changes took effect.
Upvotes: 0