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:
65
examples/07_registry_signing.php
Normal file
65
examples/07_registry_signing.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Apoloz\AlfaBank\AlfaBank;
|
||||
use Apoloz\AlfaBank\Utils\CmsSigner;
|
||||
use Apoloz\AlfaBank\Requests\Registries\CreateRegistryRequest;
|
||||
use Apoloz\AlfaBank\Data\Registries\RegistryRequestData;
|
||||
use Apoloz\AlfaBank\Data\Registries\RegistryPaymentData;
|
||||
use Apoloz\AlfaBank\Requests\Registries\SignRegistryRequest;
|
||||
use Apoloz\AlfaBank\Data\Registries\RegistrySignatureData;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
/**
|
||||
* Example: Creating and Signing a Payment Registry (Batch Payments).
|
||||
*/
|
||||
|
||||
$baas = AlfaBank::baas(
|
||||
certificatePath: 'path/to/cert.pem',
|
||||
privateKeyPath: 'path/to/key.pem'
|
||||
);
|
||||
|
||||
// 1. Create Registry
|
||||
$payload = new RegistryRequestData(
|
||||
payments: RegistryPaymentData::collect([
|
||||
[
|
||||
'amount' => 500.0,
|
||||
'date' => date('Y-m-d'),
|
||||
'payeeAccount' => '40702...',
|
||||
'payeeBankBic' => '044...',
|
||||
'payeeInn' => '770...',
|
||||
'payeeName' => 'Vendor 1',
|
||||
'payerAccount' => '40702...',
|
||||
'purpose' => 'Payment for goods'
|
||||
]
|
||||
], DataCollection::class)
|
||||
);
|
||||
|
||||
$baas->login('client-id', 'client-secret');
|
||||
$response = $baas->send(new CreateRegistryRequest($payload));
|
||||
$registryId = $response->dto()->id;
|
||||
|
||||
echo "Registry Created: $registryId\n";
|
||||
|
||||
// 2. Sign Registry
|
||||
// In real life, you might need to sign the digest provided by the bank
|
||||
// or the registry content itself. This depends on the specific bank requirement.
|
||||
$signature = CmsSigner::sign(
|
||||
$registryId, // Example data
|
||||
file_get_contents('path/to/sign_cert.pem'),
|
||||
file_get_contents('path/to/sign_key.pem')
|
||||
);
|
||||
|
||||
$signatures = RegistrySignatureData::collect([
|
||||
[
|
||||
'base64Encoded' => $signature,
|
||||
'signatureType' => 'RSA',
|
||||
'certificateUuid' => 'YOUR_CERT_UUID'
|
||||
]
|
||||
], DataCollection::class);
|
||||
|
||||
$baas->send(new SignRegistryRequest($registryId, $signatures));
|
||||
|
||||
echo "Registry Signed.\n";
|
||||
|
||||
Reference in New Issue
Block a user