@@ -14,138 +14,138 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Pix { |
16 | 16 | |
17 | - /** |
|
18 | - * IDs do Payload do Pix |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const ID_PAYLOAD_FORMAT_INDICATOR = '00'; |
|
22 | - const ID_MERCHANT_ACCOUNT_INFORMATION = '26'; |
|
23 | - |
|
24 | - const ID_MERCHANT_ACCOUNT_INFORMATION_GUI = '00'; |
|
25 | - const ID_MERCHANT_ACCOUNT_INFORMATION_CHAVE = '01'; |
|
26 | - const ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION = '02'; |
|
27 | - |
|
28 | - const ID_MERCHANT_CATEGORY_CODE = '52'; |
|
29 | - const ID_TRANSACTION_CURRENCY = '53'; |
|
30 | - const ID_TRANSACTION_AMOUNT = '54'; |
|
31 | - const ID_COUNTRY_CODE = '58'; |
|
32 | - const ID_MERCHANT_NAME = '59'; |
|
33 | - const ID_MERCHANT_CITY = '60'; |
|
34 | - |
|
35 | - const ID_ADDITIONAL_DATA_FIELD_TEMPLATE = '62'; |
|
36 | - const ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID = '05'; |
|
37 | - |
|
38 | - const ID_CRC16 = '63'; |
|
39 | - |
|
40 | - /** |
|
41 | - * Chave Pix |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - private $pixKey; |
|
45 | - |
|
46 | - /** |
|
47 | - * Descrição do pagamento |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - private $description; |
|
51 | - |
|
52 | - /** |
|
53 | - * Nome do titular da conta |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - private $merchantName; |
|
57 | - |
|
58 | - /** |
|
59 | - * Cidade do titular da conta |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - private $merchantCity; |
|
63 | - |
|
64 | - /** |
|
65 | - * ID de transação Pix |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - private $txid; |
|
69 | - |
|
70 | - /** |
|
71 | - * Valor da transação |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - private $amount; |
|
75 | - |
|
76 | - /** |
|
77 | - * Método responsável por definir o valor de $pixKey |
|
78 | - * @param string $pixKey |
|
79 | - */ |
|
80 | - public function setPixKey($pixKey) { |
|
17 | + /** |
|
18 | + * IDs do Payload do Pix |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const ID_PAYLOAD_FORMAT_INDICATOR = '00'; |
|
22 | + const ID_MERCHANT_ACCOUNT_INFORMATION = '26'; |
|
23 | + |
|
24 | + const ID_MERCHANT_ACCOUNT_INFORMATION_GUI = '00'; |
|
25 | + const ID_MERCHANT_ACCOUNT_INFORMATION_CHAVE = '01'; |
|
26 | + const ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION = '02'; |
|
27 | + |
|
28 | + const ID_MERCHANT_CATEGORY_CODE = '52'; |
|
29 | + const ID_TRANSACTION_CURRENCY = '53'; |
|
30 | + const ID_TRANSACTION_AMOUNT = '54'; |
|
31 | + const ID_COUNTRY_CODE = '58'; |
|
32 | + const ID_MERCHANT_NAME = '59'; |
|
33 | + const ID_MERCHANT_CITY = '60'; |
|
34 | + |
|
35 | + const ID_ADDITIONAL_DATA_FIELD_TEMPLATE = '62'; |
|
36 | + const ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID = '05'; |
|
37 | + |
|
38 | + const ID_CRC16 = '63'; |
|
39 | + |
|
40 | + /** |
|
41 | + * Chave Pix |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + private $pixKey; |
|
45 | + |
|
46 | + /** |
|
47 | + * Descrição do pagamento |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + private $description; |
|
51 | + |
|
52 | + /** |
|
53 | + * Nome do titular da conta |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + private $merchantName; |
|
57 | + |
|
58 | + /** |
|
59 | + * Cidade do titular da conta |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + private $merchantCity; |
|
63 | + |
|
64 | + /** |
|
65 | + * ID de transação Pix |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + private $txid; |
|
69 | + |
|
70 | + /** |
|
71 | + * Valor da transação |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + private $amount; |
|
75 | + |
|
76 | + /** |
|
77 | + * Método responsável por definir o valor de $pixKey |
|
78 | + * @param string $pixKey |
|
79 | + */ |
|
80 | + public function setPixKey($pixKey) { |
|
81 | 81 | $this->pixKey = $pixKey; |
82 | 82 | return $this; |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Método responsável por definir o valor de $description |
|
87 | - * @param string $description |
|
88 | - */ |
|
89 | - public function setDescription($description) { |
|
85 | + /** |
|
86 | + * Método responsável por definir o valor de $description |
|
87 | + * @param string $description |
|
88 | + */ |
|
89 | + public function setDescription($description) { |
|
90 | 90 | $this->description = $description; |
91 | 91 | return $this; |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Método responsável por definir o valor de $merchantName |
|
96 | - * @param string $merchantName |
|
97 | - */ |
|
98 | - public function setMerchantName($merchantName) { |
|
94 | + /** |
|
95 | + * Método responsável por definir o valor de $merchantName |
|
96 | + * @param string $merchantName |
|
97 | + */ |
|
98 | + public function setMerchantName($merchantName) { |
|
99 | 99 | $this->merchantName = $merchantName; |
100 | 100 | return $this; |
101 | - } |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Método responsável por definir o valor de $merchantCity |
|
105 | - * @param string $merchantCity |
|
106 | - */ |
|
107 | - public function setMerchantCity($merchantCity) { |
|
103 | + /** |
|
104 | + * Método responsável por definir o valor de $merchantCity |
|
105 | + * @param string $merchantCity |
|
106 | + */ |
|
107 | + public function setMerchantCity($merchantCity) { |
|
108 | 108 | $this->merchantCity = $merchantCity; |
109 | 109 | return $this; |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Método responsável por definir o valor de $txid |
|
114 | - * @param string $txid |
|
115 | - */ |
|
116 | - public function setTxid($txid) { |
|
112 | + /** |
|
113 | + * Método responsável por definir o valor de $txid |
|
114 | + * @param string $txid |
|
115 | + */ |
|
116 | + public function setTxid($txid) { |
|
117 | 117 | $this->txid = $txid; |
118 | 118 | return $this; |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | 122 | * @param $amount |
123 | 123 | * @return $this |
124 | 124 | */ |
125 | - public function setAmount($amount) { |
|
126 | - $amount = str_replace('.', '', $amount); |
|
127 | - $amount = str_replace(',', '.', $amount); |
|
128 | - $this->amount = number_format($amount, 2, ',', '.'); |
|
125 | + public function setAmount($amount) { |
|
126 | + $amount = str_replace('.', '', $amount); |
|
127 | + $amount = str_replace(',', '.', $amount); |
|
128 | + $this->amount = number_format($amount, 2, ',', '.'); |
|
129 | 129 | return $this; |
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Método responsável por retornar o valor completo de um objeto pauload |
|
134 | - * @param string $id |
|
135 | - * @param string $value |
|
136 | - * @return string $id.$size.$value |
|
137 | - */ |
|
138 | - private function getValue($id, $value) { |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Método responsável por retornar o valor completo de um objeto pauload |
|
134 | + * @param string $id |
|
135 | + * @param string $value |
|
136 | + * @return string $id.$size.$value |
|
137 | + */ |
|
138 | + private function getValue($id, $value) { |
|
139 | 139 | $size = str_pad(strlen($value), 2, '0', STR_PAD_LEFT); |
140 | 140 | |
141 | 141 | return $id.$size.$value; |
142 | - } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Método responsável por retornar valores completos da informação da conta |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - private function getMerchantAccountInformation() { |
|
144 | + /** |
|
145 | + * Método responsável por retornar valores completos da informação da conta |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + private function getMerchantAccountInformation() { |
|
149 | 149 | // Domínio do Banco Central |
150 | 150 | $gui = $this->getValue(self::ID_MERCHANT_ACCOUNT_INFORMATION_GUI, 'br.gov.bcb.pix'); |
151 | 151 | |
@@ -160,25 +160,25 @@ discard block |
||
160 | 160 | |
161 | 161 | // Retorna o valor completo da conta |
162 | 162 | return $this->getValue(self::ID_MERCHANT_ACCOUNT_INFORMATION, $gui.$key.$description); |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Método responsável por retornar os valores completos do campo adicional do pix ($txid) |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - private function getAdditionalDataFieldTemplate() { |
|
165 | + /** |
|
166 | + * Método responsável por retornar os valores completos do campo adicional do pix ($txid) |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + private function getAdditionalDataFieldTemplate() { |
|
170 | 170 | // txid |
171 | 171 | $txid = $this->getValue(self::ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID, $this->txid); |
172 | 172 | |
173 | 173 | // Retorna o valor completo |
174 | 174 | return $this->getValue(self::ID_ADDITIONAL_DATA_FIELD_TEMPLATE, $txid); |
175 | - } |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * Método responsável por calcular o valor da hash de validação do código pix |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - private function getCRC16($payload) { |
|
177 | + /** |
|
178 | + * Método responsável por calcular o valor da hash de validação do código pix |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + private function getCRC16($payload) { |
|
182 | 182 | // Adiciona dados gerais do payload |
183 | 183 | $payload .= self::ID_CRC16.'04'; |
184 | 184 | |
@@ -199,26 +199,26 @@ discard block |
||
199 | 199 | |
200 | 200 | // Retorna o código CRC16 de 4 caractéres |
201 | 201 | return self::ID_CRC16.'04'.strtoupper(dechex($resultado)); |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Método responsável por gerar o código completo do payload Pix |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public function getPayload() { |
|
204 | + /** |
|
205 | + * Método responsável por gerar o código completo do payload Pix |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public function getPayload() { |
|
209 | 209 | // Cria o $payload |
210 | 210 | $payload = |
211 | - $this->getValue(self::ID_PAYLOAD_FORMAT_INDICATOR, '01') . |
|
212 | - $this->getMerchantAccountInformation() . |
|
213 | - $this->getValue(self::ID_MERCHANT_CATEGORY_CODE, '0000') . |
|
214 | - $this->getValue(self::ID_TRANSACTION_CURRENCY, '986') . |
|
215 | - $this->getValue(self::ID_TRANSACTION_AMOUNT, $this->amount) . |
|
216 | - $this->getValue(self::ID_COUNTRY_CODE, 'BR') . |
|
217 | - $this->getValue(self::ID_MERCHANT_NAME, $this->merchantName) . |
|
218 | - $this->getValue(self::ID_MERCHANT_CITY, $this->merchantCity) . |
|
219 | - $this->getAdditionalDataFieldTemplate(); |
|
211 | + $this->getValue(self::ID_PAYLOAD_FORMAT_INDICATOR, '01') . |
|
212 | + $this->getMerchantAccountInformation() . |
|
213 | + $this->getValue(self::ID_MERCHANT_CATEGORY_CODE, '0000') . |
|
214 | + $this->getValue(self::ID_TRANSACTION_CURRENCY, '986') . |
|
215 | + $this->getValue(self::ID_TRANSACTION_AMOUNT, $this->amount) . |
|
216 | + $this->getValue(self::ID_COUNTRY_CODE, 'BR') . |
|
217 | + $this->getValue(self::ID_MERCHANT_NAME, $this->merchantName) . |
|
218 | + $this->getValue(self::ID_MERCHANT_CITY, $this->merchantCity) . |
|
219 | + $this->getAdditionalDataFieldTemplate(); |
|
220 | 220 | |
221 | 221 | // Retorna o payload + CRC16 |
222 | 222 | return $payload.$this->getCRC16($payload); |
223 | - } |
|
223 | + } |
|
224 | 224 | } |
225 | 225 | \ No newline at end of file |