Iugu API 集成非官方库

v1.0.3 2022-06-02 14:19 UTC

This package is auto-updated.

Last update: 2024-09-30 01:35:57 UTC


README

与 Iugu API 集成的库

StyleCI Maintainability

通过 composer 安装

$ composer require acaodireta-php/iugu

服务

此 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' => 'Lucas Colette',
    'email' => 'lucas@bubb.com.br',
]);

// 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' => 'lucas@bubb.com.br',
            'order_id' => uniqid(),
            'payer' => [
                'cpf_cnpj' => '65634052076',
                'name' => 'Lucas Colette',
                'phone_prefix' => '11',
                'phone' => '11111111',
                'email' => 'lucas@bubb.com.br',
                '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' => 'lucas@bubb.com.br',
    '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' => 'Lucas Colette',
        'phone_prefix' => '11',
        'phone' => '11111111',
        'email' => 'lucas@bubb.com.br',
        '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

变更日志

请参阅 CHANGELOG 获取最近更改的详细信息。

贡献

请参阅 CONTRIBUTING 获取更多详细信息。