64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use Apoloz\AlfaBank\AlfaBank;
|
|
use Apoloz\AlfaBank\Data\Registries\RegistryPaymentData;
|
|
use Apoloz\AlfaBank\Data\Registries\RegistryRequestData;
|
|
use Apoloz\AlfaBank\Data\Registries\RegistrySignatureData;
|
|
use Apoloz\AlfaBank\Requests\Registries\CreateRegistryRequest;
|
|
use Apoloz\AlfaBank\Requests\Registries\SignRegistryRequest;
|
|
use Apoloz\AlfaBank\Utils\CmsSigner;
|
|
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";
|