IntegraĆ§Ć£o com a AZPay para Laravel
composer require gmodugno/azpaylaravel
, (*1)
Abra o arquivo config/app.php
e adicione ao Array providers
a seguinte instruĆ§Ć£o:, (*2)
AzPayLaravel\AzPay\AzPayServiceProvider::class,
Ainda no arquivo config/app.php
adicione no Array aliases
a seguinte instruĆ§Ć£o:, (*3)
'AZPay' => AzPayLaravel\AzPay\Facades\AZPay::class,
Digite o seguinte comando no seu Terminal, (*4)
php artisan vendor:publish --tag=config
, (*5)
Pronto, se tudo deu certo, irĆ” paracer a seguinte mensagem, (*6)
Copied File [/vendor/gmodugno/azpaylaravel/src/AzPay/Config/azpay.php] To [/config/azpay.php]
, (*7)
Abra o arquivo config/azpay.php
e coloque suas credenciais da AzPay.
``` php
return [
'merchant_id' => 'MERCHANT_ID',
'merchant_key' => 'MERCHANT_KEY'
];, (*8)
## Inicializar a SDK ``` php $azpay = AZPay::init();
``` php // Order $azpay->setOrder([ 'reference' => '123456789', 'totalAmount' => '1000' ]);, (*9)
## Billing ``` php // Billing $azpay->setBilling([ 'customerIdentity' => '1', 'name' => 'Fulano de Tal', 'address' => 'Av. Federativa, 230', 'address2' => '10 Andar', 'city' => 'Mogi das Cruzes', 'state' => 'SP', 'postalCode' => '20031-170', 'phone' => '21 4009-9400', 'email' => 'fulanodetal@email.com' ]);
``` php // Options $azpay->setOptions([ 'urlReturn' => 'http://loja.exemplo.com.br', 'fraud' => 'false', 'customField' => '' ]);, (*10)
## CreditCard ``` php // CreditCard $azpay->setCardPayment([ 'acquirer' => AZPay::getCardOperators()['cielo']['modes']['store']['code'], 'method' => '1', 'amount' => '1000', 'currency' => AZPay::getCurrencies('BRL'), 'numberOfPayments' => '1', 'groupNumber' => '0', 'country' => 'BRA', 'flag' => 'visa', 'cardHolder' => 'JosƩ da Silva', 'cardNumber' => '4012001037141112', 'cardSecurityCode' => '123', 'cardExpirationDate' => '201805', 'saveCreditCard' => 'true' ]);
``` php // Try try {, (*11)
// venda direta $azpay->sale()->execute(); $xml_request = $azpay->response(); return $xml_request;
} catch (AzPayLaravel\AzPay\SDK\AZPay_Error $e) {, (*12)
# HTTP 409 - AZPay Error $error = $azpay->responseError(); dd($error);
} catch (AzPayLaravel\AzPay\SDK\AZPay_Curl_Exception $e) {, (*13)
# Connection Error dd($e->getMessage());
} catch (AzPayLaravel\AzPay\SDK\AZPay_Exception $e) {, (*14)
# General Error dd($e->getMessage());
} ```, (*15)
MIT license, (*16)