From 0c01622d41ec85df4159e4d879f761ec5e3f9aaf Mon Sep 17 00:00:00 2001 From: Piotr Synowiec Date: Mon, 23 May 2022 15:13:52 +0200 Subject: [PATCH] refactor-params-to-array: refactor all gateway methods to array $options (#29) --- src/Gateway.php | 26 +++++++++++--------------- tests-api/GatewayTest.php | 10 +++++++--- tests/GatewayTest.php | 10 ++++++++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 570c48b..c153de1 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -122,11 +122,11 @@ public function testAccess(): TestAccessRequest /** * @return AbstractRequest|MethodsRequest */ - public function methods(string $lang = 'en'): MethodsRequest + public function methods(array $options = [ + 'lang' => 'en', + ]): MethodsRequest { - return $this->createRequest(MethodsRequest::class, [ - 'lang' => $lang, - ]); + return $this->createRequest(MethodsRequest::class, $options); } /** @@ -152,21 +152,17 @@ public function completePurchase(array $options = []): CompletePurchaseRequest /** * @return AbstractRequest|PurchaseInfoRequest */ - public function purchaseInfo(string $sessionId): PurchaseInfoRequest + public function purchaseInfo(array $options = []): PurchaseInfoRequest { - return $this->createRequest(PurchaseInfoRequest::class, [ - 'sessionId' => $sessionId, - ]); + return $this->createRequest(PurchaseInfoRequest::class, $options); } /** * @return AbstractRequest|CardInfoRequest */ - public function cardInfo(string $transactionId): CardInfoRequest + public function cardInfo(array $options = []): CardInfoRequest { - return $this->createRequest(CardInfoRequest::class, [ - 'transactionId' => $transactionId, - ]); + return $this->createRequest(CardInfoRequest::class, $options); } /** @@ -184,7 +180,7 @@ public function refund(array $options = []): RefundsRequest * * @return AbstractRequest|CardPayRequest */ - public function cardPay(array $options): CardPayRequest + public function cardPay(array $options = []): CardPayRequest { return $this->createRequest(CardPayRequest::class, $options); } @@ -194,7 +190,7 @@ public function cardPay(array $options): CardPayRequest * * @return AbstractRequest|CardChargeRequest */ - public function cardCharge(array $options): CardChargeRequest + public function cardCharge(array $options = []): CardChargeRequest { return $this->createRequest(CardChargeRequest::class, $options); } @@ -204,7 +200,7 @@ public function cardCharge(array $options): CardChargeRequest * * @return AbstractRequest|PurchaseOfflineRequest */ - public function purchaseOffline(array $options): PurchaseOfflineRequest + public function purchaseOffline(array $options = []): PurchaseOfflineRequest { return $this->createRequest(PurchaseOfflineRequest::class, $options); } diff --git a/tests-api/GatewayTest.php b/tests-api/GatewayTest.php index a26442d..c37f04d 100644 --- a/tests-api/GatewayTest.php +++ b/tests-api/GatewayTest.php @@ -13,7 +13,7 @@ class GatewayTest extends TestCase { private $gateway; - public function setUp() + public function setUp(): void { $settings = [ 'merchantId' => getenv('P24V1_MERCHANT_ID'), @@ -107,7 +107,9 @@ public function testComplete(): void public function testPurchaseInfo(): void { $sessionId = '20c62d6b-5ff0-46a0-97eb-eea0dd5b4a93'; // real existing session - $response = $this->gateway->purchaseInfo($sessionId)->send(); + $response = $this->gateway->purchaseInfo([ + 'sessionId' => $sessionId, + ])->send(); VarDumper::dump($response->getCode()); VarDumper::dump($response->getInfo()); @@ -155,7 +157,9 @@ public function testCardInfo(): void { $transactionId = '317229535'; $this->markTestSkipped('Comment this out if you have payment with credit card'); - $response = $this->gateway->cardInfo($transactionId)->send(); + $response = $this->gateway->cardInfo([ + 'transactionId' => $transactionId, + ])->send(); dump($response->getCode()); dump($response->getInfo()); } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 6bfbbd9..f40e857 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -132,6 +132,7 @@ public function itShouldCreateAMethods() { $request = $this->gateway->methods(); $this->assertInstanceOf(MethodsRequest::class, $request); + $this->assertSame('en', $request->getLang()); } /** @@ -214,7 +215,9 @@ public function itShouldCreateARefund( */ public function itShouldCreateAPurchaseInfo() { - $request = $this->gateway->purchaseInfo('session-id'); + $request = $this->gateway->purchaseInfo([ + 'sessionId' => 'session-id', + ]); $this->assertInstanceOf(PurchaseInfoRequest::class, $request); $this->assertSame('session-id', $request->getSessionId()); } @@ -224,8 +227,11 @@ public function itShouldCreateAPurchaseInfo() */ public function itShouldCreateCardInfo() { - $request = $this->gateway->cardInfo('transaction-id'); + $request = $this->gateway->cardInfo([ + 'transactionId' => 'transaction-id', + ]); $this->assertInstanceOf(CardInfoRequest::class, $request); + $this->assertSame('transaction-id', $request->getTransactionId()); } /**