be-lenka/fio-php-sdk

从 Fio 银行读取 JSON 文件并可以发送请求。

1.0.1 2024-05-31 12:06 UTC

This package is auto-updated.

Last update: 2024-09-11 07:08:06 UTC


README

支持 Fio API。读取是通过 JSON 文件提供的。

项目安装

安装 be-lenka/fio-php-sdk 的最佳方式是使用 Composer

$ composer require be-lenka/fio-php-sdk

如何使用

这里有一个 示例,通过命令行运行。此脚本需要同一目录中的 account.ini 文件,其外观如下。

[my-account]
account = 123456789
token = abcdefghijklmn

[wife-account]
account = 987654321
token = zyxuvtsrfd

FioFactory 类帮助您创建 FioPay 和 FioRead 类的实例。

use Belenka\Fio;
$fioFactory = new Fio\Utils\FioFactory([
	'my-alias' => [
		'account' => '123456789',
		'token' => 'abcdefg'
	],
	'next-alias' => [
		'account' => '987654321',
		'token' => 'tuvwxyz'
	]
]);

$fioRead = $fioFactory->createFioRead('my-account');
$fioPay = $fioFactory->createFioPay('wife-account');

读取

在日期之间读取范围。

use Belenka\Fio;
/* @var $fioRead Fio\FioRead */
/* @var $list Fio\Response\Read\TransactionList */
$list = $fioRead->movements(/* $from, $to */); // default is last week

foreach ($list as $transaction) {
    /* @var $transaction Fio\Response\Read\Transaction */
    var_dump($transaction->moveId);
    foreach ($transaction as $property => $value) {
        var_dump($property, $value);
    }
}

var_dump($list->getInfo());

您可以通过年份的 ID 下载交易。

use Belenka\Fio;
/* @var $fioRead Fio\FioRead */
/* @var $list Fio\Response\Read\TransactionList */
$list = $fioRead->movementId(2, 2015); // second transaction of year 2015

非常有用的方法,可以下载最后几笔交易。

下载后,自动设置新的断点。

use Belenka\Fio;
/* @var $fioRead Fio\FioRead */
/* @var $list Fio\Response\Read\TransactionList */
$list = $fioRead->lastDownload();
// same use like above
var_dump($list->getInfo()->idLastDownload);

更改您的断点。

按日期。

$fioRead->setLastDate('1986-12-30');
$list = $fioRead->lastDownload();
var_dump($list->getInfo()->idLastDownload);

按交易 ID。

$fioRead->setLastId(123456789);
$list = $fioRead->lastDownload();
var_dump($list->getInfo()->idLastDownload); // 123456789

自定义交易类

默认为 Belenka\Fio\Response\Read\Transaction,如果您想为属性指定其他名称,请将其定义为 FioFactory 的第二个参数。

定义注解,并不要忘记在括号中包含 ID。

<?php

use Belenka\Fio\Response\Read\TransactionAbstract

/**
 * @property-read float $amount [1]
 * @property-read string $to_account [2]
 * @property-read string $bank_code [3]
 */
class MyTransaction extends TransactionAbstract
{
	/** custom method */
	public function setBank_code($value)
	{
		return str_pad($value, 4, '0', STR_PAD_LEFT);
	}
}

$fioFactory = new Utils\FioFactory([/* ... */], 'MyTransaction');

支付(写入)

API 有三种响应语言,默认设置为 cs。要更改

/* @var $fioPay Belenka\Fio\FioPay */
$fioPay->setLanguage('en');

发送请求的方法是 send,它接受文件路径到您的 xml 或 abo 文件或 Property 类的实例。

$myFile = '/path/to/my/xml/or/abo/file'
$fioPay->send($myFile);

仅对捷克或斯洛伐克支付的对象

/* @var $national Belenka\Fio\Request\Pay\Payment\National */
$national = $fioPay->createNational($amount, $accountTo);
$national->setVariableSymbol($vs);
/* set next payment property $national->set* */
$fioPay->send($national);

欧元区支付

/* @var $euro Belenka\Fio\Request\Pay\Payment\Euro */
$euro = $fioPay->createEuro($amount, $accountTo, $name);
$euro->setVariableSymbol($vs);
/* set next payment property $euro->set* */
$fioPay->send($euro);

国际支付

/* @var $international Belenka\Fio\Request\Pay\Payment\International */
$international = $fioPay->createInternational($amount, $accountTo, $bic, $name, $street, $city, $country, $info);
$international->setRemittanceInfo2('foo');
/* set next payment property $international->set* */
$fioPay->send($international);

在一个请求中发送更多支付

foreach($pamentsRows as $row) {
	/* @var $national Belenka\Fio\Request\Pay\Payment\National */
	$national = $fioPay->createNational($row->amount, $row->accountTo);
	$national->setVariableSymbol($row->vs);
	$fioPay->addPayment($national);
}
$fioPay->send();