52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use Apoloz\AlfaBank\AlfaBank;
|
|
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\AddressData;
|
|
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\CreateBeneficiaryRequestData;
|
|
use Apoloz\AlfaBank\Enums\Environment;
|
|
use Apoloz\AlfaBank\Requests\NominalAccounts\Beneficiaries\CreateBeneficiaryRequest;
|
|
use Spatie\LaravelData\DataCollection;
|
|
|
|
// 1. Initialize
|
|
// In Laravel Tinker: $baas = app(\Apoloz\AlfaBank\Core\AlfaBankConnector::class);
|
|
// In Standalone:
|
|
$baas = AlfaBank::baas(
|
|
certificatePath: __DIR__ . '/certs/client.cer',
|
|
privateKeyPath: __DIR__ . '/certs/private.key',
|
|
environment: Environment::SANDBOX,
|
|
clientId: getenv('ALFA_BAAS_CLIENT_ID'),
|
|
clientSecret: getenv('ALFA_BAAS_CLIENT_SECRET')
|
|
);
|
|
|
|
// 2. Auth
|
|
// $baas->login(); // Or refresh token logic
|
|
|
|
// 3. Prepare Payload
|
|
$payload = new CreateBeneficiaryRequestData(
|
|
type: 'FL_RESIDENT',
|
|
countryOfTaxResidence: 'RU',
|
|
name: 'Ivanov Ivan',
|
|
addresses: new DataCollection(AddressData::class, [
|
|
new AddressData('REGISTRATION_ADDRESS', 'Moscow', 'RU'),
|
|
])
|
|
// Note: digestSignatures is now optional!
|
|
);
|
|
|
|
// 4. Sign Payload (New DX!)
|
|
$payload->sign($baas->getSigner());
|
|
|
|
// 5. Send
|
|
$response = $baas->send(new CreateBeneficiaryRequest($payload));
|
|
|
|
echo 'Status: ' . $response->status() . "\n";
|
|
echo 'ID: ' . $response->dto()->id . "\n";
|
|
|
|
if ($response->successful()) {
|
|
$data = $response->dto(); // BeneficiaryResponseData
|
|
echo "Beneficiary creation accepted. ID: {$data->id}, Status: {$data->status}\n";
|
|
} else {
|
|
echo 'Error: ' . $response->body() . "\n";
|
|
}
|