Olá @igormacedo 🙋🏻♂️
Certo. Então vamos lá! Estou utilizando:
WordPress na versão 5.6.1
WooCommerce na versão 4.9.2
QR Code PicPay para WooCommerce na versão 1.2.0
1º teste) Com o “authorizationId” sendo nulo:
curl -k -i \
--request POST \
--url https://test/woocommerce/wc-api/WC_PicPay_Gateway/ \
--header 'x-seller-token: 10874731-facd-4193-9800-9eb715e22c0e' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"referenceId": "WC-294",
"authorizationId": null
}'
Resultado: HTTP Status 200
Print do teste: https://i.imgur.com/HnScQyC.png
Registros de depuração:
...
02-07-2021 @ 23:34:39 - Checking CALLBACK request...
02-07-2021 @ 23:34:39 - CALLBACK request is OK.
02-07-2021 @ 23:34:39 - Get payment status for order WC-294
...
2º teste) Com um “referenceId” que não existe na loja:
curl -k -i \
--request POST \
--url https://test/woocommerce/wc-api/WC_PicPay_Gateway/ \
--header 'x-seller-token: 10874731-facd-4193-9800-9eb715e22c0e' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"referenceId": "WC-XXXX",
"authorizationId": "5b01780ba8914c001a007673"
}'
Resultado: HTTP Status 200
Print do teste: https://i.imgur.com/YfR2tYr.png
Registros de depuração:
...
02-07-2021 @ 23:35:42 - Checking CALLBACK request...
02-07-2021 @ 23:35:42 - CALLBACK request is OK.
02-07-2021 @ 23:35:42 - Get payment status for order WC-XXXX
02-07-2021 @ 23:35:43 - PicPay payment status response: Array
(
[message] => Pedido referenceId='WC-XXXX' não encontrado
[code] => 422
)
...
3º teste) Com "x-seller-token" diferente do que está nas configurações:
curl -k -i \
--request POST \
--url https://test/woocommerce/wc-api/WC_PicPay_Gateway/ \
--header 'x-seller-token: 1a9c0314-97a1-4f95-89a9-7b46ae447621' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"referenceId": "WC-294",
"authorizationId": "5b01780ba8914c001a007673"
}'
Resultado: HTTP Status 200
Print do teste: https://i.imgur.com/0OY40rb.png
Registros de depuração:
...
02-07-2021 @ 23:36:53 - Checking CALLBACK request...
02-07-2021 @ 23:36:53 - Invalid CALLBACK request, invalid Seller Token.
...
4º teste) Com todos os campos preenchidos, inclusive o "authorizationId":
curl -k -i \
--request POST \
--url https://test/woocommerce/wc-api/WC_PicPay_Gateway/ \
--header 'x-seller-token: 10874731-facd-4193-9800-9eb715e22c0e' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"referenceId": "WC-294",
"authorizationId": "5b01780ba8914c001a007673"
}'
Resultado: HTTP Status 200
Print do teste: https://i.imgur.com/R43Rkdl.png
Registros de depuração:
...
02-07-2021 @ 23:38:25 - Checking CALLBACK request...
02-07-2021 @ 23:38:25 - CALLBACK request is OK.
02-07-2021 @ 23:38:25 - Get payment status for order WC-294
...
Baseados nos resultados que obtive nos testes que foram realizados acima, não consegui encontrar o erro 400 que foi citado.
A questão toda está em torno deste problema:
2021 @ 23:22:54 - Invalid CALLBACK request, invalid Seller Token.
onde o registro de depuração é gerado nesta linha:
https://github.com/dadeke/woo-picpay/blob/7e9c64a8c5fca377fdcd41c9867777ae9fca4e02/includes/class-wc-picpay-api.php#L257
Então meu palpite é descobrir o Seller Token que a PicPay está enviando.
Para fazer isto, basta alterar temporariamente este trecho de:
if($this->gateway->debug == 'yes') {
$this->gateway->log->add($this->gateway->id, 'Invalid CALLBACK request, invalid Seller Token.');
}
para:
if($this->gateway->debug == 'yes') {
$this->gateway->log->add($this->gateway->id, 'Invalid CALLBACK request, invalid Seller Token.');
// Start temporary test
$this->gateway->log->add($this->gateway->id, 'Seller Token received: ' . $_SERVER['HTTP_X_SELLER_TOKEN']);
$payment = file_get_contents("php://input");
$payment = json_decode($payment, true);
$this->gateway->log->add($this->gateway->id, 'Request body: ' . print_r($payment, true));
// Finish temporary test
}
Depois faça uma compra real na sua loja e veja o Seller Token que irá aparecer no Status do Sistema > Registros.
Assim será possível comparar com os próprios olhos o valor do Seller Token que está sendo enviado com o valor do Seller Token que está salvo nas configurações. 👀
Caso o Seller Token enviado esteja diferente, verifique se "referenceId" (Prefixo + ID do Pedido) no "Request body" que possivelmente foi enviado existe na sua loja. Caso exista, copie o verdadeiro Seller Token e salve-o nas configurações do WooCommerce.
Caso o "referenceId" (Prefixo + ID do Pedido) não exista na loja, aí sim será um tremendo mistério! 🤔
Tome cuidado! Qualquer pessoa que obter posse do seu Seller Token pode hackear a confirmação dos pagamentos da sua loja.
O Seller Token que utilizei nos testes é fictício. 👍
Tudo bem?