forked from apoloz/alfa-bank-sdk
85 lines
3.3 KiB
PHP
85 lines
3.3 KiB
PHP
<?php
|
|
|
|
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
|
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 Saloon\Http\Faking\MockResponse;
|
|
use Spatie\LaravelData\DataCollection;
|
|
|
|
test('can create payment registry', function () {
|
|
$mockClient = new \Saloon\Http\Faking\MockClient([
|
|
CreateRegistryRequest::class => MockResponse::make([
|
|
'id' => 'REG-123',
|
|
'status' => 'CREATED'
|
|
], 201),
|
|
]);
|
|
|
|
$config = createTestConfig();
|
|
$connector = new AlfaBankConnector($config);
|
|
$connector->withMockClient($mockClient);
|
|
|
|
$payload = new RegistryRequestData(
|
|
payments: RegistryPaymentData::collect([
|
|
[
|
|
'amount' => 100.0,
|
|
'date' => '2023-10-10',
|
|
'payeeAccount' => '40702...',
|
|
'payeeBankBic' => '044...',
|
|
'payeeInn' => '770...',
|
|
'payeeName' => 'Recipient LLC',
|
|
'payerAccount' => '40702...',
|
|
'purpose' => 'Payment'
|
|
]
|
|
], DataCollection::class)
|
|
);
|
|
|
|
$response = $connector->send(new CreateRegistryRequest($payload));
|
|
|
|
expect($response->status())->toBe(201)
|
|
->and($response->json('id'))->toBe('REG-123');
|
|
});
|
|
|
|
test('can sign payment registry', function () {
|
|
$mockClient = new \Saloon\Http\Faking\MockClient([
|
|
SignRegistryRequest::class => MockResponse::make([], 200),
|
|
]);
|
|
|
|
$config = createTestConfig();
|
|
$connector = new AlfaBankConnector($config);
|
|
$connector->withMockClient($mockClient);
|
|
|
|
$signatures = RegistrySignatureData::collect([
|
|
[
|
|
'base64Encoded' => 'SIG...',
|
|
'signatureType' => 'RSA',
|
|
'certificateUuid' => 'CERT-123'
|
|
]
|
|
], DataCollection::class);
|
|
|
|
$response = $connector->send(new \Apoloz\AlfaBank\Requests\Registries\SignRegistryRequest('reg-1', \Apoloz\AlfaBank\Data\Registries\RegistrySignatureData::collect([], \Spatie\LaravelData\DataCollection::class)));
|
|
|
|
expect($response->status())->toBe(200);
|
|
});
|
|
|
|
test('can get registry details', function () {
|
|
$mockClient = new \Saloon\Http\Faking\MockClient([
|
|
\Apoloz\AlfaBank\Requests\Registries\GetRegistryRequest::class => \Saloon\Http\Faking\MockResponse::make(['id' => 'reg-1'], 200),
|
|
\Apoloz\AlfaBank\Requests\Registries\GetRegistryPaymentsRequest::class => \Saloon\Http\Faking\MockResponse::make(['payments' => []], 200),
|
|
]);
|
|
|
|
$config = new \Apoloz\AlfaBank\Core\AlfaConfig('https://test.com', __DIR__ . '/../../test_cert.pem', __DIR__ . '/../../test_key.pem');
|
|
$signer = new \Apoloz\AlfaBank\Services\OpenSslCmsSigner(__DIR__ . '/../../test_cert.pem', __DIR__ . '/../../test_key.pem');
|
|
$connector = new \Apoloz\AlfaBank\Core\AlfaBankConnector($config, $signer);
|
|
$connector->withMockClient($mockClient);
|
|
|
|
$response = $connector->send(new \Apoloz\AlfaBank\Requests\Registries\GetRegistryRequest('reg-1'));
|
|
expect($response->status())->toBe(200);
|
|
|
|
$response = $connector->send(new \Apoloz\AlfaBank\Requests\Registries\GetRegistryPaymentsRequest('reg-1'));
|
|
expect($response->status())->toBe(200);
|
|
});
|
|
|