-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathpayout.php
More file actions
57 lines (46 loc) · 1.93 KB
/
Copy pathpayout.php
File metadata and controls
57 lines (46 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
header('Content-Type: text/html; charset=UTF-8');
/**
* Payouts (mass-payment). Account-level API: authenticates with the ACCOUNT key +
* login, not the project key. The login is the first argument of every payout method,
* and the account key goes in the options array, overriding the project key from the
* constructor.
*
* @link https://help.unitpay.ru/api/create_payout
* @link https://help.unitpay.ru/api/payout_info
* @link https://help.unitpay.ru/api/poluchenie-spravochnika-bankov-uchastnikov-sbp-api
*/
use Unitpay\Exception\UnitpayExceptionInterface;
use Unitpay\Model\Enum\PaymentType;
use Unitpay\Unitpay;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/config.php';
$unitpay = new Unitpay($domain, $secretKey);
$accountKey = ['secretKey' => $accountSecretKey];
$transactionId = 'payout-1782'; // unique on your side
try {
$payouts = $unitpay->payouts();
// SBP member banks: memberId is required for SBP payouts.
$banks = $payouts->getSbpBankList($login, $accountKey);
var_dump($banks->result ?? $banks->error ?? $banks);
// Create a payout to the recipient via SBP.
$response = $payouts->massPayment(
$login,
$transactionId,
100,
'79510000071',
PaymentType::SBP,
$accountKey + ['memberId' => '100000000004'] // memberId from getSbpBankList; SBP only
);
if (isset($response->result)) {
$payoutId = $response->result->payoutId;
$status = $response->result->status; // success | not_completed
// Later — check the payout status by your transactionId.
$info = $payouts->massPaymentStatus($login, $transactionId, $accountKey);
var_dump($info->result ?? $info->error ?? $info);
} elseif (isset($response->error->message)) {
print 'Error: ' . $response->error->message;
}
} catch (UnitpayExceptionInterface $exception) {
print 'SDK error: ' . $exception->getMessage();
}