forked from apoloz/alfa-bank-sdk
refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
54
examples/04_nominal_accounts.php
Normal file
54
examples/04_nominal_accounts.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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
|
||||
$baas->login('client-id', 'client-secret');
|
||||
$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";
|
||||
}
|
||||
Reference in New Issue
Block a user