Payouts with our widget
You can make payouts using our tokenization widget. The widget stores the account number on the side of Bank 131 and returns a token to you, which you use to make payouts.
Step 1. Generate a public token
The public token is needed to work with the widget. Send a token request to create a token, specifying the tokenize_widget widget type. You will receive a public token in response.
Request example
- cURL
- PHP
curl -X POST \
http://demo.bank131.ru/api/v1/token \
-H 'Content-Type: application/json' \
-H 'X-PARTNER-PROJECT: your_project_name' \
-H 'X-PARTNER-SIGN: signature' \
-d '{
"tokenize_widget": {
"access": true
}
}'
use Bank131\SDK\API\Request\Builder\RequestBuilderFactory;
use Bank131\SDK\Client;
use Bank131\SDK\Config;
$config = new Config(
'https://demo.bank131.ru',
'your_project_name',
file_get_contents('/path/to/your/private_key.pem')
);
$client = new Client($config);
$request = RequestBuilderFactory::create()
->issuePublicTokenBuilder()
->setTokenizeWidget()
->build();
$response = $client->widget()->issuePublicToken($request);
$publicToken = $response->getPublicToken();
Step 2. Show the widget on your website
Initialize the widget on your website using the public token you received at the previous step.
After this, the recipient can enter their bank account number into the widget form.
Step 3. Create a payment session
Create a session using the session/create method. You will receive the payment session identifier in response. You will need it in the subsequent steps.
Alternatively, you can use the (
session/init/payout) method to create a session and a payout at the same time. In this case, specify all the payout parameters along with the token from the widget right away and skip the next step. This option is not recommended.
Request example
- cURL
- PHP
curl -X POST \
https://demo.bank131.ru/api/v1/session/create \
-H 'Content-Type: application/json' \
-H 'X-PARTNER-PROJECT: your_project_name' \
-H 'X-PARTNER-SIGN: signature' \
-d '{
"metadata": "good"
}'
use Bank131\SDK\API\Request\Builder\RequestBuilderFactory;
use Bank131\SDK\Client;
use Bank131\SDK\Config;
$config = new Config(
'https://demo.bank131.ru',
'your_project_name',
file_get_contents('/path/to/your/private_key.pem')
);
$client = new Client($config);
$request = RequestBuilderFactory::create()
->createPayoutSession()
->setMetadata('good')
->build();
$response = $client->session()->create($request);
Step 4. Start the payout
Start the payout using the session/start/payout method. Pass the session identifier along with the payout parameters and the token from the widget.
You can get information on the token or account using the token/info method. For example, you can get the first 5 and last 4 digits of the account number to show the recipient which account the payout will be credited to.
Request example
curl -X POST \
https://demo.bank131.ru/api/v1/session/start/payout \
-H 'Content-Type: application/json' \
-H 'X-PARTNER-PROJECT: your_project_name' \
-H 'X-PARTNER-SIGN: signature' \
-d '{
"session_id": "ps_3230",
"payment_method": {
"type": "bank_account",
"bank_account": {
"system_type": "ru",
"ru": {
"token": "3f03ee2580046153bb0aa859558e7ada10d3835270fdb4c4b70961239d37f31d",
"full_name": "Ivanov Ivan Ivanovich",
"description": "Money transfer"
}
}
},
"amount_details": {
"amount": 10000,
"currency": "rub"
},
"metadata": "good"
}'
Step 5. Wait for a webhook saying the payout is ready
Bank 131 will send you a ready_to_confirm webhook. This means that the payout can be performed and the Bank is waiting for you to confirm (or cancel) it.
Step 6. Confirm or cancel the payout
Check the payout details and confirm that you are ready to perform the payout (session/confirm) or cancel it (session/cancel).
Confirming the session
- cURL
- PHP
curl -X POST \
https://demo.bank131.ru/api/v1/session/confirm \
-H 'Content-Type: application/json' \
-H 'X-PARTNER-PROJECT: your_project_name' \
-H 'X-PARTNER-SIGN: signature' \
-d '{
"session_id": "ps_3230"
}'
use Bank131\SDK\Client;
use Bank131\SDK\Config;
$config = new Config(
'https://demo.bank131.ru',
'your_project_name',
file_get_contents('/path/to/your/private_key.pem')
);
$client = new Client($config);
$response = $client->session()->confirm('session_id');
Canceling the session
- cURL
- PHP
curl -X POST \
https://demo.bank131.ru/api/v1/session/cancel \
-H 'Content-Type: application/json' \
-H 'X-PARTNER-PROJECT: your_project_name' \
-H 'X-PARTNER-SIGN: signature' \
-d '{
"session_id": "ps_3230"
}'
use Bank131\SDK\Client;
use Bank131\SDK\Config;
$config = new Config(
'https://demo.bank131.ru',
'your_project_name',
file_get_contents('/path/to/your/private_key.pem')
);
$client = new Client($config);
$response = $client->session()->cancel('session_id');
Step 7. Wait for a webhook with the payout results
Bank 131 will send you a payment_finished webhook. The result of the payout can be found in the status field of the payments/payout_list object.
If the status is succeeded, then the payout was successful. If the status is failed, then an error occurred during the payout.
More about the payout statuses >