Skip to content

Commit

Permalink
feat: use source
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Nov 23, 2023
1 parent 2e61093 commit 9b35b28
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .devcontainer/devcontainer.json
@@ -0,0 +1,7 @@
// 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": "union-bank-api-client-php",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/php:0-8.1"
}
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -33,7 +33,8 @@
"brokeyourbike/resolve-uri": "^1.0",
"brokeyourbike/http-enums": "^2.0",
"brokeyourbike/data-transfer-object": "^0.2",
"psr/simple-cache": "^1.0|^3.0"
"psr/simple-cache": "^1.0|^3.0",
"brokeyourbike/has-source-model": "^2.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4",
Expand Down
11 changes: 11 additions & 0 deletions src/Client.php
Expand Up @@ -8,6 +8,8 @@

namespace BrokeYourBike\UnionBank;

use BrokeYourBike\HasSourceModel\HasSourceModelTrait;
use BrokeYourBike\HasSourceModel\SourceModelInterface;
use Psr\SimpleCache\CacheInterface;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\ClientInterface;
Expand All @@ -30,6 +32,7 @@ class Client implements HttpClientInterface
{
use HttpClientTrait;
use ResolveUriTrait;
use HasSourceModelTrait;

private ConfigInterface $config;
private CacheInterface $cache;
Expand Down Expand Up @@ -119,6 +122,10 @@ public function nameEnquiry(string $bankCode, string $accountNumber, ?AccountTyp

public function getTransactionStatus(TransactionInterface $transaction): GetTransactionStatusResponse
{
if ($transaction instanceof SourceModelInterface) {
$this->setSourceModel($transaction);
}

$response = $this->performRequest(HttpMethodEnum::GET, 'transactions/getStatus', [
'transactionReference' => $transaction->getRemoteReference(),
]);
Expand All @@ -127,6 +134,10 @@ public function getTransactionStatus(TransactionInterface $transaction): GetTran

public function initiateTransaction(TransactionInterface $transaction): InitiateTransactionResponse
{
if ($transaction instanceof SourceModelInterface) {
$this->setSourceModel($transaction);
}

$response = $this->performRequest(HttpMethodEnum::POST, 'transactions/initiate', [
'pin' => $transaction->getReference(),
'merchantCode' => $this->config->getMerchantCode(),
Expand Down

0 comments on commit 9b35b28

Please sign in to comment.