rfservices/iugu-php-sdk

与 Iugu API 集成的非官方库

dev-master 2022-04-14 13:26 UTC

This package is auto-updated.

Last update: 2024-09-14 18:53:19 UTC


README

Iugu API 集成的库

StyleCI Maintainability

通过 composer 安装

$ composer require rfservices/iugu-php-sdk

服务

此 SDK 支持以下服务

API 参考

配置

为了使用此 SDK,您需要使用 Iugu 账户的访问令牌。

use bubbstore\Iugu;
use bubbstore\Iugu\Exceptions\IuguException;
use bubbstore\Iugu\Exceptions\IuguValidationException;

$iugu = new Iugu('SEU_TOKEN');

客户

创建客户

$customer = $iugu->customer()->create([
    'name'  => 'User Test',
    'email' => 'test@test.com',
]);

// Imprime o ID do cliente
echo $customer['id'];

更新客户

$customer = $iugu->customer()->update('ID_CLIENTE', [
    'name' => 'John'
]);

查找客户

$customer = $iugu->customer()->find('ID_CLIENTE');

var_dump($customer);

删除客户

$iugu->customer()->delete('ID_CLIENTE');

直接收费

创建带有银行汇票的收费

$charge = $iugu->charge()->create([
            'method'   => 'bank_slip',
            'email'    => 'test@test.com',
            'order_id' => uniqid(),
            'payer'    => [
                'cpf_cnpj'     => '65634052076',
                'name'         => 'User Test',
                'phone_prefix' => '11',
                'phone'        => '111111111',
                'email'        => 'test@test.com',
                'address'      => [
                    'street'   => 'Foo Bar',
                    'number'   => '123',
                    'district' => 'Foo',
                    'city'     => 'Foo',
                    'state'    => 'SP',
                    'zip_code' => '14940000',
                ],
            ],
            'items' => [
                [
                    'description' => 'Item 1',
                    'quantity'    => 1,
                    'price_cents' => 1000
                ],
                [
                    'description' => 'Item 2',
                    'quantity'    => 2,
                    'price_cents' => 2000
                ],
            ],
        ]);

使用信用卡支付账单

$charge = $iugu->charge()->create([
    'invoice_id' => '12345678',
    'token'      => '0000000000000000' // Token gerado através da lib iugu.js
]);

账单

创建账单

$invoice = $iugu->invoice()->create([
    'order_id'         => uniqid(),
    'email'            => 'test@test.com',
    'due_date'         => '2018-07-14',
    'notification_url' => 'https://webhook.site/08703bf2-d408-4f4c-b91c-0bc8e14352b2',
    'fines'            => false,
    'per_day_interest' => false,
    'discount_cents'   => 500,
    'ignore_due_email' => true,
    'payable_with'     => 'bank_slip',
    'items' => [
        [
            'description' => 'Item 1',
            'quantity'    => 1,
            'price_cents' => 1000
        ],
        [
            'description' => 'Item 2',
            'quantity'    => 2,
            'price_cents' => 2000
        ],
        [
            'description' => 'Frete',
            'quantity'    => 1,
            'price_cents' => 1000
        ],
    ],
    'payer' => [
        'cpf_cnpj'     => '65634052076',
        'name'         => 'User Test',
        'phone_prefix' => '11',
        'phone'        => '11111111',
        'email'        => 'test@test.com',
        'address'      => [
            'street'   => 'Foo Bar',
            'number'   => '123',
            'district' => 'Foo',
            'city'     => 'Foo',
            'state'    => 'SP',
            'zip_code' => '14940000',
        ],
    ],
]);

// Imprime o ID da fatura
echo $invoice['id'];

捕获账单

$iugu->invoice()->capture('ID_FATURA');

查找账单

$iugu->invoice()->find('ID_FATURA');

退款账单

$iugu->invoice()->refund('ID_FATURA');

取消账单

$iugu->invoice()->cancel('ID_FATURA');

支付方式

创建支付方式

$payment = $iugu->paymentMethod()->create('ID_CLIENTE', [
    'description' => 'Cartão de Crédito',
    'token'       => '123456',
]);

// Imprime o ID do pagamento
echo $payment['id'];

更新支付方式

$iugu->paymentMethod()->update('ID_CLIENTE', 'ID_METODO_PAGAMENTO', [
    'description' => 'Outra description',
]);

查找支付方式

$iugu->paymentMethod()->find('ID_CLIENTE', 'ID_METODO_PAGAMENTO');

删除支付方式

$iugu->paymentMethod()->delete('ID_CLIENTE', 'ID_METODO_PAGAMENTO');

测试

$ composer test

安全性

如果您发现任何与安全性相关的问题,请通过 contato@bubbstore.com.br 发送电子邮件,而不是使用问题报告。