forked from apoloz/alfa-bank-sdk
Update documentation and examples, add new nominal accounts features and authentication methods
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
70
examples/15_nominal_accounts_list.php
Normal file
70
examples/15_nominal_accounts_list.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Apoloz\AlfaBank\AlfaBank;
|
||||
use Apoloz\AlfaBank\Enums\Environment;
|
||||
use Apoloz\AlfaBank\Requests\NominalAccounts\Beneficiaries\GetBeneficiariesRequest;
|
||||
|
||||
/**
|
||||
* FINAL GOAL EXAMPLE: Get List of Nominal Account Beneficiaries
|
||||
*
|
||||
* This script assumes you have already:
|
||||
* 1. Generated/Received Certificates.
|
||||
* 2. Obtained Client ID & Secret (via Portal or Script 14).
|
||||
* 3. Passed H2H Auth via Browser and obtained a Refresh Token (via Script 13).
|
||||
*/
|
||||
|
||||
// --- CONFIGURATION (From .env) ---
|
||||
$config = [
|
||||
'client_id' => getenv('ALFA_BAAS_CLIENT_ID'),
|
||||
'client_secret' => getenv('ALFA_BAAS_CLIENT_SECRET'),
|
||||
'redirect_uri' => 'https://your-app.com/callback',
|
||||
'cert_path' => __DIR__ . '/certs/client.cer',
|
||||
'key_path' => __DIR__ . '/certs/private.key',
|
||||
|
||||
// BUSINESS DATA
|
||||
'account_num' => '40702810...', // Nominal Account Number
|
||||
'refresh_token' => 'saved_refresh_token_db' // Your stored token
|
||||
];
|
||||
|
||||
try {
|
||||
// 1. Initialize Connector with Auth Config
|
||||
$baas = AlfaBank::baas(
|
||||
certificatePath: $config['cert_path'],
|
||||
privateKeyPath: $config['key_path'],
|
||||
environment: Environment::SANDBOX,
|
||||
clientId: $config['client_id'],
|
||||
clientSecret: $config['client_secret'],
|
||||
redirectUri: $config['redirect_uri']
|
||||
);
|
||||
|
||||
// 2. Refresh Token (Get valid Access Token for this session)
|
||||
echo "Refreshing session...\n";
|
||||
$authenticator = $baas->refreshAccessToken($config['refresh_token']);
|
||||
|
||||
// Apply authentication to the connector
|
||||
$baas->authenticate($authenticator);
|
||||
|
||||
// 3. Perform Business Request
|
||||
echo "Requesting beneficiaries list...\n";
|
||||
$request = new GetBeneficiariesRequest(
|
||||
accountNumber: $config['account_num'],
|
||||
type: 'FL_RESIDENT'
|
||||
);
|
||||
|
||||
$response = $baas->send($request);
|
||||
|
||||
// 4. Handle Result
|
||||
$list = $response->dto();
|
||||
echo "Found " . count($list->beneficiaries) . " beneficiaries.\n";
|
||||
|
||||
foreach ($list->beneficiaries as $b) {
|
||||
echo "- {$b->name} (ID: {$b->beneficiaryId})\n";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user