forked from apoloz/alfa-bank-sdk
- Implement H2H authentication service for secure client authentication - Add new examples for authorization code flow and H2H auth service - Include example for generating client secret - Update core connector and token request functionality - Enhance README with new features Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use Apoloz\AlfaBank\AlfaBank;
|
|
use Apoloz\AlfaBank\Enums\Environment;
|
|
use Apoloz\AlfaBank\Requests\NominalAccounts\Beneficiaries\CreateBeneficiaryRequest;
|
|
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\CreateBeneficiaryRequestData;
|
|
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\AddressData;
|
|
use Apoloz\AlfaBank\Data\NominalAccounts\Payouts\DigestSignatureData;
|
|
use Spatie\LaravelData\DataCollection;
|
|
|
|
/**
|
|
* Example: Creating a Beneficiary for a Nominal Account.
|
|
* This flow requires a digital signature (CMS).
|
|
*/
|
|
|
|
$baas = AlfaBank::baas(
|
|
certificatePath: 'path/to/cert.pem',
|
|
privateKeyPath: 'path/to/key.pem',
|
|
environment: Environment::SANDBOX
|
|
);
|
|
|
|
// 1. Prepare beneficiary data
|
|
$payload = new CreateBeneficiaryRequestData(
|
|
type: 'FL_RESIDENT',
|
|
countryOfTaxResidence: 'RU',
|
|
name: 'Ivanov Ivan Ivanovich',
|
|
inn: '771234567890',
|
|
addresses: AddressData::collect([
|
|
[
|
|
'type' => 'REGISTRATION_ADDRESS',
|
|
'address' => 'Moscow, Lenina st, 10',
|
|
'country' => 'RU'
|
|
]
|
|
], DataCollection::class),
|
|
digestSignatures: DigestSignatureData::collect([
|
|
[
|
|
'base64Encoded' => 'MOCK_SIGNATURE', // In real life, use CmsSigner::sign()
|
|
'signatureType' => 'cms'
|
|
]
|
|
], DataCollection::class)
|
|
);
|
|
|
|
// 2. Login and send request
|
|
// For Nominal Accounts, use H2H Auth (Refresh Token)
|
|
// See examples/13_h2h_auth_service.php
|
|
$auth = AlfaBank::auth(
|
|
'client-id', 'client-secret', 'https://callback',
|
|
'path/to/cert.pem', 'path/to/key.pem', Environment::SANDBOX
|
|
);
|
|
$auth->refreshToken('saved-refresh-token'); // Authenticates the connector
|
|
|
|
$response = $baas->send(new CreateBeneficiaryRequest($payload));
|
|
|
|
if ($response->successful()) {
|
|
$data = $response->dto(); // BeneficiaryResponseData
|
|
echo "Beneficiary creation accepted. ID: {$data->id}, Status: {$data->status}\n";
|
|
} else {
|
|
echo "Error: " . $response->body() . "\n";
|
|
}
|