-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathpayload.php
60 lines (53 loc) · 2.12 KB
/
payload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
use Piggly\Pix\DynamicPayload;
use Piggly\Pix\Exceptions\EmvIdIsRequiredException;
use Piggly\Pix\Exceptions\InvalidEmvFieldException;
use Piggly\Pix\Exceptions\InvalidPixKeyException;
use Piggly\Pix\Exceptions\InvalidPixKeyTypeException;
use Piggly\Pix\StaticPayload;
try
{
// Pix estático
// Obtém os dados pix do usuário
// -> Dados obrigatórios
$keyType = htmlspecialchars( filter_input( INPUT_POST, 'keyType' ) );
$keyValue = htmlspecialchars( filter_input( INPUT_POST, 'keyValue' ) );
$merchantName = htmlspecialchars( filter_input( INPUT_POST, 'merchantName' ) );
$merchantCity = htmlspecialchars( filter_input( INPUT_POST, 'merchantCity' ) );
// -> Dados opcionais
$amount = htmlspecialchars( filter_input( INPUT_POST, 'amount' ) );
$tid = htmlspecialchars( filter_input( INPUT_POST, 'tid' ) );
$description = htmlspecialchars( filter_input( INPUT_POST, 'description' ) );
$payload =
(new StaticPayload())
->setAmount($amount)
->setTid($tid)
->setDescription($description)
->setPixKey($keyType, $keyValue)
->setMerchantName($merchantName)
->setMerchantCity($merchantCity);
// Pix dinâmico
// Obtém os dados pix do usuário
// -> Dados obrigatórios
$merchantName = htmlspecialchars( filter_input( INPUT_POST, 'merchantName' ) );
$merchantCity = htmlspecialchars( filter_input( INPUT_POST, 'merchantCity' ) );
// Obtém os dados do SPI para o Pix
$payload =
(new DynamicPayload())
->setUrl($spiUrl) // URL do Pix no SPI
->setMerchantName($merchantName)
->setMerchantCity($merchantCity);
// Continue o código
// Código pix
echo $pix->getPixCode();
// QR Code
echo '<img style="margin:12px auto" src="'.$pix->getQRCode().'" alt="QR Code de Pagamento" />';
}
catch ( InvalidPixKeyException $e )
{ /** Retorna que a chave pix está inválida. */ }
catch ( InvalidPixKeyTypeException $e )
{ /** Retorna que a chave pix está inválida. */ }
catch ( InvalidEmvFieldException $e )
{ /** Retorna que algum campo está inválido. */ }
catch ( EmvIdIsRequiredException $e )
{ /** Retorna que um campo obrigatório não foi preenchido. */ }