Skip to content

Latest commit

 

History

History
145 lines (118 loc) · 2.59 KB

README.md

File metadata and controls

145 lines (118 loc) · 2.59 KB

Gerencianet for Yii2

An implementation of Gerencianet.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require code-on-yii/yii2-gerencianet:*

or add

"code-on-yii/yii2-gerencianet": "*"

to the require section of your composer.json file.

Usage

Append in your config file:

'components' => [
    'gerencianet' => [
        'class' => 'codeonyii\gerencianet\GerenciaNet',
        'client_id' => '',
        'client_secret' => '',
        'sandbox' => true
    ]
]

Add a product

Yii::$app->gerencianet->addProduct([
   'name' => 'Item 1',
   'amount' => 1,
   'value' => 1000
]);

Add a shipping

Yii::$app->gerencianet->addShipping([
    'name' => 'My Shipping',
    'value' => 2000
]);

Add a metadata

Yii::$app->gerencianet->addMetadata([
    'custom_id' => 'Product 0001',
    'notification_url' => 'http://my_domain.com/notification'
]);

Charge

Yii::$app->gerencianet->charge();

Add a customer

Yii::$app->gerencianet->addCustomer([
    'name' => 'Gorbadoc Oldbuck',
    'cpf' => '04267484171',
    'phone_number' => '5144916523'
]);

Pay with billet

$model = new Billet([
    'expire_at' => '2018-12-12',
    'instructions' => [
        'Pay only with money',
        'Do not pay with gold'
    ],
]);

$result = Yii::$app->gerencianet->payCharge($model);

Pay with credit card

$billingAddress = new Address([
    'street' => 'Av. JK',
    'number' => 909,
    'neighborhood' => 'Bauxita',
    'zipcode' => '35400000',
    'city' => 'Ouro Preto',
    'state' => 'MG',
]);

$model = new CreditCard([
    'installments' => 1,
    'billing_address' => $billingAddress,
    'payment_token' => '6426f3abd8688639c6772963669bbb8e0eb3c319',
]);

$result = Yii::$app->gerencianet->payCharge($model);

Register CreditCard JS and collect payment_token

GerenciaNetCreditCard::widget([
    'options' => [
            'brand' => 'visa',
            'number' => '9999999999999999',
            'cvv' => '123',
            'expiration_month' => '01',
        'expiration_year' => '2015'
    ],
    'callback' => new JsExpression('function() {
    }')
]);

Register Installments JS and collect installments

GerenciaNetInstallments::widget([
    'total' => 1000,
    'brand' => 'visa',
    'callback' => new JsExpression('function() {
    }')
]);

Get array of brands

GerenciaNetHelper::getBrands();

Testing

$ ./vendor/bin/phpunit