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:
45
examples/02_sbp_qr.php
Normal file
45
examples/02_sbp_qr.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Apoloz\AlfaBank\AlfaBank;
|
||||
use Apoloz\AlfaBank\Enums\Environment;
|
||||
use Apoloz\AlfaBank\Sbp\Requests\GetQrCodeRequest;
|
||||
use Apoloz\AlfaBank\Sbp\Data\QrCodeRequestData;
|
||||
|
||||
// 1. Initialize SBP
|
||||
$sbp = AlfaBank::sbp(
|
||||
certificatePath: __DIR__ . '/certs/client.cer',
|
||||
privateKeyPath: __DIR__ . '/certs/private.key',
|
||||
keyNameAlias: 'my-alias', // Required for SBP signatures in some contexts
|
||||
environment: Environment::SANDBOX
|
||||
);
|
||||
|
||||
try {
|
||||
echo "Generating Static QR Code...\n";
|
||||
|
||||
$payload = new QrCodeRequestData(
|
||||
termNo: 'TEST_TERM_001',
|
||||
qrcType: '01', // Static
|
||||
amount: '15000', // 150.00 RUB
|
||||
paymentPurpose: 'Test Payment'
|
||||
);
|
||||
|
||||
$request = new GetQrCodeRequest($payload);
|
||||
$response = $sbp->send($request);
|
||||
|
||||
if ($response->successful()) {
|
||||
$qrData = $response->dto();
|
||||
echo "QR Payload: " . $qrData->payload . "\n";
|
||||
echo "QR Image URL: " . $qrData->image . "\n";
|
||||
} else {
|
||||
echo "Failed to generate QR.\n";
|
||||
}
|
||||
|
||||
// Example of Pagination (if supported by SBP endpoints)
|
||||
// $paginator = $sbp->paginate(new SomeSbpListRequest());
|
||||
// foreach($paginator as $item) { ... }
|
||||
|
||||
} catch (\Exception $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user