Skip to content

Basic usage of Benjamin

Danton Dietze Cancella edited this page Aug 5, 2019 · 2 revisions

Getting Started

It is very simple to use Benjamin. You will only need an instance of Ebanx\Benjamin\Models\Configs\Config:

$config = new Config([
    //Config properties
]);

$ebanx = EBANX($config);

Example

Here's a simple example of a working snippet that generates a sandbox payment with boleto:

$config = new Config([
    'sandboxIntegrationKey' => 'YOUR_SANDBOX_INTEGRATION_KEY',
    'isSandbox' => true,
    'baseCurrency' => Currency::BRL
]);

$payment = new Payment([
    'type' => 'boleto',
    'address' => new Address([
        'address' => 'Rua Rodrigues',
        'city' => 'Vila Malena d\'Oeste',
        'country' => Country::BRAZIL,
        'state' => 'MS',
        'streetComplement' => 'Apto 35',
        'streetNumber' => '55',
        'zipcode' => '10493-222'
    ]),
    'amountTotal' => 48.63,
    'deviceId' => 'b2017154beac2625eec083a5d45d872f12dc2c57535e25aa149d3bdb57cbdeb9',
    'merchantPaymentCode' => 'a6d690137e32c38db369beed8844e997',
    'note' => 'Example payment.',
    'person' => new Person([
        'type' => 'business',
        'birthdate' => new \DateTime('1978-03-29 08:15:51.000000 UTC'),
        'document' => '40701766000118',
        'email' => '[email protected]',
        'ip' => '30.43.84.28',
        'name' => 'Sr. Gustavo Fernando Valência',
        'phoneNumber' =>  '(41) 9999-9999'
    ]),
    'items' => [
        new Item ([
            'sku' => 'S-NDI-359444',
            'name' => 'consequuntur perferendis',
            'description' => 'Aut aliquid quibusdam quidem neque alias aliquid culpa maxime. Totam voluptatum et fuga nesciunt expedita rerum.',
            'unitPrice' => 7.19,
            'quantity' => 3,
            'type' => 'sed'
        ]),
        new Item ([
            'sku' => 'X-LQF-592041',
            'name' => 'esse sint',
            'description' => 'Eligendi error iusto et ut. Cupiditate sint ut et in vitae non.',
            'unitPrice' => 9.02,
            'quantity' => 3,
            'type' => 'est'
        ])
    ],
    'responsible' => new Person ([
        'type' => 'personal',
        'birthdate' => new \DateTime ('1986-06-18 10:18:33 UTC'),
        'document' => '38346222653',
        'email' => '[email protected]',
        'ip' => '49.29.237.45',
        'name' => 'Luana Aragão Mendes',
        'phoneNumber' => '(74) 97063-8157',
    ]),
    'dueDate' => new \DateTime ('2017-05-20 01:47:31 UTC')
]);

$result = EBANX($config)->create($payment);

// Type can also be explicit, like so:
$result = EBANX($config)->boleto()->create($payment);

The result will be something like this (for now):

Array
(
    [payment] => Array
        (
            [hash] => 591b803da5549b6a1bac524b31e6eef55c2e67af8e40e1e4
            [pin] => 670071563
            [merchant_payment_code] => 248b2672f000e293268be28d6048d600
            [order_number] => null
            [status] => PE
            [status_date] => null
            [open_date] => 2017-05-16 19:42:05
            [confirm_date] => null
            [transfer_date] => null
            [amount_br] => 48.81
            [amount_ext] => 48.63
            [amount_iof] => 0.18
            [currency_rate] => 1.0000
            [currency_ext] => BRL
            [due_date] => 2018-11-22
            [instalments] => 1
            [payment_type_code] => boleto
            [boleto_url] => https://sandbox.ebanx.com/print/?hash=591b803da5549b6a1bac524b31e6eef55c2e67af8e40e1e4
            [boleto_barcode] => 34191760071244348372714245740007871600000004881
            [boleto_barcode_raw] => 34198716000000048811760012443483721424574000
            [pre_approved] => null
            [capture_available] => null
            [customer] => Array
                (
                    [document] => 40701766000118
                    [email] => [email protected]
                    [name] => SR GUSTAVO FERNANDO VALENCIA
                    [birth_date] => 1978-03-28
                )

        )

    [status] => SUCCESS
)
Clone this wiki locally