-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13ee9a8
commit 58b917e
Showing
9 changed files
with
287 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "brokeyourbike/parallex-bank-api-client", | ||
"description": "Parallex Bank API Client for PHP", | ||
"keywords": [ | ||
"api", | ||
"api-client", | ||
"parallex-bank", | ||
"brokeyourbike" | ||
], | ||
"type": "library", | ||
"license": "MPL-2.0", | ||
"autoload": { | ||
"psr-4": { | ||
"BrokeYourBike\\ParallexBank\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"BrokeYourBike\\ParallexBank\\Tests\\": "tests/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Ivan Stasiuk", | ||
"email": "[email protected]", | ||
"homepage": "https://stasi.uk" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": "^8.1", | ||
"brokeyourbike/http-client": "^1.0", | ||
"brokeyourbike/resolve-uri": "^1.0", | ||
"brokeyourbike/http-enums": "^2.0", | ||
"brokeyourbike/has-source-model": "^2.0", | ||
"brokeyourbike/data-transfer-object": "^0.2.0" | ||
}, | ||
"require-dev": { | ||
"bamarni/composer-bin-plugin": "^1.4", | ||
"phpunit/phpunit": "^9", | ||
"mockery/mockery": "^1.4", | ||
"nesbot/carbon": "^2.53" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"bamarni/composer-bin-plugin": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
// Copyright (C) 2023 Ivan Stasiuk <[email protected]>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ParallexBank; | ||
|
||
use GuzzleHttp\ClientInterface; | ||
use BrokeYourBike\ResolveUri\ResolveUriTrait; | ||
use BrokeYourBike\ParallexBank\Models\TransactionResponse; | ||
use BrokeYourBike\ParallexBank\Interfaces\TransactionInterface; | ||
use BrokeYourBike\ParallexBank\Interfaces\ConfigInterface; | ||
use BrokeYourBike\HttpEnums\HttpMethodEnum; | ||
use BrokeYourBike\HttpClient\HttpClientTrait; | ||
use BrokeYourBike\HttpClient\HttpClientInterface; | ||
use BrokeYourBike\HasSourceModel\SourceModelInterface; | ||
use BrokeYourBike\HasSourceModel\HasSourceModelTrait; | ||
|
||
/** | ||
* @author Ivan Stasiuk <[email protected]> | ||
*/ | ||
class Client implements HttpClientInterface | ||
{ | ||
use HttpClientTrait; | ||
use ResolveUriTrait; | ||
use HasSourceModelTrait; | ||
|
||
private ConfigInterface $config; | ||
|
||
public function __construct(ConfigInterface $config, ClientInterface $httpClient) | ||
{ | ||
$this->config = $config; | ||
$this->httpClient = $httpClient; | ||
} | ||
|
||
public function getConfig(): ConfigInterface | ||
{ | ||
return $this->config; | ||
} | ||
|
||
public function postTransaction(string $requestId, TransactionInterface $transaction): TransactionResponse | ||
{ | ||
$options = [ | ||
\GuzzleHttp\RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Client-Id' => $this->config->getClientId(), | ||
'Client-Key' => $this->config->getClientSecret(), | ||
], | ||
\GuzzleHttp\RequestOptions::JSON => [ | ||
'BankId' => $transaction->getBankCode(), | ||
'TrnType' => 'T', | ||
'TrnSubType' => 'CI', | ||
'RequestID' => $requestId, | ||
'PartTrnRec' => [ | ||
[ | ||
'AcctId' => $transaction->getBankAccount(), | ||
'CreditDebitFlg' => 'D', | ||
'TrnAmt' => $transaction->getAmount(), | ||
'CurrencyCode' => $transaction->getCurrencyCode(), | ||
'TrnParticulars' => $transaction->getReference(), | ||
'ValueDt' => $transaction->getValueDate()->format('Y-m-d\TH:i:s.uP'), | ||
] | ||
], | ||
], | ||
]; | ||
|
||
if ($transaction instanceof SourceModelInterface){ | ||
$options[\BrokeYourBike\HasSourceModel\Enums\RequestOptions::SOURCE_MODEL] = $transaction; | ||
} | ||
|
||
$uri = (string) $this->resolveUriFor($this->config->getUrl(), '/coreapi/api/finacle/PostingTransaction'); | ||
$response = $this->httpClient->request(HttpMethodEnum::POST->value, $uri, $options); | ||
|
||
return new TransactionResponse($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
// Copyright (C) 2023 Ivan Stasiuk <[email protected]>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ParallexBank\Enums; | ||
|
||
/** | ||
* @author Ivan Stasiuk <[email protected]> | ||
*/ | ||
enum ErrorCodeEnum: string | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
// Copyright (C) 2023 Ivan Stasiuk <[email protected]>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ParallexBank\Interfaces; | ||
|
||
/** | ||
* @author Ivan Stasiuk <[email protected]> | ||
*/ | ||
interface ConfigInterface | ||
{ | ||
public function getUrl(): string; | ||
public function getClientId(): string; | ||
public function getClientSecret(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
// Copyright (C) 2023 Ivan Stasiuk <[email protected]>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ParallexBank\Interfaces; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
/** | ||
* @author Ivan Stasiuk <[email protected]> | ||
*/ | ||
interface TransactionInterface | ||
{ | ||
public function getReference(): string; | ||
public function getAmount(): float; | ||
public function getCurrencyCode(): string; | ||
public function getBankCode(): string; | ||
public function getBankAccount(): string; | ||
public function getValueDate(): CarbonImmutable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
// Copyright (C) 2023 Ivan Stasiuk <[email protected]>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ParallexBank\Models; | ||
|
||
use Spatie\DataTransferObject\Attributes\MapFrom; | ||
use BrokeYourBike\DataTransferObject\JsonResponse; | ||
|
||
/** | ||
* @author Ivan Stasiuk <[email protected]> | ||
*/ | ||
class TransactionResponse extends JsonResponse | ||
{} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
// Copyright (C) 2023 Ivan Stasiuk <[email protected]>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ParallexBank\Tests; | ||
|
||
use BrokeYourBike\ResolveUri\ResolveUriTrait; | ||
use BrokeYourBike\ParallexBank\Interfaces\ConfigInterface; | ||
use BrokeYourBike\ParallexBank\Client; | ||
use BrokeYourBike\HttpClient\HttpClientTrait; | ||
use BrokeYourBike\HttpClient\HttpClientInterface; | ||
use BrokeYourBike\HasSourceModel\HasSourceModelTrait; | ||
|
||
/** | ||
* @author Ivan Stasiuk <[email protected]> | ||
*/ | ||
class ClientTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_implemets_http_client_interface(): void | ||
{ | ||
/** @var ConfigInterface */ | ||
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock(); | ||
|
||
/** @var \GuzzleHttp\ClientInterface */ | ||
$mockedHttpClient = $this->getMockBuilder(\GuzzleHttp\ClientInterface::class)->getMock(); | ||
|
||
$api = new Client($mockedConfig, $mockedHttpClient); | ||
|
||
$this->assertInstanceOf(HttpClientInterface::class, $api); | ||
$this->assertSame($mockedConfig, $api->getConfig()); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_http_client_trait(): void | ||
{ | ||
$usedTraits = class_uses(Client::class); | ||
|
||
$this->assertArrayHasKey(HttpClientTrait::class, $usedTraits); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_resolve_uri_trait(): void | ||
{ | ||
$usedTraits = class_uses(Client::class); | ||
|
||
$this->assertArrayHasKey(ResolveUriTrait::class, $usedTraits); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_has_source_model_trait(): void | ||
{ | ||
$usedTraits = class_uses(Client::class); | ||
|
||
$this->assertArrayHasKey(HasSourceModelTrait::class, $usedTraits); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
// Copyright (C) 2023 Ivan Stasiuk <[email protected]>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ParallexBank\Tests; | ||
|
||
/** | ||
* @author Ivan Stasiuk <[email protected]> | ||
*/ | ||
abstract class TestCase extends \PHPUnit\Framework\TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
\Mockery::close(); | ||
} | ||
} |