Define Adresss

Sending a customer billing address is always mandatory for payment via credit card, while the delivery address is optional.

The rest of this page has the detailed procedures, but you need to install one of our libraries on your server to run the sample code. Make sure the Gerencianet SDK has been installed.

Any address has the following structure:


Address Attributes:

AttributesDescriptionRequiredType
streetStreet nameYesString
numberNumberYesString/Integer
neighborhoodneighborhood nameYesString
complementAdress's ComplementNoString/null
cityCitySimYes
stateState (2 characters)YesString
zipcodeCEP, no dots or hyphenYesString

1. Setting address (usage example)

<?php
require __DIR__.'/../../vendor/autoload.php'; // caminho relacionado a SDK
use Gerencianet\Exception\GerencianetException;
use Gerencianet\Gerencianet;
$clientId = 'your_client_id'; // insira seu Client_Id, conforme o ambiente (Des ou Prod)
$clientSecret = 'your_client_secret'; // insira seu Client_Secret, conforme o ambiente (Des ou Prod)
$options = [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'sandbox' => true // altere conforme o ambiente (true = desenvolvimento e false = producao)
];
$paymentToken = 'payment_token'; // payment_token obtido na 1ª etapa (através do Javascript único por conta Gerencianet)
// $charge_id refere-se ao ID da transação gerada anteriormente
$params = [
'id' => $charge_id
];
$customer = [
'name' => 'Gorbadoc Oldbuck', // nome do cliente
'cpf' => '94271564656' , // cpf do cliente
'phone_number' => '5144916523' // telefone do cliente
];
$billingAddress = [
'street' => 'Street 3',
'number' => 10,
'neighborhood' => 'Bauxita',
'zipcode' => '35400000',
'city' => 'Ouro Preto',
'state' => 'MG',
];
$creditCard = [
'installments' => 1, // número de parcelas em que o pagamento deve ser dividido
'billing_address' => $billingAddress,
'payment_token' => $paymentToken,
'customer' => $customer
];
$body = [
'payment' => $payment
];
$payment = [
'credit_card' => $creditCard
];
try {
$api = new Gerencianet($options);
$charge = $api->payCharge($params, $body);
print_r($charge);
} catch (GerencianetException $e) {
print_r($e->code);
print_r($e->error);
print_r($e->errorDescription);
} catch (Exception $e) {
print_r($e->getMessage());
}


2. Setando endereço de entrega (exemplo de utilização)

<?php
require __DIR__.'/../../vendor/autoload.php'; // caminho relacionado a SDK
use Gerencianet\Exception\GerencianetException;
use Gerencianet\Gerencianet;
$clientId = 'your_client_id'; // insira seu Client_Id, conforme o ambiente (Des ou Prod)
$clientSecret = 'your_client_secret'; // insira seu Client_Secret, conforme o ambiente (Des ou Prod)
$options = [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'sandbox' => true // altere conforme o ambiente (true = desenvolvimento e false = producao)
];
// $charge_id refere-se ao ID da transação gerada anteriormente
$params = [
'id' => $charge_id
];
$customerAddress = [
'street' => 'Av. JK',
'number' => 909,
'neighborhood' => 'Bauxita',
'zipcode' => '35400000',
'city' => 'Ouro Preto',
'state' => 'MG',
];
$customer = [
'name' => 'Gorbadoc Oldbuck', // nome do cliente
'cpf' => '94271564656', // cpf do cliente
'phone_number' => '5144916523', // telefone do cliente
'address' => $customerAddress
];
$banking_billet = [
'customer' => $customer
];
$payment = [
'banking_billet' => $banking_billet // forma de pagamento (banking_billet = boleto)
];
$body = [
'payment' => $payment
];
try {
$api = new Gerencianet($options);
$charge = $api->payCharge($params, $body);
print_r($charge);
} catch (GerencianetException $e) {
print_r($e->code);
print_r($e->error);
print_r($e->errorDescription);
} catch (Exception $e) {
print_r($e->getMessage());
}