Skip to content

Commit

Permalink
feat: v3
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Feb 21, 2024
1 parent 1d90be9 commit 8ce276a
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 208 deletions.
20 changes: 20 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/devcontainers/php:0-8.1

RUN apt-get update && apt-get install -y \
libzip-dev \
libxml2-dev

# install php extensions
RUN docker-php-ext-install \
pdo \
pdo_mysql \
xml \
zip \
bcmath \
pcntl

# disable xdebug
RUN rm -f /usr/local/etc/php/conf.d/xdebug.ini

# set memory limit
RUN echo 'memory_limit = 512M' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/php
{
"name": "access-bank-api-client-php",

// More info: https://containers.dev/guide/dockerfile
"build": {
"dockerfile": "Dockerfile"
},

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"bmewburn.vscode-intelephense-client",
"calebporzio.better-phpunit",
"neilbrayfield.php-docblocker",
"MehediDracula.php-namespace-resolver"
]
}
}
}
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ jobs:
run: vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Upload coverage to codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
continue-on-error: true
with:
files: ./coverage.xml

- name: Upload coverage to codeclimate
uses: paambaati/codeclimate-action@v3.0.0
uses: paambaati/codeclimate-action@v5
continue-on-error: true
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TOKEN }}
Expand Down
67 changes: 29 additions & 38 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
use BrokeYourBike\HasSourceModel\SourceModelInterface;
use BrokeYourBike\HasSourceModel\HasSourceModelTrait;
use BrokeYourBike\AccessBank\Models\TransactionResponse;
use BrokeYourBike\AccessBank\Models\FetchBankAccountNameResponse;
use BrokeYourBike\AccessBank\Models\FetchAuthTokenResponse;
use BrokeYourBike\AccessBank\Models\FetchAccountBalanceResponse;
use BrokeYourBike\AccessBank\Interfaces\ConfigInterface;
use BrokeYourBike\AccessBank\Interfaces\BankTransactionInterface;

Expand All @@ -35,7 +33,6 @@ class Client implements HttpClientInterface

private ConfigInterface $config;
private CacheInterface $cache;
private int $ttlMarginInSeconds = 60;

public function __construct(ConfigInterface $config, ClientInterface $httpClient, CacheInterface $cache)
{
Expand Down Expand Up @@ -73,7 +70,7 @@ public function getAuthToken(): string
$this->cache->set(
$this->authTokenCacheKey(),
$response->accessToken,
(int) $response->expiresIn - $this->ttlMarginInSeconds
$response->expiresIn / 2
);

return $response->accessToken;
Expand Down Expand Up @@ -102,29 +99,7 @@ public function fetchAuthTokenRaw(): FetchAuthTokenResponse
return new FetchAuthTokenResponse($response);
}

public function fetchAccountBalanceRaw(string $auditId, string $accountNumber): FetchAccountBalanceResponse
{
$response = $this->performRequest(HttpMethodEnum::POST, 'getAccountBalance', [
'accountNumber' => $accountNumber,
'auditId' => $auditId,
'appId' => $this->config->getAppId(),
]);

return new FetchAccountBalanceResponse($response);
}

public function fetchDomesticBankAccountNameRaw(string $auditId, string $accountNumber): FetchBankAccountNameResponse
{
$response = $this->performRequest(HttpMethodEnum::POST, 'getBankAccountName', [
'accountNumber' => $accountNumber,
'auditId' => $auditId,
'appId' => $this->config->getAppId(),
]);

return new FetchBankAccountNameResponse($response);
}

public function fetchDomesticTransactionStatusRaw(string $auditId, string $reference): TransactionResponse
public function fetchDomesticTransactionStatus(string $auditId, string $reference): TransactionResponse
{
$response = $this->performRequest(HttpMethodEnum::POST, 'getBankFTStatus', [
'paymentAuditId' => $reference,
Expand All @@ -142,35 +117,51 @@ public function sendDomesticTransaction(BankTransactionInterface $bankTransactio
}

$response = $this->performRequest(HttpMethodEnum::POST, 'bankAccountFT', [
'auditId' => $bankTransaction->getReference(),
'appId' => $this->config->getAppId(),
'debitAccount' => $bankTransaction->getDebitAccount(),
'beneficiaryAccount' => $bankTransaction->getRecipientAccount(),
'beneficiaryName' => $bankTransaction->getRecipientName(),
'senderCountry' => $bankTransaction->getSenderCountry(),
'senderName' => $bankTransaction->getSenderName(),
'amount' => $bankTransaction->getAmount(),
'currency' => $bankTransaction->getCurrencyCode(),
'narration' => $bankTransaction->getDescription(),
'auditId' => $bankTransaction->getReference(),
'newCustomer' => false,
]);

return new TransactionResponse($response);
}

public function fetchOtheBankTransactionStatus(string $auditId, string $reference): TransactionResponse
{
$response = $this->performRequest(HttpMethodEnum::POST, 'getOtherBankFTStatus', [
'paymentAuditId' => $reference,
'auditId' => $auditId,
'appId' => $this->config->getAppId(),
]);

return new TransactionResponse($response);
}

public function sendOtherBankTransaction(BankTransactionInterface $bankTransaction): ResponseInterface
public function sendOtherBankTransaction(BankTransactionInterface $bankTransaction): TransactionResponse
{
if ($bankTransaction instanceof SourceModelInterface) {
$this->setSourceModel($bankTransaction);
}

return $this->performRequest(HttpMethodEnum::POST, 'USDOtherBankFT', [
'AuditId' => $bankTransaction->getReference(),
'AppId' => $this->config->getAppId(),
'DebitAccountNumber' => $bankTransaction->getDebitAccount(),
'BeneficiaryAccount' => $bankTransaction->getRecipientAccount(),
'BeneficiaryName' => $bankTransaction->getRecipientName(),
'Amount' => $bankTransaction->getAmount(),
'Bank' => $bankTransaction->getBankCode(),
'Narration' => $bankTransaction->getDescription(),
$response = $this->performRequest(HttpMethodEnum::POST, 'otherBankAccountFT', [
'auditId' => $bankTransaction->getReference(),
'appId' => $this->config->getAppId(),
'debitAccountNumber' => $bankTransaction->getDebitAccount(),
'beneficiaryAccount' => $bankTransaction->getRecipientAccount(),
'beneficiaryName' => $bankTransaction->getRecipientName(),
'amount' => $bankTransaction->getAmount(),
'bank' => $bankTransaction->getBankCode(),
'narration' => $bankTransaction->getDescription(),
]);

return new TransactionResponse($response);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Interfaces/BankTransactionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public function getBankCode(): string;
public function getDebitAccount(): string;
public function getRecipientAccount(): string;
public function getRecipientName(): string;
public function getSenderCountry(): string;
public function getSenderName(): string;
public function getDescription(): string;
}
23 changes: 0 additions & 23 deletions src/Models/FetchAccountBalanceResponse.php

This file was deleted.

24 changes: 0 additions & 24 deletions src/Models/FetchBankAccountNameResponse.php

This file was deleted.

83 changes: 0 additions & 83 deletions tests/FetchAccountBalanceRawTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author Ivan Stasiuk <[email protected]>
*/
class FetchDomesticTransactionStatusRawTest extends TestCase
class FetchDomesticTransactionStatusTest extends TestCase
{
private string $appId = 'app-id';
private string $clientSecret = 'secure-token';
Expand Down Expand Up @@ -73,7 +73,7 @@ public function it_can_prepare_request(): void
* */
$api = new Client($mockedConfig, $mockedClient, $mockedCache);

$requestResult = $api->fetchDomesticTransactionStatusRaw($this->auditId, '123456789');
$requestResult = $api->fetchDomesticTransactionStatus($this->auditId, '123456789');

$this->assertInstanceOf(TransactionResponse::class, $requestResult);
}
Expand Down
Loading

0 comments on commit 8ce276a

Please sign in to comment.