├── README.md
├── notification.php
├── payment.php
└── src
└── paymentPicPay.php
/README.md:
--------------------------------------------------------------------------------
1 | # PicPay PHP Simple
2 |
3 | [](https://github.com/luannsr12/picpay-php/)
4 | [](https://github.com/luannsr12/picpay-php/issues)
5 | [](https://github.com/luannsr12/picpay-php)
6 | [](https://github.com/luannsr12/picpay-php)
7 |
8 |
9 | ### Efetuando Pagamento (payment.php)
10 | #### Adicione seu `x-picpay-token` e `x-seller-token` | Clique [aqui](https://lojista.picpay.com/dashboard/ecommerce-token) para pegar as credenciais
11 |
12 | ```php
13 | requestPayment($produto,$cliente);
34 |
35 | if(isset($payment->message)):
36 | echo $payment->message;
37 | else:
38 | $link = $payment->paymentUrl;
39 | $qrCode = $payment->qrcode->base64;
40 |
41 | echo 'Pagar com PicPay';
42 | echo '
';
43 | echo '
';
44 |
45 | endif;
46 | ?>
47 | ```
48 |
49 | ### Recebendo Notificação do PicPay (notification.php)
50 | ```php
51 | notificationPayment();
57 |
58 | if($notification){
59 |
60 | $status = $notification->status;
61 | $authorizationId = $notification->authorizationId;
62 | $referenceId = $notification->referenceId;
63 |
64 |
65 | /* -- Tratar dados -- */
66 | }
67 | ?>
68 | ```
69 | #### A função notificationPayment retorna com os seguintes dados:
70 | - referenceId (Referencia do pedido no seu sistema)
71 | - status (Confira as respostas de status na documentação do picpay)
72 | - authorizationId (Usado para estornar o pedido)
73 |
74 |
75 |
76 |
77 | Documentação PicPay API: https://ecommerce.picpay.com/doc/
78 |
--------------------------------------------------------------------------------
/notification.php:
--------------------------------------------------------------------------------
1 | notificationPayment();
24 |
25 | if($notification){
26 |
27 | $status = $notification->status;
28 | $authorizationId = $notification->authorizationId;
29 | $referenceId = $notification->referenceId;
30 |
31 |
32 | /* -- Tratar dados -- */
33 | }
34 |
35 | ?>
36 |
--------------------------------------------------------------------------------
/payment.php:
--------------------------------------------------------------------------------
1 | requestPayment($produto,$cliente);
34 |
35 | if(isset($payment->message)):
36 |
37 | echo $payment->message;
38 |
39 | else:
40 |
41 | $link = $payment->paymentUrl;
42 | $qrCode = $payment->qrcode->base64;
43 |
44 | echo 'Pagar com PicPay';
45 | echo '
';
46 | echo '
';
47 |
48 | endif;
49 | ?>
50 |
--------------------------------------------------------------------------------
/src/paymentPicPay.php:
--------------------------------------------------------------------------------
1 | x_picpay_token = $x_picpay_token;
13 | $this->x_seller_token = $x_seller_token;
14 | }
15 |
16 | /*
17 | *@var type String: $urlCallBack
18 | */
19 | private $urlCallBack = "https://seusite.com/notification.php";
20 |
21 | /*
22 | *@var type String: $urlReturn
23 | */
24 | private $urlReturn = "https://seusite.com/user";
25 |
26 |
27 | //Função que faz a requisição
28 | public function requestPayment($produto,$cliente){
29 |
30 | $data = array(
31 | 'referenceId' => $produto->ref,
32 | 'callbackUrl' => $this->urlCallBack,
33 | 'returnUrl' => $this->urlReturn,
34 | 'value' => $produto->valor,
35 | 'buyer' => [
36 | 'firstName' => $cliente->nome,
37 | 'lastName' => $cliente->sobreNome,
38 | 'document' => $cliente->cpf,
39 | 'email' => $cliente->email,
40 | 'phone' => $cliente->telefone
41 | ],
42 | );
43 |
44 | $ch = curl_init('https://appws.picpay.com/ecommerce/public/payments');
45 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
46 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
47 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-picpay-token: '.$this->x_picpay_token));
48 |
49 | $res = curl_exec($ch);
50 | curl_close($ch);
51 | $return = json_decode($res);
52 |
53 | return $return;
54 |
55 | }
56 |
57 |
58 |
59 | // Notificação PicPay
60 | public function notificationPayment(){
61 |
62 | $content = trim(file_get_contents("php://input"));
63 | $payBody = json_decode($content);
64 |
65 | if(isset($payBody->authorizationId)):
66 |
67 | $referenceId = $payBody->referenceId;
68 |
69 | $ch = curl_init('https://appws.picpay.com/ecommerce/public/payments/'.$referenceId.'/status');
70 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
71 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-picpay-token: '.$this->x_picpay_token));
72 |
73 | $res = curl_exec($ch);
74 | curl_close($ch);
75 | $notification = json_decode($res);
76 |
77 | $notification->referenceId = $payBody->referenceId;
78 | $notification->authorizationId = $payBody->authorizationId;
79 |
80 | return $notification;
81 |
82 | else:
83 |
84 | return false;
85 |
86 | endif;
87 |
88 |
89 | }
90 |
91 |
92 |
93 |
94 | }
95 |
96 |
97 |
98 |
99 |
100 | ?>
101 |
--------------------------------------------------------------------------------