Closed sjoukedv closed 2 years ago
Hi. Could you share the code of AppStoreProcessor->validateReceipt method?
Yes:
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
use ReceiptValidator\iTunes\Validator as iTunesValidator;
......
class AppStoreProcessor {
........
function validateReceipt($receipt, $production = false) {
// echo "validating on " . ($production ? "production" : "sandbox") . PHP_EOL;
// echo $receipt;
$validator = new iTunesValidator($production ? iTunesValidator::ENDPOINT_PRODUCTION : iTunesValidator::ENDPOINT_SANDBOX); // Or iTunesValidator::ENDPOINT_SANDBOX if sandbox testing
$receiptBase64Data = $receipt;
try {
$response = $validator->setReceiptData($receiptBase64Data)->validate();
$sharedSecret = '.......';
$response = $validator->setSharedSecret($sharedSecret)->setReceiptData($receiptBase64Data)->validate();
} catch (Exception $e) {
echo 'got error = ' . $e->getMessage() . PHP_EOL;
return false;
}
if ($response->isValid()) {
// $this->write_receipt_log($response);
return $response;
} else {
if($production == false) {
return $this->validateReceipt($receipt, true);
}
// echo "Nothing to be done";
return false;
}
}
}
Note, that this takes place inside a Wordpress environment.
I appreciate your help!
Could you also share a version of guzzle in composer.lock?
composer.json
{
"require": {
"aporat/store-receipt-validator": "^3.4.1",
"psr/log": "1.1.4",
"psr/cache": "1.0.1"
},
"scripts": {
"post-install-cmd": [
"Google_Task_Composer::cleanup"
],
"post-update-cmd": [
"Google_Task_Composer::cleanup"
]
},
"extra": {
"google/apiclient-services": [
"AndroidPublisher"
]
}
}
composer.lock
Also tried on staging using only composer require aporat/store-receipt-validator
As I can see the version of guzzle is 6.5.5.
Could you debug a little and show what is the class name of $client
using get_class()?
In iTunes/Validator.php
private function sendRequestUsingClient(HttpClient $client)
{
....
var_dump('DEBUG_CLASS ' . get_class($client));
$baseUri = (string) $client->getConfig('base_uri');
....
}
returns
"DEBUG_CLASS GuzzleHttp\Client"
In addition;
var_dump('DEBUG_METHOD ' . method_exists($client, 'getConfig'));
is
string(13) "DEBUG_METHOD "
And
var_dump(get_class_methods($client));
returns
[0]=>
string(11) "__construct"
[1]=>
string(16) "getDefaultOption"
[2]=>
string(16) "setDefaultOption"
[3]=>
string(10) "getBaseUrl"
[4]=>
string(13) "createRequest"
[5]=>
string(3) "get"
[6]=>
string(4) "head"
[7]=>
string(6) "delete"
[8]=>
string(3) "put"
[9]=>
string(5) "patch"
[10]=>
string(4) "post"
[11]=>
string(7) "options"
[12]=>
string(4) "send"
[13]=>
string(7) "sendAll"
[14]=>
string(17) "getDefaultHandler"
[15]=>
string(19) "getDefaultUserAgent"
[16]=>
string(10) "getEmitter"
}
Looks like you've installed Guzzle 5.x https://github.com/guzzle/guzzle/blob/5.3/src/Client.php
This package requires 6 or 7.
The expected list of methods should be
It works fine when called directly from a file, but I am using the package within Wordpress' mu-plugins
directory (also in own namespace). A lot of other plugins (basically which one doesn't) use GuzzleHttp
and I bet they are on different versions, leading to a conflict.
Could it be that it is referring to another GuzzleHttp
package elsewhere?
Edit: composer.lock
contains several GuzzleHttp
versions for google/auth
and google/apiclient
, but pretty certain it's one of the plugins causing an issue. Is GuzzleHttp
properly scoped @Stafox ?
Thank you once again for the help!
Take a look into vendor/autoload.php
here you can find the path to Guzzle client.
Maybe there was some revert on your side and you got
"name": "guzzlehttp/guzzle",
"version": "6.5.5",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "9d4290de1cfd701f38099ef7e183b64b4b7b0c5e"
},
in composer lock, but in vendor dir the version of guzzle is 5.x
As you can see google/auth can work with guzzle 5.x, 6.x and 7.x.
{
"name": "google/auth",
"version": "v1.18.0",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-auth-library-php.git",
"reference": "21dd478e77b0634ed9e3a68613f74ed250ca9347"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/21dd478e77b0634ed9e3a68613f74ed250ca9347",
"reference": "21dd478e77b0634ed9e3a68613f74ed250ca9347",
"shasum": ""
},
"require": {
"firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0",
"guzzlehttp/guzzle": "^5.3.1|^6.2.1|^7.0",
I have found the issue; the (official) Cloudflare plugin was not scoped properly and using and older version of GuzzleHttp
resulting in a conflict. That is the reason for the conflict.
Thanks @Stafox!
Tried different PHP (
7.4
,8.0
,8.1
) and package (3.4.1
,3.5
,4.1
latest) versions$client instanceof ClientInterface
seems to befalse
.Isn't this the proper way to instantiate a client
$client = new GuzzleHttp\Client();
?