|
| 1 | +#### Descrição |
| 2 | +Adicionar uma nova funcionalidade ao projeto para implementar as rotinas de geração de token e criptograma de cartão, com foco no suporte completo ao protocolo de tokenização de bandeira Visa. Essa funcionalidade é essencial para aumentar a segurança nas transações de e-commerce, substituindo o número do cartão por um token exclusivo de bandeira combinado com um criptograma. |
| 3 | + |
| 4 | +Importante: Identificamos que os testes para a tokenização da bandeira Visa ainda não estão presentes no projeto. A Visa tem incentivado a adoção dos tokens por estabelecimentos e passou a aplicar uma multa sobre o valor das transações realizadas sem token. Assim, a implementação dessa funcionalidade é prioritária para garantir conformidade com os padrões da bandeira e evitar custos adicionais para os clientes. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +### **1. Geração do Token do Cartão** |
| 9 | +#### Descrição |
| 10 | +A rotina deve enviar os dados do cartão e do comprador para o endpoint `/v1/tokenization/token`, que retornará um token exclusivo associado ao cartão. |
| 11 | + |
| 12 | +#### Detalhes do Endpoint |
| 13 | +**URL:** `/v1/tokenization/token` |
| 14 | +**Método:** `POST` |
| 15 | + |
| 16 | +**Request Body:** |
| 17 | +```json |
| 18 | +{ |
| 19 | + "customer_id": "customer_45678900, 123.456.789-00 ou 12345678900", |
| 20 | + "card_pan": "4622943120000493", |
| 21 | + "card_pan_source": "ON_FILE, MANUALLY_ENTERED ou VIA_APPLICATION", |
| 22 | + "card_brand": "VISA, MASTERCARD", |
| 23 | + "expiration_year": "2023", |
| 24 | + "expiration_month": "07", |
| 25 | + "security_code": 1234, |
| 26 | + "email": "tokenizacao_bandeira@getnet.com.br" |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +### **2. Geração do Criptograma do Cartão** |
| 33 | +#### Descrição |
| 34 | +A rotina deve enviar o token gerado previamente (`network_token_id`) e os dados adicionais da transação para o endpoint responsável por gerar o criptograma. |
| 35 | + |
| 36 | +#### Detalhes do Endpoint |
| 37 | +**URL:** `/v1/cryptogram/generate` |
| 38 | +**Método:** `POST` |
| 39 | + |
| 40 | +**Request Body:** |
| 41 | +```json |
| 42 | +{ |
| 43 | + "network_token_id": "1b110aaa71934ae492bff48baab9af81", |
| 44 | + "transaction_type": "CIT ou MIT", |
| 45 | + "cryptogram_type": "VISA_TAVV ou MC_DSRP_LONG", |
| 46 | + "amount": 1000, |
| 47 | + "customer_id": "customer_45678900", |
| 48 | + "email": "tokenizacao_bandeira@getnet.com.br", |
| 49 | + "card_brand": "VISA ou MASTERCARD" |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +#### Exemplo de transação |
| 54 | +```php |
| 55 | +<?php |
| 56 | + |
| 57 | +use Getnet\API\Getnet; |
| 58 | +use Getnet\API\Tokenization; |
| 59 | +use Getnet\API\Transaction; |
| 60 | +use Getnet\API\Environment; |
| 61 | +use Getnet\API\Token; |
| 62 | +use Getnet\API\BrandToken; |
| 63 | +use Getnet\API\BrandCryptToken; |
| 64 | +use Getnet\API\Credit; |
| 65 | +use Getnet\API\Customer; |
| 66 | +use Getnet\API\Card; |
| 67 | +use Getnet\API\Order; |
| 68 | + |
| 69 | +include 'vendor/autoload.php'; |
| 70 | + |
| 71 | +$client_id = "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx"; |
| 72 | +$client_secret = "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx"; |
| 73 | +$seller_id = "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx"; |
| 74 | +$environment = Environment::sandbox(); |
| 75 | + |
| 76 | +//Opicional, passar chave se você quiser guardar o token do auth na sessão para não precisar buscar a cada trasação, só quando expira |
| 77 | +$keySession = null; |
| 78 | + |
| 79 | +//Autenticação da API |
| 80 | +$getnet = new Getnet($client_id, $client_secret, $environment, $keySession); |
| 81 | + |
| 82 | +$brandToken = new BrandToken( |
| 83 | + "customer_210818263", |
| 84 | + "customer@email.com.br", |
| 85 | + "VISA", |
| 86 | + "MANUALLY_ENTERED", |
| 87 | + "4622943123039761", |
| 88 | + "722", |
| 89 | + "12", |
| 90 | + "2025", |
| 91 | + $getnet |
| 92 | +); |
| 93 | + |
| 94 | +$transaction = new Transaction(); |
| 95 | +$transaction->setSellerId($getnet->getSellerId()); |
| 96 | +$transaction->setCurrency("BRL"); |
| 97 | +$transaction->setAmount(103.03); |
| 98 | + |
| 99 | +//Adicionar dados do Pedido |
| 100 | +$transaction->order("123456") |
| 101 | + ->setProductType(Order::PRODUCT_TYPE_SERVICE) |
| 102 | + ->setSalesTax(0); |
| 103 | + |
| 104 | +//Criar token Cartão |
| 105 | +$tokenCard = new Token("4622943123039761", "customer_210818263", $getnet); |
| 106 | + |
| 107 | + |
| 108 | +//Adicionar dados do Pagamento |
| 109 | +$transaction->credit() |
| 110 | + ->setAuthenticated(false) |
| 111 | + ->setDynamicMcc("1799") |
| 112 | + ->setSoftDescriptor("LOJA*TESTE*COMPRA-123") |
| 113 | + ->setDelayed(false) |
| 114 | + ->setPreAuthorization(false) |
| 115 | + ->setNumberInstallments(3) |
| 116 | + ->setSaveCardData(false) |
| 117 | + ->setTransactionType(Credit::TRANSACTION_TYPE_INSTALL_WITH_INTEREST) |
| 118 | + ->card($tokenCard) |
| 119 | + ->setBrand(Card::BRAND_MASTERCARD) |
| 120 | + ->setExpirationMonth("12") |
| 121 | + ->setExpirationYear(date('y')+1) |
| 122 | + ->setCardholderName("Jax Teller") |
| 123 | + ->setSecurityCode("123"); |
| 124 | + |
| 125 | +//Adicionar dados do cliente |
| 126 | +$transaction->customer("customer_210818263") |
| 127 | + ->setDocumentType(Customer::DOCUMENT_TYPE_CPF) |
| 128 | + ->setEmail("customer@email.com.br") |
| 129 | + ->setFirstName("Jax") |
| 130 | + ->setLastName("Teller") |
| 131 | + ->setName("Jax Teller") |
| 132 | + ->setPhoneNumber("5551999887766") |
| 133 | + ->setDocumentNumber("12345678912") |
| 134 | + ->billingAddress() |
| 135 | + ->setCity("São Paulo") |
| 136 | + ->setComplement("Sons of Anarchy") |
| 137 | + ->setCountry("Brasil") |
| 138 | + ->setDistrict("Centro") |
| 139 | + ->setNumber("1000") |
| 140 | + ->setPostalCode("90230060") |
| 141 | + ->setState("SP") |
| 142 | + ->setStreet("Av. Brasil"); |
| 143 | + |
| 144 | +//Adicionar dados de entrega |
| 145 | +$transaction->shipping() |
| 146 | + ->setFirstName("Jax") |
| 147 | + ->setEmail("customer@email.com.br") |
| 148 | + ->setName("Jax Teller") |
| 149 | + ->setPhoneNumber("5551999887766") |
| 150 | + ->setShippingAmount(0) |
| 151 | + ->address() |
| 152 | + ->setCity("Porto Alegre") |
| 153 | + ->setComplement("Sons of Anarchy") |
| 154 | + ->setCountry("Brasil") |
| 155 | + ->setDistrict("São Geraldo") |
| 156 | + ->setNumber("1000") |
| 157 | + ->setPostalCode("90230060") |
| 158 | + ->setState("RS") |
| 159 | + ->setStreet("Av. Brasil"); |
| 160 | + |
| 161 | +$brandCryptToken = new BrandCryptToken( |
| 162 | + $brandToken->getNetworkTokenId(), |
| 163 | + BrandCryptToken::TYPE_MERCHANT, |
| 164 | + BrandCryptToken::TYPE_VISA, |
| 165 | + 103.03, |
| 166 | + "customer_210818263", |
| 167 | + "customer@email.com.br", |
| 168 | + "VISA", |
| 169 | + $getnet |
| 170 | +); |
| 171 | + |
| 172 | +$transaction->tokenization() |
| 173 | + ->setType(Tokenization::TYPE_MASTER) |
| 174 | + ->setCryptogram($brandCryptToken->getCryptogram()) |
| 175 | + ->setRequestorId($brandToken->getRequestId()); |
| 176 | + |
| 177 | +//Ou pode adicionar entrega com os mesmos dados do customer |
| 178 | +//$transaction->addShippingByCustomer($transaction->getCustomer())->setShippingAmount(0); |
| 179 | + |
| 180 | +//Adiciona o dispositivo |
| 181 | +$transaction->device("device_id")->setIpAddress("127.0.0.1"); |
| 182 | + |
| 183 | +$response = $getnet->authorize($transaction); |
| 184 | + |
| 185 | +print_r($response->getStatus()."\n"); |
| 186 | +``` |
| 187 | + |
| 188 | +--- |
| 189 | + |
| 190 | +### **Referências** |
| 191 | +- Documentação da API: [[link para a documentação](https://developers.getnet.com.br/idempotency#tag/Tokenizacao-Bandeira)] |
0 commit comments