1
I’m having trouble with the Gateway Picpay to make a integration.
I’m following the manual informed by them on link down below:
https://ecommerce.picpay.com/doc/
Good I’m doing so:
<?php
$urlLoja = "http://www.hotplateprensas.com.br";
$urlPicPay = "https://appws.picpay.com/ecommerce/public/payments";
/*
AQUI VÃO AS VARIÁVEIS $headers, $dados e $buyer mostradas mais abaixo
*/
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $urlPicPay);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode ( $dados ) );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
print_r($result);
curl_close ($ch);
?>
In the part which reads in code here are the variables, I tried three times:
Attempt 1:
$headers = array();
$headers["Content-Type"] = "application/json";
$headers["X-Picpay-Token"] = "d12eac65-ddf3-4e6a-a7de-8a1d04c46a92";
$buyer = array();
$buyer["firstName"] = "Carlos";
$buyer["lastName"] = "Alberto";
$buyer["document"] = "12345678900";
$buyer["email"] = "[email protected]";
$buyer["phone"] = "+55 32 3721-6149";
$dados = array();
$dados["referenceId"] = "1234";
$dados["callbackUrl"] = $urlLoja . "/picpay.php";
$dados["returnUrl"] = $urlLoja . "/picpayReturn.php";
$dados["value"] = "222.22";
$dados["buyer"] = $buyer;
Attempt 2:
$headers = array();
$headers[] = 'Content-Type : application/json';
$headers[] = 'X-Picpay-Token : d12eac65-ddf3-4e6a-a7de-8a1d04c46a92';
$buyer = array();
$buyer[] = "firstName : Carlos";
$buyer[] = "lastName : Alberto";
$buyer[] = "document : 12345678900";
$buyer[] = "email : [email protected]";
$buyer[] = "phone : +55 32 3721-6149";
$dados = array();
$dados[] = "referenceId : " . 1234;
$dados[] = "callbackUrl : " . $site . "/picpay.php";
$dados[] = "returnUrl : " . $site . "/picpayReturn.php";
$dados[] = "value : " . 222.22;
$dados[] = "buyer => " . $buyer;
Attempt 3
$headers = array (
"Content-Type => application/json",
"x-picpay-token => d12eac65-ddf3-4e6a-a7de-8a1d04c46a92"
);
$dados = array (
"referenceId" => 1234,
"callbackUrl" => $site . "/picpay.php",
"returnUrl" => $site . "/picpayReturn.php",
"value" => 222.22,
"buyer" => array (
"firstName" => "Carlos",
"lastName" => "Alberto",
"document" => 12345678900,
"email" => "[email protected]",
"phone" => "+55 32 3721-6149" // +55 27 12345-6789
),
);
All 3 give the same return to:
print_r (result);
{"message":"Error: token x-picpay-token mandatory." ,"code":"401"}
For message of error, says the problem is in token which is invalid. However, it is dashboard of Picpay that I’m taking this token.
They say it’s code error. But I see no error.
If there’s a mistake there, please show me.
Obs.:
As directed by the staff of Picpay, I must follow this pattern who is in the language own of Curl and move on to PHP.
curl -X POST \
https://appws.picpay.com/ecommerce/public/payments \
-H 'Content-Type: application/json' \
-H 'x-picpay-token: 5b008cef7f321d00ef2367b2' \
-d '{
"referenceId": "102030",
"callbackUrl": "http://www.sualoja.com.br/callback",
"returnUrl": "http://www.sualoja.com.br/cliente/pedido/102030",
"value": 20.51,
"buyer": {
"firstName": "João",
"lastName": "Da Silva",
"document": "123.456.789-10",
"email": "[email protected]",
"phone": "+55 27 12345-6789"
}
}'
Did I go PHP 3 times wrong?
Thank you!
Error 401, authentication credentials not valid for the destination resource, already gives a good hint. I haven’t read the documentation, but are you sure the key is this? Isn’t there a test environment key and a production one? Another question, in your key, would not be the case to remove the hyphens? (d12eac65ddf34e6aa7de8a1d04c46a92). Pass (x-picpay-token:) lowercase parameter.
– Fabiano Monteiro
so I’m going to do this test. But no, the token is this. copied from Picpay itself
– Carlos Rocha
Some progress?
– Fabiano Monteiro
Yes, I added as an answer/tutorial
– Carlos Rocha