potelo/inter-php

该软件包的最新版本(dev-main)没有提供许可证信息。

Banco Inter PHP 库

dev-main 2023-04-02 13:29 UTC

This package is auto-updated.

Last update: 2024-08-31 00:26:55 UTC


README

Banco Inter PHP 客户端提供了从用 PHP 语言编写的应用程序中方便地访问 Banco Inter API 的功能。

其他语言

en pt-br

要求

PHP 7.4.0 及以上版本。

Composer

您可以通过 Composer 安装该软件包。运行以下命令

composer require potelo/inter-php

或者,简单地将它添加到您的 composer.json 依赖中,然后运行 composer update

"require": {
    "potelo/inter-php": "dev-main"
}

要使用客户端,使用 Composer 的 自动加载

require_once 'vendor/autoload.php';

依赖项

该库需要以下扩展才能正常工作

如果您使用 Composer,这些依赖项应自动处理。如果您手动安装,请确保这些扩展可用。

用法

获取授权 文档

$privateKey = 'you-private-key-path.key';
$certificate = 'you-certificate-path.crt';
$clientId = 'you-client-id';
$clientSecret = 'your-client-secret';

$client = new \Potelo\InterPhp\InterClient($privateKey, $certificate, $clientId, $clientSecret);

$scopes = ['cob.read'];
$client->authorize($scopes);

您可以使用相同的客户端实例使用新的作用域获取新的令牌

$scopes = ['cob.read', 'cob.write', 'pix.read', 'pix.write'];
$client->authorize($scopes);

Bank Slip 收费 API

get 文档

获取一张银行汇票。

$bankSlip = $client->bankSlipApi()->get('bank-slip-our-number');

print_r($bankSlip);

getPdf 文档

获取一张银行汇票的 PDF。

$bankSlip = $client->bankSlipApi()->getPdf('bank-slip-our-number');

print_r($bankSlip);

create 文档

创建一张银行汇票。

$yorNumber = "your-number";
$dueDate = new \DateTime('2023-03-31');
$payer = new Payer("cpf number", "FISICA", "Payer Name", "Address", "Salvador", "BA", "41000000");
$bankSlip = $this->client->bankSlipApi()->create($yorNumber, 10.90, $dueDate, 0, $payer);

print_r($bankSlip);

list 文档

在一段时间内获取银行汇票列表。

$after = new \DateTime('2023-03-31');
$before = new \DateTime('2023-03-31');
$bankSlips = $this->client->bankSlipApi()->list($after, $before);

print_r($bankSlips);

其他过滤器

您可以将过滤器数组传递给 list 方法。

$after = new \DateTime('2023-03-31');
$before = new \DateTime('2023-03-31');
$filters = [
    'filtrarDataPor' => 'VENCIMENTO',
];

$bankSlips = $this->client->bankSlipApi()->list($after, $before, $filters);

print_r($bankSlips);

summary 文档

获取银行汇票列表的摘要。

$after = new \DateTime('2023-03-31');
$before = new \DateTime('2023-03-31');
$summary = $this->client->bankSlipApi()->summary($after, $before);

print_r($summary);

cancel 文档

取消银行汇票。

$cancelReason = "APEDIDODOCLIENTE";
$this->client->bankSlipApi()->cancel('bank-slip-our-number', $cancelReason);

Immediate Charge Pix API

get 文档

通过交易 ID 获取即时收费。

$immediateCharge = $client->immediateChargeApi()->get('your-immediate-charge-txid');

print_r($immediateCharge);

create 文档

创建即时收费。

$amount = 12.50;
$pixKey = 'your-pix-key';
$expiry = 3600; // seconds

$data = [
    "devedor" => [
        "cpf" => "01234567891",
        "nome" => "John Doe"
    ],
    "loc" => [
        "tipoCob" => "cob"
    ],
    "solicitacaoPagador" => " ",
    "infoAdicionais" => [
        [
            "nome" => "Product",
            "valor" => "cool pajamas"
        ]
    ]
];

$immediateCharge = $client->immediateChargeApi()->create($pixKey, $amount, $expiry, $data);

print_r($immediateCharge);

createAs 文档

指定唯一的交易 ID 创建即时收费。

$txId = 'your-unique-transaction-id';
$amount = 12.44;
$pixKey = 'your-pix-key';
$secondsToExpiry = 3600;

$data = [
    "devedor" => [
        "cpf" => "01234567891",
        "nome" => "John Doe"
    ],
    "loc" => [
        "tipoCob" => "cob"
    ],
    "solicitacaoPagador" => " ",
    "infoAdicionais" => [
        [
            "nome" => "Product",
            "valor" => "cool pajamas"
        ]
    ]
];

$immediateCharge = $client->immediateChargeApi()->createAs($txId, $pixKey, $amount, $secondsToExpiry, $data);

print_r($immediateCharge);

update 文档

更新即时收费。

$data = [
    "valor" => 22.50
];
$immediateCharge = $client->immediateChargeApi()->update('immediate-charge-txid', $data);

print_r($immediateCharge);

list 文档

在一段时间内获取即时收费列表。

$after = new \DateTime('2023-03-01T00:00:00-03:00');
$before = new \DateTime('2023-03-23T23:59:00-03:00');

$immediateCharges = $client->immediateChargeApi()->list($after, $before);

print_r($immediateCharges);

其他过滤器

您可以将过滤器数组传递给 list 方法。

$after = new \DateTime('2023-03-01T00:00:00-03:00');
$before = new \DateTime('2023-03-23T23:59:00-03:00');
$filters = [
    'cpf' => '01234567891',
];

$immediateCharges = $client->immediateChargeApi()->list($after, $before, $filters);

print_r($immediateCharges);

Pix Pix API

get 文档

通过交易 ID 获取 Pix。

$pix = $client->pixApi()->get('pix-endToEndId');

print_r($pix);

list 文档

获取一个时间段内的Pix列表。

$after = new \DateTime('2023-03-01T00:00:00-03:00');
$before = new \DateTime('2023-03-23T23:59:00-03:00');

$pixList = $client->immediateChargeApi()->list($after, $before);

print_r($pixList);

returnPix 文档

返回一个Pix。

$id = 'your-unique-id';
$amountToReturn = 12.44;
$pix = $client->pixApi()->returnPix('pix-endToEndId', $id, $amountToReturn);

print_r($pix);

getReturnPix 文档

获取Pix退货。

$id = 'your-unique-id';
$pix = $client->pixApi()->getReturnPix('pix-endToEndId', $id);

print_r($pix);

API文档

Banco Inter API文档可以在这里找到:这里