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>
57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use Apoloz\AlfaBank\AlfaBank;
|
|
use Apoloz\AlfaBank\Enums\Environment;
|
|
|
|
// 1. Initialize
|
|
// Ensure you have valid certificates for the Sandbox
|
|
$baas = AlfaBank::baas(
|
|
certificatePath: __DIR__ . '/certs/client.cer',
|
|
privateKeyPath: __DIR__ . '/certs/private.key',
|
|
environment: Environment::SANDBOX,
|
|
caBundlePath: __DIR__ . '/certs/russian_trusted_sub_ca.crt' // Mincifry
|
|
);
|
|
|
|
try {
|
|
echo "Authenticating...\n";
|
|
|
|
// METHOD A: Standard Client Credentials (for simple services)
|
|
// $baas->login(
|
|
// clientId: 'your-client-id',
|
|
// clientSecret: 'your-client-secret'
|
|
// );
|
|
|
|
// METHOD B: Authorization Code Flow (H2H) (for Nominal Accounts)
|
|
// See examples/13_h2h_auth_service.php for the full setup
|
|
$auth = \Apoloz\AlfaBank\AlfaBank::auth(
|
|
clientId: 'your-client-id',
|
|
clientSecret: 'your-client-secret',
|
|
redirectUri: 'https://...',
|
|
certificatePath: __DIR__ . '/certs/client.cer',
|
|
privateKeyPath: __DIR__ . '/certs/private.key',
|
|
environment: Environment::SANDBOX
|
|
);
|
|
// Assuming you have a saved refresh token:
|
|
// $auth->refreshToken('saved_refresh_token');
|
|
|
|
echo "Authentication Successful!\n";
|
|
|
|
// 2. Create a Beneficiary (Counterparty)
|
|
echo "Creating Beneficiary...\n";
|
|
|
|
// In a real app, use the DTOs
|
|
// $payload = new CreateBeneficiaryRequestData(...);
|
|
// $baas->send(new CreateBeneficiaryRequest($payload));
|
|
|
|
echo "Beneficiary Request Sent (Mock).\n";
|
|
|
|
} catch (\Exception $e) {
|
|
echo "Error: " . $e->getMessage() . "\n";
|
|
if ($e instanceof \Apoloz\AlfaBank\Exceptions\AlfaBankException) {
|
|
echo "API Code: " . $e->getErrorCode() . "\n";
|
|
}
|
|
}
|
|
|