aporat / store-receipt-validator

PHP receipt validator for Apple iTunes, Google Play and Amazon App Store
Apache License 2.0
633 stars 153 forks source link

Not working for google play when validate a receipt #81

Closed hiren004 closed 5 years ago

hiren004 commented 5 years ago

I'm using this package for google play and iTunes. iTunes seems working great for me, but when i was trying to implement it for google play it's giving me some error. I don't know how to use this for google play OR how to fix it!

Please help me with this one. I'm using this code by the way:

$client = new \Google_Client();
$client->setApplicationName('APP_NAME');
$client->setAuthConfig(public_path('credentials.json'));
$client->setScopes('https://www.googleapis.com/auth/androidpublisher'); 
$validator = new PlayValidator(new \Google_Service_AndroidPublisher($client));

try {
      $response = $validator->setPackageName('PACKAGE_NAME')
                            ->setProductId($request->product_id)
                            ->setPurchaseToken($request->purchase_token)
                            ->validatePurchase();
       var_dump($response);
 } catch (Exception $e){
         return response()->json([
                 'errorCode'  => '1',
                 'errorMsg'   => 'Receipt is not valid',
                 'data'       => []
         ]);
}

Any help will be really appreciated!! Thanks!

raminshahab commented 5 years ago

What is your response outputting? Check to see that you are able to communicate with the Google API server. Also, as mentioned in the README there is some footwork that needs to be done with your google play store and using a service account prior to using the code ( if that's the route you took to authenticate).

hiren004 commented 5 years ago

@rms5981 I've fixed it now and it's working for me now. Thank you!

raminshahab commented 5 years ago

@hiren004 Awesome!