diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 35224b2..a0eb583 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -15,6 +15,3 @@ jobs: with: release-type: php bump-minor-pre-major: true - - - uses: actions/checkout@v2 - if: ${{ steps.release.outputs.release_created }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e3e4662..2e2bf1f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,11 +32,13 @@ jobs: - name: Upload coverage to codecov uses: codecov/codecov-action@v2 + continue-on-error: true with: files: ./coverage.xml - name: Upload coverage to codeclimate uses: paambaati/codeclimate-action@v3.0.0 + continue-on-error: true env: CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TOKEN }} with: diff --git a/src/Models/TransactionResponse.php b/src/Models/TransactionResponse.php index 5169633..a3b009e 100644 --- a/src/Models/TransactionResponse.php +++ b/src/Models/TransactionResponse.php @@ -16,9 +16,11 @@ */ class TransactionResponse extends JsonResponse { - public bool $success; - public string $errorCode; public string $message; + public ?bool $success; + public ?string $errorCode; + public ?string $statusCode; + public ?string $activityId; #[MapFrom('payment.transactionId')] public ?string $transactionId; diff --git a/tests/SendDomesticTransactionTest.php b/tests/SendDomesticTransactionTest.php index 1bc23a2..2db76a5 100644 --- a/tests/SendDomesticTransactionTest.php +++ b/tests/SendDomesticTransactionTest.php @@ -89,6 +89,70 @@ public function it_can_prepare_request(): void $this->assertInstanceOf(TransactionResponse::class, $requestResult); $this->assertSame('BANKAPI123456789', $requestResult->transactionId); + $this->assertSame('0', $requestResult->errorCode); $this->assertSame('1', $requestResult->transactionStatus); + $this->assertSame(true, $requestResult->success); + } + + /** @test */ + public function it_can_handle_failed_reponse() + { + /** @var BankTransactionInterface $transaction */ + $transaction = $this->getMockBuilder(BankTransactionInterface::class)->getMock(); + + $mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock(); + $mockedConfig->method('getUrl')->willReturn('https://api.example/'); + $mockedConfig->method('getAppId')->willReturn($this->appId); + $mockedConfig->method('getClientSecret')->willReturn($this->clientSecret); + $mockedConfig->method('getSubscriptionKey')->willReturn($this->subscriptionKey); + + $mockedResponse = $this->getMockBuilder(ResponseInterface::class)->getMock(); + $mockedResponse->method('getStatusCode')->willReturn(500); + $mockedResponse->method('getBody') + ->willReturn('{ + "statusCode": 500, + "message": "Internal server error", + "activityId": "c1f6bbd9-096f-4c5f-b04f-fbfae795b0ea" + }'); + + /** @var \Mockery\MockInterface $mockedClient */ + $mockedClient = \Mockery::mock(\GuzzleHttp\Client::class); + $mockedClient->shouldReceive('request')->withArgs([ + 'POST', + 'https://api.example/bankAccountFT', + [ + \GuzzleHttp\RequestOptions::HEADERS => [ + 'Accept' => 'application/json', + 'Authorization' => "Bearer {$this->clientSecret}", + 'Ocp-Apim-Subscription-Key' => $this->subscriptionKey, + ], + \GuzzleHttp\RequestOptions::JSON => [ + 'debitAccount' => $transaction->getDebitAccount(), + 'beneficiaryAccount' => $transaction->getRecipientAccount(), + 'beneficiaryName' => $transaction->getRecipientName(), + 'amount' => $transaction->getAmount(), + 'currency' => $transaction->getCurrencyCode(), + 'narration' => $transaction->getDescription(), + 'auditId' => $transaction->getReference(), + 'appId' => $this->appId, + ], + ], + ])->once()->andReturn($mockedResponse); + + $mockedCache = $this->getMockBuilder(CacheInterface::class)->getMock(); + $mockedCache->method('has')->willReturn(true); + $mockedCache->method('get')->willReturn($this->clientSecret); + + /** + * @var ConfigInterface $mockedConfig + * @var \GuzzleHttp\Client $mockedClient + * @var CacheInterface $mockedCache + * */ + $api = new Client($mockedConfig, $mockedClient, $mockedCache); + + $requestResult = $api->sendDomesticTransaction($transaction); + + $this->assertInstanceOf(TransactionResponse::class, $requestResult); + $this->assertSame('Internal server error', $requestResult->message); } }