Skip to content

Commit

Permalink
refactor gateway methods to array $options
Browse files Browse the repository at this point in the history
  • Loading branch information
mysiar authored May 23, 2022
2 parents b088ae9 + 0c01622 commit d18e804
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
26 changes: 11 additions & 15 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
10 changes: 7 additions & 3 deletions tests-api/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GatewayTest extends TestCase
{
private $gateway;

public function setUp()
public function setUp(): void
{
$settings = [
'merchantId' => getenv('P24V1_MERCHANT_ID'),
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
Expand Down
10 changes: 8 additions & 2 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function itShouldCreateAMethods()
{
$request = $this->gateway->methods();
$this->assertInstanceOf(MethodsRequest::class, $request);
$this->assertSame('en', $request->getLang());
}

/**
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}

/**
Expand Down

0 comments on commit d18e804

Please sign in to comment.