forked from apoloz/alfa-bank-sdk
feat: Add Laravel tinker examples and update nominal accounts functionality
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -7,56 +7,42 @@ 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).
|
||||
*/
|
||||
|
||||
// 1. Initialize
|
||||
// In Laravel Tinker: $baas = app(\Apoloz\AlfaBank\Core\AlfaBankConnector::class);
|
||||
// In Standalone:
|
||||
$baas = AlfaBank::baas(
|
||||
certificatePath: 'path/to/cert.pem',
|
||||
privateKeyPath: 'path/to/key.pem',
|
||||
environment: Environment::SANDBOX
|
||||
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')
|
||||
);
|
||||
|
||||
// 1. Prepare beneficiary data
|
||||
// 2. Auth
|
||||
// $baas->login(); // Or refresh token logic
|
||||
|
||||
// 3. Prepare Payload
|
||||
$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)
|
||||
name: 'Ivanov Ivan',
|
||||
addresses: new DataCollection(AddressData::class, [
|
||||
new AddressData('REGISTRATION_ADDRESS', 'Moscow', 'RU')
|
||||
])
|
||||
// Note: digestSignatures is now optional!
|
||||
);
|
||||
|
||||
// 2. Login and send request
|
||||
// For Nominal Accounts, use H2H Auth (Refresh Token)
|
||||
// See examples/13_h2h_auth_service.php for setting this up.
|
||||
|
||||
// CREDENTIALS SOURCE:
|
||||
// - client-id: Developer Portal -> App -> Overview
|
||||
// - client-secret: Developer Portal -> App -> Keys (Click Eye Icon) OR SDK Generator
|
||||
$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
|
||||
// 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";
|
||||
|
||||
Reference in New Issue
Block a user