paysera / lib-wallet-transfer-rest-client

关于此软件包最新版本(0.3.0)没有提供许可信息。

Paysera.com 钱包转账的 PHP REST 客户端

0.3.0 2019-12-16 12:28 UTC

This package is auto-updated.

Last update: 2024-09-16 22:33:06 UTC


README

提供用于操作 Transfers API 的方法。它会自动验证所有请求并为您映射所需的数据结构。

使用方法

此库提供 ClientFactory 类,您应该使用此类来获取 API 客户端本身

use Paysera\Client\TransfersClient\ClientFactory;

$clientFactory = new ClientFactory([
    'base_url' => 'https://wallet.paysera.com/transfer/rest/v1/', // optional, in case you need a custom one.
    'basic' => [                                        // use this, it API requires Basic authentication.
        'username' => 'username',
        'password' => 'password',
    ],
    'oauth' => [                                        // use this, it API requires OAuth v2 authentication.
        'token' => [
            'access_token' => 'my-access-token',
            'refresh_token' => 'my-refresh-token',
        ],
    ],
    // other configuration options, if needed
]);

$transfersClient = $clientFactory->getTransfersClient();

请仅使用 Paysera 提供的单一认证机制。

现在,您已经有了 TransfersClient 的实例,您可以使用以下方法

方法

为转账保留资金并使其变为“已保留”。这足以使转账得到处理。如果没有足够的资金、达到任何限制等,转账仍将是“新的”且不会发生任何操作。如果没有可用资金,则返回错误。

use Paysera\Client\TransfersClient\Entity as Entities;

$transferRegistrationParameters = new Entities\TransferRegistrationParameters();

$transferRegistrationParameters->setConvertCurrency($convertCurrency);
$transferRegistrationParameters->setUserIp($userIp);
    
$result = $transfersClient->reserveTransfer($id, $transferRegistrationParameters);

为状态为 waiting_password 的转账提供密码。如果操作成功,转账状态将变为 done。仅适用于内部转账。如果提供的密码无效,则返回错误。

use Paysera\Client\TransfersClient\Entity as Entities;

$transferPassword = new Entities\TransferPassword();

$transferPassword->setValue($value);
    
$result = $transfersClient->provideTransferPassword($id, $transferPassword);

使转账在前端可见以进行签名。如果货币转换操作与转账相关,它们将在转账变为 reserved 时完成。如果存在与货币转换请求的期望,如果在那些期望失败的情况下,转账将与相关的转换请求一起变为 failed。这仅使转账“已保留”,因此在我们的 Web UI 中可见以供签名

use Paysera\Client\TransfersClient\Entity as Entities;

$transferRegistrationParameters = new Entities\TransferRegistrationParameters();

$transferRegistrationParameters->setConvertCurrency($convertCurrency);
$transferRegistrationParameters->setUserIp($userIp);
    
$result = $transfersClient->registerTransfer($id, $transferRegistrationParameters);

签名转账

use Paysera\Client\TransfersClient\Entity as Entities;

$transferRegistrationParameters = new Entities\TransferRegistrationParameters();

$transferRegistrationParameters->setConvertCurrency($convertCurrency);
$transferRegistrationParameters->setUserIp($userIp);
    
$result = $transfersClient->signTransfer($id, $transferRegistrationParameters);

获取转账。

$result = $transfersClient->getTransfer($id);

撤消转账。

$result = $transfersClient->deleteTransfer($id);

在系统中创建转账。创建的转账不可见,如果没有执行更多操作,则将被删除。

use Paysera\Client\TransfersClient\Entity as Entities;

$transferInput = new Entities\TransferInput();

$transferInput->setAmount($amount);
$transferInput->setBeneficiary($beneficiary);
$transferInput->setPayer($payer);
$transferInput->setFinalBeneficiary($finalBeneficiary);
$transferInput->setPerformAt($performAt);
$transferInput->setChargeType($chargeType);
$transferInput->setUrgency($urgency);
$transferInput->setNotifications($notifications);
$transferInput->setPurpose($purpose);
$transferInput->setPassword($password);
$transferInput->setCancelable($cancelable);
$transferInput->setAutoCurrencyConvert($autoCurrencyConvert);
$transferInput->setAutoChargeRelatedCard($autoChargeRelatedCard);
$transferInput->setAutoProcessToDone($autoProcessToDone);
$transferInput->setReserveUntil($reserveUntil);
$transferInput->setCallback($callback);
    
$result = $transfersClient->createTransfer($transferInput);

标准的 SQL 风格结果过滤

use Paysera\Client\TransfersClient\Entity as Entities;

$transfersFilter = new Entities\TransfersFilter();

$transfersFilter->setCreatedDateFrom($createdDateFrom);
$transfersFilter->setCreatedDateTo($createdDateTo);
$transfersFilter->setCreditAccountNumber($creditAccountNumber);
$transfersFilter->setDebitAccountNumber($debitAccountNumber);
$transfersFilter->setStatuses($statuses);
    
$result = $transfersClient->getTransfers($transfersFilter);