igorsamaral / iugu-php
Iugu PHP 库
1.0.2
2021-07-06 17:40 UTC
Requires
- php: >=5.6.0
- guzzlehttp/guzzle: ^7.3
Requires (Dev)
- phpunit/phpunit: ^8.0
README
这个库旨在使其尽可能灵活,以便所有用户都可以使用所有版本的API的所有功能。
您可以通过访问此链接来获取Iugu的官方文档。
目录
安装
使用以下命令安装库
composer require igorsamaral/iugu-php
配置
要将库添加到您的项目中,只需执行以下操作
<?php require __DIR__ . "/vendor/autoload.php" $iugu = new Iugu\Client("SUA_CHAVE_DE_API");
定义自定义头
- 如果需要,您可以定义自定义HTTP头以供请求使用。为此,只需在创建
Client对象时提供它们即可。
<?php require __DIR__ . "/vendor/autoload.php" $iugu = new iugu\Client( "SUA_CHAVE_DE_API", ["headers" => ["MEU_HEADER_CUSTOMIZADO" => "VALOR HEADER CUSTOMIZADO"]] );
然后,您可以使用该客户端向Iugu.com.br发送请求,如下面的示例所示。
客户
客户代表您的商店或业务中的用户。该对象包含有关他们的信息,例如姓名、电子邮件和电话,以及其他字段。
创建客户
<?php $customer = $iugu->customers()->create([ "email" => "joao.neves@email.com", "name" => "João das Neves", "notes" => "lorem...", "phone" => "999999999", "phone_prefix" => "11", "cpf_cnpj" => "11743685009", "zip_code" => "76814112", "number" => "100", "street" => "Rua Cabedelo", "city" => "Porto Velho", "state" => "RO", "district" => "Marcos Freire", "complement" => "complemento...", "custom_variables" => [ "key" => "value" ] ]);
返回客户
<?php $customers = $iugu->customers()->getList();
返回一个客户
<?php $customer = $iugu->customers()->get([ "id" => "ID_DO_CLIENTE" ]);
令牌和直接扣费
令牌是客户支付方式的表示(例如:信用卡),它完全安全,因此没有人能够通过该令牌获取客户的信用卡信息。令牌是为特定交易生成的,使其更加安全。
创建令牌
<?php $token = $iugu->paymentToken()->create([ "account_id" => "ID_DA_SUA_CONTA_IUGU", "customer_id" => "ID_DO_CUSTOMER", "method" => "credit_card", "data" => [ "number" => "4242424242424242", "verification_value" => "648", "first_name" => "João", "last_name" => "das Neves", "month" => "01", "year" => "2023" ], "test" => true, ]);
直接扣费
通过支票或信用卡进行简单收款。
<?php $charge = $iugu->charges()->create([ "token" => "ID_DO_TOKEN_DE_PAGAMENTO_CRIADO", "customer_id" => "ID_DO_CUSTOMER", "total" => 10000, "payer" => [ "cpf_cnpj" => "84752882000", "name" => "João das Neves", "address" => [ "zip_code" => "72917210", "number" => "100" ] ], "items": [ [ "description" => "Descrição do item 1", "quantity" => 1, "price_cents" => 10000 ] ] ]);
账单
为客户创建账单。
创建账单
<?php $invoice = $iugu->invoices()->create([ "email" => "joao@email.com.br", "due_date" => "2021-07-21", "items" => [ [ "description" => "Descrição do item 1", "quantity" => 1, "price_cents" => 10000 ] ], "total" => 10000, "payer" => [ "cpf_cnpj" => "84752882000", "name" => "João das Neves", "address" => [ "zip_code" => "72917210", "number" => "100" ] ] ]);
返回账单
<?php $invoices = $iugu->invoices()->getList();
返回一个账单
<?php $invoice = $iugu->invoices()->get([ "id" => "ID_DA_FATURA" ]);