Skip to content

Commit 1e8e2a6

Browse files
committed
- Pix
- melhorias na resposta
1 parent 751e20f commit 1e8e2a6

File tree

9 files changed

+296
-41
lines changed

9 files changed

+296
-41
lines changed

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Gateway de Pagamento - SDK PHP
22

33
Modalidades de pagamentos:
4+
- PIX
45
- Cartão de crédito
56
- Cartão de débito
67
- Paypal Plus
78
- Paypal Express Chekout
89
- Pagseguro V4.0
9-
- Boleto bancário (Bradesco Shop Fácil e Itaú Shopline)
10+
- Boleto bancário (Bradesco Shop Fácil, Itaú Shopline e AZPAY)
1011
- Transferência eletronica bancária (Itaú Shopline)
1112

1213
Recursos disponíveis
1314
- Parcelamento de pagamentos
1415
- Pagamentos agendados ( recorrências )
1516
- Análise de antifraude
1617
- Tokenização de cartões
18+
- Split de pagamentos (AZPAY)
1719

1820
---
1921

@@ -23,8 +25,6 @@ Recursos disponíveis
2325

2426
include_once "autoload.php";
2527

26-
use Exception as Exception;
27-
2828
try {
2929
$credential = new Credential("{{INSERT_MERCHANT_ID}}", "{{INSERT_TOKEN}}", Environment::SANDBOX);
3030
$gateway = new Gateway($credential);
@@ -216,21 +216,42 @@ $response = $gateway->sale("{TransactionID}");
216216
```
217217

218218
### Tranferência Bancária (Transfer)
219+
219220
```php
220221
$response = $gateway->OnlineTransfer($transaction);
221222
```
222223

223224
### Boleto Bancário (Payment Bank Slip)
225+
224226
```php
225227
$response = $gateway->Boleto($transaction);
226228
```
227229

230+
### PIX
231+
232+
```php
233+
$transaction->Payment()
234+
->setAcquirer(Acquirers::AZPAY)
235+
->setCurrency(Currency::BRAZIL_BRAZILIAN_REAL_BRL)
236+
->setCountry("BRA")
237+
->setExpire("2021-09-17T23:00:00")
238+
->setFine(1.12)
239+
->setInterest(1.12)
240+
->setInstructions("PIX: Anuidade do serviço")
241+
->Split($split); //opcional
242+
243+
$response = $gateway->Pix($transaction);
244+
245+
```
246+
228247
### Paypal
248+
229249
```php
230250
$response = $gateway->Paypal($transaction);
231251
```
232252

233253
### Pagamento agendado ( Recorrência)
254+
234255
```php
235256
$response = $gateway->Rebill($transaction);
236257
```
@@ -302,9 +323,4 @@ $response = $gateway->Rebill($transaction);
302323
|Cartão de Débito|[source / example](examples/Debit.php)|
303324
|Paypal|[source / example](examples/Paypal.php)|
304325
|Recorrência|[source / example](examples/Rebill.php)|
305-
|Transfência eletrônica|[source / example](examples/OnlineTransfer.php)|
306-
307-
308-
309-
310-
326+
|Transfência eletrônica|[source / example](examples/OnlineTransfer.php)|

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"require": {
2222
"php": ">=7.0",
23-
"ext-json": "*"
23+
"ext-json": "*",
24+
"ext-curl": "*"
2425
}
25-
}
26-
26+
}

examples/Boleto.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,4 @@
8282

8383
} catch (Exception $e) {
8484
print_r($e->getMessage());
85-
}
86-
85+
}

examples/Credit.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
try {
17-
$credential = new Credential("1", "d41d8cd98f00b204e9800998ecf8427e",
17+
$credential = new Credential("{{mechantID}}", "{{mechantKEY}}",
1818
Environment::SANDBOX);
1919
$gateway = new Gateway($credential);
2020

@@ -33,10 +33,10 @@
3333
->setCurrency(Currency::BRAZIL_BRAZILIAN_REAL_BRL)
3434
->setCountry("BRA")
3535
->setNumberOfPayments(2)
36-
->setSoftDescriptor("Bruno paz")
36+
->setSoftDescriptor("NOMEDAEMPRESA")
3737
->Card()
3838
->setBrand(Brand::VISA)
39-
->setCardHolder("Bruno paz")
39+
->setCardHolder("Fulano de tal")
4040
->setCardNumber("2223000148400010")
4141
->setCardSecurityCode("123")
4242
->setCardExpirationDate("202001");
@@ -45,7 +45,7 @@
4545
$transaction->Customer()
4646
->setCustomerIdentity("999999999")
4747
->setName("Bruno")
48-
->setCpf("306.282.848-02")
48+
->setCpf("106.182.848-01")
4949
->setCnpj("18303116000165")
5050
->setEmail("[email protected]");
5151

@@ -108,5 +108,4 @@
108108

109109
} catch (Exception $e) {
110110
print_r($e->getMessage());
111-
}
112-
111+
}

examples/Pix.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Gateway\API;
4+
5+
include_once "autoload.php";
6+
7+
use Exception as Exception;
8+
9+
try {
10+
$credential = new Credential("{{mechantID}}", "{{mechantKEY}}",
11+
Environment::SANDBOX);
12+
$gateway = new Gateway($credential);
13+
$split = [
14+
[
15+
"recipient" => "d71c944b96a43b39c2b38fd6353b6a2",
16+
"liable" => "true",
17+
"charge_processing_fee" => "true",
18+
"percentage" => 10,
19+
"amount" => 10,
20+
],
21+
22+
];
23+
### CREATE A NEW TRANSACTION
24+
$transaction = new Transaction();
25+
26+
// Set ORDER
27+
$transaction->Order()
28+
->setReference("ss")
29+
->setTotalAmount(1000);
30+
31+
// Set PAYMENT
32+
$transaction->Payment()
33+
->setAcquirer(Acquirers::AZPAY)
34+
->setCurrency(Currency::BRAZIL_BRAZILIAN_REAL_BRL)
35+
->setCountry("BRA")
36+
->setExpire("2021-09-17T23:00:00")
37+
->setFine(0)
38+
->setInterest(1.12)
39+
->setInstructions("PIX: Anuidade do serviço")
40+
->Split($split);
41+
42+
// SET CUSTOMER
43+
$transaction->Customer()
44+
->setCustomerIdentity("999999999")
45+
->setName("Bruno")
46+
->setAddress("Rua teste de varginha")
47+
->setAddress2("Apartamento 23")
48+
->setPostalCode("08742350")
49+
->setCity("São Paulo")
50+
->setState("SP")
51+
->setCountry("BRASIL")
52+
->setCpf("94127918012")
53+
->setEmail("[email protected]");
54+
55+
// Set URL RETURN
56+
$transaction->setUrlReturn("http://127.0.0.1:8989/return.php");
57+
58+
// PROCESS - ACTION
59+
$response = $gateway->Pix($transaction);
60+
61+
// REDIRECT IF NECESSARY (Debit uses)
62+
if ($response->isRedirect()) {
63+
print $response->getRedirectUrl();
64+
//$response->redirect();
65+
}
66+
67+
// RESULTED
68+
if ($response->isAuthorized()) { // Action Authorized
69+
print "<br>RESULTED: ".$response->getStatus();
70+
} else { // Action Unauthorized
71+
print "<br>RESULTED:".$response->getStatus();
72+
}
73+
74+
// REPORT
75+
$response = $gateway->Report($response->getTransactionID());
76+
print "<br>REPORTING: ".$response->getStatus();
77+
print "<br>INFO: <HR>";
78+
var_dump($response->getPixInfo()); // array
79+
80+
} catch (Exception $e) {
81+
print_r($e->getMessage());
82+
}

src/gateway/API/Gateway.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Gateway\API;
1010

11+
use Exception;
12+
1113
/**
1214
* Class Gateway
1315
*
@@ -50,7 +52,7 @@ public function __construct(Credential $credential)
5052
* @param Transaction $transaction
5153
*
5254
* @return $this
53-
* @throws \Exception
55+
* @throws Exception
5456
*/
5557
public function Authorize(Transaction $transaction)
5658
{
@@ -76,7 +78,7 @@ public function Authorize(Transaction $transaction)
7678
* @param Transaction $transaction
7779
*
7880
* @return $this
79-
* @throws \Exception
81+
* @throws Exception
8082
*/
8183
public function Sale(Transaction $transaction)
8284
{
@@ -102,7 +104,7 @@ public function Sale(Transaction $transaction)
102104
* @param Transaction $transaction
103105
*
104106
* @return $this
105-
* @throws \Exception
107+
* @throws Exception
106108
*/
107109
public function Rebill(Transaction $transaction)
108110
{
@@ -119,7 +121,7 @@ public function Rebill(Transaction $transaction)
119121
* @param int null $amount
120122
*
121123
* @return $this
122-
* @throws \Exception
124+
* @throws Exception
123125
*/
124126
public function Capture(string $transactionId, int $amount = null)
125127
{
@@ -136,7 +138,7 @@ public function Capture(string $transactionId, int $amount = null)
136138
* @param int null $amount
137139
*
138140
* @return $this
139-
* @throws \Exception
141+
* @throws Exception
140142
*/
141143
public function Cancel(string $transactionId, int $amount = null)
142144
{
@@ -153,7 +155,7 @@ public function Cancel(string $transactionId, int $amount = null)
153155
* @param string $transactionId
154156
*
155157
* @return $this
156-
* @throws \Exception
158+
* @throws Exception
157159
*/
158160
public function Report(string $transactionId)
159161
{
@@ -168,23 +170,33 @@ public function Report(string $transactionId)
168170
* @param Transaction $transaction
169171
*
170172
* @return $this
171-
* @throws \Exception
173+
* @throws Exception
172174
*/
173175
public function Boleto(Transaction $transaction)
174176
{
175-
$sale = new Boleto($transaction, $this->credential);
176-
$request = new Request($this->credential);
177+
$sale = new Boleto($transaction, $this->credential);
178+
$request = new Request($this->credential);
177179

178180
$this->response = $request->post("/v1/receiver", $sale->toJSON());
179181

180182
return $this;
181183
}
182184

185+
public function Pix(Transaction $transaction)
186+
{
187+
$sale = new Pix($transaction, $this->credential);
188+
$request = new Request($this->credential);
189+
$this->response = $request->post("/v1/receiver", $sale->toJSON());
190+
191+
return $this;
192+
}
193+
194+
183195
/**
184196
* @param Transaction $transaction
185197
*
186198
* @return $this
187-
* @throws \Exception
199+
* @throws Exception
188200
*/
189201
public function OnlineTransfer(Transaction $transaction)
190202
{
@@ -305,6 +317,8 @@ public function isRedirect()
305317
return true;
306318
} elseif (isset($this->response["processor"]["urlReturn"])) {
307319
return true;
320+
} elseif (isset($this->response["processor"]["urlPix"])) {
321+
return true;
308322
} else {
309323
return false;
310324
}
@@ -339,6 +353,10 @@ public function getRedirectUrl()
339353
return $this->response["processor"]["Transfer"]["urlTransfer"];
340354
}
341355

356+
if (isset($this->response["processor"]["urlPix"])) {
357+
return $this->response["processor"]["urlPix"];
358+
}
359+
342360
if (isset($this->response["processor"]["urlReturn"])) {
343361
return $this->response["processor"]["urlReturn"];
344362
}
@@ -352,7 +370,6 @@ public function getRedirectUrl()
352370
public function getBoletoUrl()
353371
{
354372

355-
356373
if (isset($this->response["processor"]["Boleto"]["details"]["urlBoleto"])) {
357374
return $this->response["processor"]["Boleto"]["details"]["urlBoleto"];
358375
}
@@ -364,6 +381,18 @@ public function getBoletoUrl()
364381
return "";
365382
}
366383

384+
/**
385+
* @return array|mixed
386+
*/
387+
public function getPixInfo()
388+
{
389+
if (isset($this->response["processor"]["urlPix"])) {
390+
return $this->response["processor"];
391+
}
392+
393+
return [];
394+
}
395+
367396
/**
368397
* @return bool
369398
*/

0 commit comments

Comments
 (0)