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