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