145 lines
6.3 KiB
PHP
145 lines
6.3 KiB
PHP
<?php
|
||
|
||
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
||
use Apoloz\AlfaBank\Requests\Statement\GetTransactionsRequest;
|
||
use Saloon\Http\Faking\MockResponse;
|
||
|
||
test('can get transactions statement', function (): void {
|
||
$mockClient = new \Saloon\Http\Faking\MockClient([
|
||
GetTransactionsRequest::class => MockResponse::make([
|
||
'_links' => [
|
||
['rel' => 'prev', 'href' => '?accountNumber=40702810500006103990&statementDate=2018-03-15&page=1'],
|
||
['rel' => 'next', 'href' => '?accountNumber=40702810500006103990&statementDate=2018-03-15&page=3'],
|
||
],
|
||
'transactions' => [
|
||
[
|
||
'uuid' => '55daccdf-de87-3879-976c-8b8415c8caf9',
|
||
'transactionId' => '1211206MOCO#DS0000017',
|
||
'operationDate' => '2018-12-31T00:00:00Z',
|
||
'number' => '1843',
|
||
'direction' => 'CREDIT',
|
||
'amount' => ['amount' => 100.00, 'currencyName' => 'RUB'],
|
||
'amountRub' => ['amount' => 100.00, 'currencyName' => 'RUR'],
|
||
'documentDate' => '2021-10-07',
|
||
'filial' => 'АО "АЛЬФА-БАНК"',
|
||
'operationCode' => '01',
|
||
'paymentPurpose' => 'НДС не облагается',
|
||
'priority' => '5',
|
||
'revaln' => 'ПК',
|
||
'correspondingAccount' => '30101810400000000225',
|
||
'debtorCode' => '0',
|
||
'extendedDebtorCode' => '50012008',
|
||
'rurTransfer' => [
|
||
'cartInfo' => [
|
||
'documentCode' => 'doc-code',
|
||
'documentNumber' => 'doc-num',
|
||
],
|
||
'deliveryKind' => 'электронно',
|
||
'departmentalInfo' => [
|
||
'kbk' => '39210202010061000160',
|
||
'oktmo' => '11605000',
|
||
],
|
||
'payeeAccount' => '40802810401300015422',
|
||
'payeeBankBic' => '044525593',
|
||
'payeeInn' => '7728168971',
|
||
'payeeName' => 'Наименование получателя',
|
||
'payerAccount' => '40802810701300000761',
|
||
'payerBankBic' => '044525593',
|
||
'payerInn' => '7728168971',
|
||
'payerName' => 'Гаврилов Добрыня Петрович',
|
||
'payingCondition' => 'payingCondition',
|
||
'paymentKind110' => '1',
|
||
'purposeCode' => '1',
|
||
'receiptDate' => '2018-12-31',
|
||
'valueDate' => '2018-12-31',
|
||
],
|
||
'swiftTransfer' => [
|
||
'bankOperationCode' => 'CRED',
|
||
'beneficiaryBankAccount' => 'LOYDGB21323',
|
||
'beneficiaryBankName' => 'АО "АЛЬФА-БАНК"',
|
||
'exchangeRate' => '67,74',
|
||
'instructedAmount' => 'USD70,00',
|
||
],
|
||
'curTransfer' => [
|
||
'bankOperationCode' => 'CRED',
|
||
'intermediaryBankOption' => 'D',
|
||
'intermediaryBankName' => 'АО "АЛЬФА-БАНК"',
|
||
'orderingCustomerName' => 'ООО Радуга',
|
||
'exchangeRate' => '67,74',
|
||
],
|
||
],
|
||
],
|
||
], 200, ['Content-Type' => 'application/json']),
|
||
]);
|
||
|
||
$config = createTestConfig();
|
||
$connector = new AlfaBankConnector($config);
|
||
$connector->withMockClient($mockClient);
|
||
|
||
$request = new GetTransactionsRequest(
|
||
accountNumber: '40702810500006103990',
|
||
statementDate: '2018-03-15',
|
||
page: 2,
|
||
curFormat: 'swiftTransfer',
|
||
);
|
||
$response = $connector->send($request);
|
||
|
||
$dto = $response->dto();
|
||
|
||
expect($response->status())->toBe(200);
|
||
expect($dto->_links)->toBeArray()->toHaveCount(2);
|
||
expect($dto->transactions)->toHaveCount(1);
|
||
|
||
$tx = $dto->transactions[0];
|
||
expect($tx->transactionId)->toBe('1211206MOCO#DS0000017')
|
||
->and($tx->direction)->toBe('CREDIT')
|
||
->and($tx->amount->amount)->toBe(100.00)
|
||
->and($tx->amountRub->currencyName)->toBe('RUR')
|
||
->and($tx->documentDate)->toBe('2021-10-07')
|
||
->and($tx->filial)->toBe('АО "АЛЬФА-БАНК"')
|
||
->and($tx->operationCode)->toBe('01')
|
||
->and($tx->priority)->toBe('5')
|
||
->and($tx->revaln)->toBe('ПК')
|
||
->and($tx->debtorCode)->toBe('0')
|
||
->and($tx->extendedDebtorCode)->toBe('50012008');
|
||
|
||
expect($tx->rurTransfer)->not->toBeNull();
|
||
expect($tx->rurTransfer->cartInfo)->not->toBeNull();
|
||
expect($tx->rurTransfer->cartInfo->documentCode)->toBe('doc-code');
|
||
expect($tx->rurTransfer->deliveryKind)->toBe('электронно');
|
||
expect($tx->rurTransfer->departmentalInfo)->not->toBeNull();
|
||
expect($tx->rurTransfer->departmentalInfo->kbk)->toBe('39210202010061000160');
|
||
expect($tx->rurTransfer->payingCondition)->toBe('payingCondition');
|
||
expect($tx->rurTransfer->purposeCode)->toBe('1');
|
||
expect($tx->rurTransfer->receiptDate)->toBe('2018-12-31');
|
||
|
||
expect($tx->swiftTransfer)->not->toBeNull();
|
||
expect($tx->swiftTransfer->bankOperationCode)->toBe('CRED');
|
||
expect($tx->swiftTransfer->instructedAmount)->toBe('USD70,00');
|
||
|
||
expect($tx->curTransfer)->not->toBeNull();
|
||
expect($tx->curTransfer->orderingCustomerName)->toBe('ООО Радуга');
|
||
});
|
||
|
||
test('can get transactions with default page', function (): void {
|
||
$mockClient = new \Saloon\Http\Faking\MockClient([
|
||
GetTransactionsRequest::class => MockResponse::make([
|
||
'_links' => [],
|
||
'transactions' => [],
|
||
], 200, ['Content-Type' => 'application/json']),
|
||
]);
|
||
|
||
$config = createTestConfig();
|
||
$connector = new AlfaBankConnector($config);
|
||
$connector->withMockClient($mockClient);
|
||
|
||
$request = new GetTransactionsRequest(
|
||
accountNumber: '40702810500006103990',
|
||
statementDate: '2018-03-15',
|
||
);
|
||
$response = $connector->send($request);
|
||
|
||
expect($response->status())->toBe(200);
|
||
expect($response->dto()->transactions)->toHaveCount(0);
|
||
});
|