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

Trying to use google validator #162

Closed MohammadAlhallaq closed 2 years ago

MohammadAlhallaq commented 2 years ago

Hello...

I was trying to use the google validator for a test case using the data I found in the example file of the package, and I'm getting this error message

(string(71) "openssl_sign(): Supplied key param cannot be coerced into a private key")

can I mock google's response like the iTunesValidator sandbox when using apple?

here is the code I'm using

    $applicationName = 'xxxxxx';
    $scope = ['https://www.googleapis.com/auth/androidpublisher'];
    $configLocation = json_decode(Storage::disk('local')->get('googleapi.json'), true);
    $packageName = 'xxxxx';
    $productId = 'xxxxx';
    $purchaseToken = 'xxxxx';

    $googleClient = new \Google_Client();
    $googleClient->setScopes($scope);
    $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)->validatePurchase();
    } catch (\Exception $e) {
        var_dump($e->getMessage());
        // example message: Error calling GET ....: (404) Product not found for this application.
    }
}

any thoughts about this, and thanks in advance.