opsway/yesbank-api

PHP SDK for YesBank API

0.4.8 2020-08-17 09:02 UTC

This package is auto-updated.

Last update: 2020-11-22 19:55:34 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run:

composer require opsway/yesbank-api

Usage

First of all, you should to prepare API client with your parameters:

use OpsWay\YesBank\Api;
use OpsWay\YesBank\Config;
use OpsWay\YesBank\Transport\HttpTransport;
use OpsWay\YesBank\Transport\MockTransport;

// Prepare config for connection
$config = new Config('<IS_PROD_MODE>', '<CLIENT_ID>', '<SECRET>', '<CUSTOMER_ID>', '<APP_ID>');
$config->setBasicAuthLogin('<BASIC_AUTH_LOGIN>');          // Optional
$config->setBasicAuthPassword('<BASIC_AUTH_PASSWORD>');    // Optional

// Add certificate and private key (optional)
$config->setSslCert('/path/to/your.crt');
$config->setSslKey('/path/to/your.key');

// Add CA certificate (optional)
$config->setCaCert('/path/to/cainfo.crt');

$transport = new HttpTransport($config);
// or you can use mocked transport
// $transport = new MockTransport($jsonResponse);
$api = new Api($transport);

Fund Transfer

Get Balance

$balance = $api->fundTransfer()->getBalance('<ACCOUNT_NUMBER>');

// Result: OpsWay\YesBank\Api\Dto\GetBalanceResultDto Object
// (
//     [version] => 2.0
//     [accountCurrencyCode] => INR
//     [accountBalanceAmount] => 6.0793648885606E+21
//     [lowBalanceAlert] => false
// )

Start Transfer

use OpsWay\YesBank\Api\Dto\BeneficiaryDto;

$beneficiary = new BeneficiaryDto;
$beneficiary->code = '<BENEFICIARY_CODE>';
$transfer = $api->fundTransfer()->startTransfer(
    '<UNIQUE_REQUEST_NUMBER>',
    '<ACCOUNT_NUMBER>',
    $beneficiary,
    '<AMOUNT>',
    '<TRANSFER_TYPE>',        // Optional, default 'ANY'
    '<CURRENCY_CODE>',        // Optional, default 'INR'
    '<PURPOSE_CODE>',         // Optional, default 'NODAL'
    '<REMITTER_INFO>',        // Optional, default 'FUND TRANSFER'
);

// Result: OpsWay\YesBank\Api\Dto\StartTransferResultDto Object
// (
//     [version] => 1
//     [requestReferenceNo] => <UNIQUE_REQUEST_NUMBER>
//     [uniqueResponseNo] => 2d96179c4b7e11ea8e950a0028fd0000
//     [attemptNo] => 1
//     [reqTransferType] => ANY
//     [statusCode] => AS
// )

Get transfer status

$status = $api->fundTransfer()->getTransferStatus('<UNIQUE_REQUEST_NUMBER>');

// Result: OpsWay\YesBank\Api\Dto\GetTransferStatusResultDto Object
// (
//     [version] => 2.0
//     [transferType] => ANY
//     [reqTransferType] => <TRANSFER_TYPE>
//     [transactionDate] => DateTime('2020-02-10 02:16:43.000000')
// 
//     [transferAmount] => <AMOUNT>
//     [transferCurrencyCode] => <CURRENCY_CODE>
//     [transactionStatus] => OpsWay\YesBank\Api\Dto\TransactionStatusDto Object
//         (
//             [statusCode] => FAILED
//             [subStatusCode] => ns:E6003
//             [bankReferenceNo] =>
//             [beneficiaryReferenceNo] =>
//         )
// )

Maintain Beneficiary

Some code preparations:

// Prepare bank and beneficiary 
use OpsWay\YesBank\Api\Dto\BankDto;
use OpsWay\YesBank\Api\Dto\BeneficiaryDto;

$beneficiary = new BeneficiaryDto;
$beneficiary->code = '<BENEFICIARY_CODE>';
$beneficiary->name = '<BENEFICIARY_NAME>';
$beneficiary->type = '<BENEFICIARY_TYPE>';
$beneficiary->accountNo = '<BENEFICIARY_ACCOUNT_NO>';

$bank = new BankDto();
$bank->name = '<BANK_NAME>';
$bank->ifscCode = '<BANK_IFSC_CODE>';

// You can change some transport config params (optional)
$api->getTransport()->getConfig()->setBasicAuthLogin('<BASIC_AUTH_LOGIN>');
$api->getTransport()->getConfig()->setBasicAuthPassword('<BASIC_AUTH_PASSWORD>');

Add Beneficiary

$result = $api->maintainBeneficiary()->add('<ACCOUNT_NUMBER>', $beneficiary, $bank, '<AMOUNT>', '<CURRENCY_CODE>', '<PAYMENT_TYPE>');

// Result: OpsWay\YesBank\Api\Dto\MaintainBeneficiaryResponseDto Object
// (
//    [requestStatus] => SUCCESS
//    [custId] => <CUSTOMER_ID>
//    [paymentType] => <PAYMENT_TYPE>
//    [srcAccountNo] => <ACCOUNT_NUMBER>
//    [beneficiaryCd] => <BENEFICIARY_CODE>
//    [beneName] => <BENEFICIARY_NAME>
//    [beneType] => <BENEFICIARY_TYPE>
//    [beneAccountNo] => <BENEFICIARY_ACCOUNT_NO>
//    [bankName] => <BANK_NAME>
//    [ifscCode] => <BANK_IFSC_CODE>
//    [transactionLimit] => <AMOUNT>
//    [currencyCd] => <CURRENCY_CODE>
//    [action] => ADD
//    [error] => stdClass Object()
// )

Modify Beneficiary

$result = $api->maintainBeneficiary()->modify('<ACCOUNT_NUMBER>', $beneficiary, $bank, '<AMOUNT>', '<CURRENCY_CODE>', '<PAYMENT_TYPE>');

// Result: OpsWay\YesBank\Api\Dto\MaintainBeneficiaryResponseDto Object
// (
//    [requestStatus] => SUCCESS
//    [reqRefNo] => <REQUEST_REFERENCE_NO>
//    [custId] => <CUSTOMER_ID>
//    [paymentType] => <PAYMENT_TYPE>
//    [srcAccountNo] => <ACCOUNT_NUMBER>
//    [beneficiaryCd] => <BENEFICIARY_CODE>
//    [beneName] => <BENEFICIARY_NAME>
//    [beneType] => <BENEFICIARY_TYPE>
//    [beneAccountNo] => <BENEFICIARY_ACCOUNT_NO>
//    [bankName] => <BANK_NAME>
//    [ifscCode] => <BANK_IFSC_CODE>
//    [transactionLimit] => <AMOUNT>
//    [currencyCd] => <CURRENCY_CODE>
//    [action] => MODIFY
//    [error] => stdClass Object()
// )

Verify Beneficiary

$result = $api->maintainBeneficiary()->verify('<ACCOUNT_NUMBER>', '<BENEFICIARY_CODE>', '<PAYMENT_TYPE>');

// Result: OpsWay\YesBank\Api\Dto\MaintainBeneficiaryResponseDto Object
// (
//    [requestStatus] => SUCCESS
//    [reqRefNo] => <REQUEST_REFERENCE_NO>
//    [custId] => <CUSTOMER_ID>
//    [paymentType] => <PAYMENT_TYPE>
//    [srcAccountNo] => <ACCOUNT_NUMBER>
//    [beneficiaryCd] => <BENEFICIARY_CODE>
//    [beneName] => <BENEFICIARY_NAME>
//    [beneType] => <BENEFICIARY_TYPE>
//    [beneAccountNo] => <BENEFICIARY_ACCOUNT_NO>
//    [bankName] => <BANK_NAME>
//    [ifscCode] => <BANK_IFSC_CODE>
//    [transactionLimit] => <AMOUNT>
//    [currencyCd] => <CURRENCY_CODE>
//    [action] => Verify
//    [error] => stdClass Object()
// )

Disable Beneficiary

Note: In order to enable a disabled beneficiary, perform a modify operation on the beneficiary.

$result = $api->maintainBeneficiary()->disable('<ACCOUNT_NUMBER>', '<BENEFICIARY_CODE>', '<PAYMENT_TYPE>');

// Result: OpsWay\YesBank\Api\Dto\MaintainBeneficiaryResponseDto Object
// (
//    [requestStatus] => SUCCESS
//    [reqRefNo] => <REQUEST_REFERENCE_NO>
//    [custId] => <CUSTOMER_ID>
//    [paymentType] => <PAYMENT_TYPE>
//    [srcAccountNo] => <ACCOUNT_NUMBER>
//    [beneficiaryCd] => <BENEFICIARY_CODE>
//    [action] => DISABLE
//    [error] => stdClass Object()
// )

License

The MIT License (MIT). Please see License File for more information.