80 lines
2.9 KiB
PHP
80 lines
2.9 KiB
PHP
<?php
|
|
|
|
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
|
use Apoloz\AlfaBank\Data\B2C\B2CClientData;
|
|
use Apoloz\AlfaBank\Data\B2C\B2CPaymentRecipientData;
|
|
use Apoloz\AlfaBank\Data\B2C\B2CPaymentRequestData;
|
|
use Apoloz\AlfaBank\Requests\B2C\CreateB2CPaymentRequest;
|
|
use Apoloz\AlfaBank\Requests\B2C\GetB2CPaymentReportRequest;
|
|
use Saloon\Http\Faking\MockResponse;
|
|
use Spatie\LaravelData\DataCollection;
|
|
|
|
test('can create b2c sbp payout', function () {
|
|
$mockClient = new \Saloon\Http\Faking\MockClient([
|
|
CreateB2CPaymentRequest::class => MockResponse::make([
|
|
'status' => 'SUCCESS'
|
|
], 200, ['Content-Type' => 'application/json']),
|
|
]);
|
|
|
|
$config = createTestConfig();
|
|
$connector = new AlfaBankConnector($config);
|
|
$connector->withMockClient($mockClient);
|
|
|
|
$payload = new B2CPaymentRequestData(
|
|
client: new B2CClientData(b2cClientId: 'uuid-1', partnerId: 123),
|
|
inn: '7700000000',
|
|
account: '40702...',
|
|
total: 100.53,
|
|
signedBody: 'SIGNATURE',
|
|
payments: B2CPaymentRecipientData::collect([
|
|
[
|
|
'phone' => '79001112233',
|
|
'amount' => 100.53,
|
|
'nspkBankId' => '100000000001',
|
|
'sequence' => 'seq-1',
|
|
'name' => ['first' => 'Ivan', 'last' => 'Ivanov']
|
|
]
|
|
], DataCollection::class)
|
|
);
|
|
|
|
$response = $connector->send(new CreateB2CPaymentRequest($payload));
|
|
|
|
expect($response->status())->toBe(200);
|
|
});
|
|
|
|
test('can get b2c payment report', function () {
|
|
$mockClient = new \Saloon\Http\Faking\MockClient([
|
|
GetB2CPaymentReportRequest::class => MockResponse::make([
|
|
'payments' => []
|
|
], 200, ['Content-Type' => 'application/json']),
|
|
]);
|
|
|
|
$config = createTestConfig();
|
|
$connector = new AlfaBankConnector($config);
|
|
$connector->withMockClient($mockClient);
|
|
|
|
$response = $connector->send(new \Apoloz\AlfaBank\Requests\B2C\GetB2CPaymentReportRequest(null, null, '2023-01-01', '2023-01-02'));
|
|
|
|
expect($response->status())->toBe(200);
|
|
});
|
|
|
|
test('can get b2c package status', function () {
|
|
$mockClient = new \Saloon\Http\Faking\MockClient([
|
|
\Apoloz\AlfaBank\Requests\B2C\GetB2CPackageStatusRequest::class => \Saloon\Http\Faking\MockResponse::make([
|
|
'packageId' => 'pkg-123',
|
|
'status' => 'COMPLETED'
|
|
], 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\B2C\GetB2CPackageStatusRequest('pkg-123'));
|
|
|
|
expect($response->status())->toBe(200)
|
|
->and($response->json('status'))->toBe('COMPLETED');
|
|
});
|
|
|