Picpay integration: Problem

Asked

Viewed 559 times

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.

  • so I’m going to do this test. But no, the token is this. copied from Picpay itself

  • Some progress?

  • Yes, I added as an answer/tutorial

1 answer

1


Solved:

The only drawback here is that Picpay on the payments screen asks to scan a Code .

And this might not be so easy on Desktops. What will make life very difficult for us!

We’ll most likely leave Picpay for that reason.

But follow the code that worked:

<?php

$urlSite     = "http://www.urlsite.com.br";

$urlPicPay = "https://appws.picpay.com/ecommerce/public/payments";

$XPicpayToken = "X-Picpay-Token: SEU TOKEN";

$headers  = array ( 
      "Content-Type:application/json",
      $XPicpayToken
);

$buyer = array (
                "firstName" =>   "Nome",
                "lastName"  =>   "Sobrenome",
                "document"  =>   "12345678900",
                "email"     =>   "[email protected]",
                "phone"     =>   "+55 33 3333 3333" //  +55 27 12345-6789
           );

$dados = array ( 
           "referenceId"    =>   1245,
           "callbackUrl"    =>   $urlSite . "/picpay.php",
           "returnUrl"      =>   $urlSite . "/picpayReturn.php",
           "value"          =>   222.22,
           "buyer"          =>   $buyer
);

$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_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
$erro  = curl_error($ch);

$resultPHP = json_decode($result, true);


if ( isset ( $resultPHP["paymentUrl"] ) ){

    header ("Location: " . $resultPHP["paymentUrl"]);

} else {

    print_r( $erro );

}

curl_close ($ch);

?>
  • ok. So even in their example the token does not contain hyphen'x-picpay-token: 5b008cef7f321d00ef2367b2', does not mean anything. Where was the problem exactly, managed to discover?

  • 1

    in the generation of my arrays.

  • Roger, now! Good.

  • thanks. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.