-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from buckaroo-it/BA-557-fix-klarnakp-cancel-r…
…eserve-bug BA-557-fix-klarnakp-cancel-reserve-bug
- Loading branch information
Showing
2 changed files
with
75 additions
and
80 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
namespace Tests\Buckaroo\Payments; | ||
|
||
use Buckaroo\Resources\Constants\RecipientCategory; | ||
use Tests\Buckaroo\BuckarooTestCase; | ||
|
||
class KlarnaKPTest extends BuckarooTestCase | ||
|
@@ -30,26 +31,9 @@ class KlarnaKPTest extends BuckarooTestCase | |
*/ | ||
public function it_creates_a_klarnakp_payment() | ||
{ | ||
$response = $this->buckaroo->method('klarnakp')->pay([ | ||
'amountDebit' => 50.30, | ||
'order' => uniqid(), | ||
'invoice' => uniqid(), | ||
'reservationNumber' => '2377577452', | ||
'serviceParameters' => [ | ||
'articles' => [ | ||
[ | ||
'identifier' => uniqid(), | ||
'quantity' => '2', | ||
], | ||
[ | ||
'identifier' => uniqid(), | ||
'quantity' => '2', | ||
], | ||
], | ||
] | ||
]); | ||
$response = $this->buckaroo->method('klarnakp')->pay($this->getPaymentPayload()); | ||
|
||
$this->assertTrue($response->isValidationFailure()); | ||
$this->assertTrue($response->isSuccess()); | ||
} | ||
|
||
/** | ||
|
@@ -58,63 +42,7 @@ public function it_creates_a_klarnakp_payment() | |
*/ | ||
public function it_creates_a_klarnakp_reserve() | ||
{ | ||
$response = $this->buckaroo->method('klarnakp')->reserve([ | ||
'invoice' => uniqid(), | ||
'gender' => "1", | ||
'operatingCountry' => 'NL', | ||
'pno' => '01011990', | ||
'billing' => [ | ||
'recipient' => [ | ||
'firstName' => 'John', | ||
'lastName' => 'Do', | ||
], | ||
'address' => [ | ||
'street' => 'Neherkade', | ||
'houseNumber' => '1', | ||
'zipcode' => '2521VA', | ||
'city' => 'Gravenhage', | ||
'country' => 'NL', | ||
], | ||
'phone' => [ | ||
'mobile' => '0612345678', | ||
], | ||
'email' => '[email protected]', | ||
], | ||
'shipping' => [ | ||
'recipient' => [ | ||
'firstName' => 'John', | ||
'lastName' => 'Do', | ||
], | ||
'address' => [ | ||
'street' => 'Rosenburglaan', | ||
'houseNumber' => '216', | ||
'zipcode' => '4385 JM', | ||
'city' => 'Vlissingen', | ||
'country' => 'NL', | ||
], | ||
'email' => '[email protected]', | ||
], | ||
'articles' => [ | ||
[ | ||
'identifier' => 'Articlenumber1', | ||
'description' => 'Blue Toy Car', | ||
'vatPercentage' => '21', | ||
'quantity' => '2', | ||
'price' => '20.10', | ||
], | ||
[ | ||
'identifier' => 'Articlenumber2', | ||
'description' => 'Red Toy Car', | ||
'vatPercentage' => '21', | ||
'quantity' => '1', | ||
'price' => '10.10', | ||
], | ||
], | ||
'additionalParameters' => [ | ||
'initiated_by_magento' => '1', | ||
'service_action' => 'something', | ||
], | ||
]); | ||
$response = $this->buckaroo->method('klarnakp')->reserve($this->getPaymentPayload()); | ||
|
||
$this->assertTrue($response->isPendingProcessing()); | ||
} | ||
|
@@ -125,11 +53,11 @@ public function it_creates_a_klarnakp_reserve() | |
*/ | ||
public function it_creates_a_klarnakp_cancel_reservation() | ||
{ | ||
$response = $this->buckaroo->method('klarnakp')->cancelReserve([ | ||
'reservationNumber' => '2377577452', | ||
]); | ||
$response = $this->buckaroo->method('klarnakp')->cancelReserve($this->getPaymentPayload([ | ||
'reservationNumber' => 'fe65cf62-94a2-4609-a4d8-23c369969f31', | ||
])); | ||
|
||
$this->assertTrue($response->isValidationFailure()); | ||
$this->assertTrue($response->isSuccess()); | ||
} | ||
|
||
/** | ||
|
@@ -211,4 +139,69 @@ public function it_creates_a_klarnakp_refund() | |
|
||
$this->assertTrue($response->isValidationFailure()); | ||
} | ||
|
||
private function getPaymentPayload(?array $additional = null): array | ||
{ | ||
$payload = [ | ||
'currency' => 'EUR', | ||
'amountDebit' => 50.30, | ||
'order' => uniqid(), | ||
'invoice' => uniqid(), | ||
'gender' => "1", | ||
'operatingCountry' => 'NL', | ||
'billing' => [ | ||
'recipient' => [ | ||
'firstName' => 'John', | ||
'lastName' => 'Do', | ||
], | ||
'address' => [ | ||
'street' => 'Neherkade', | ||
'houseNumber' => '1', | ||
'zipcode' => '2521VA', | ||
'city' => 'Gravenhage', | ||
'country' => 'NL', | ||
], | ||
'phone' => [ | ||
'mobile' => '0612345678', | ||
], | ||
'email' => '[email protected]', | ||
], | ||
'shipping' => [ | ||
'recipient' => [ | ||
'firstName' => 'John', | ||
'lastName' => 'Do', | ||
], | ||
'address' => [ | ||
'street' => 'Rosenburglaan', | ||
'houseNumber' => '216', | ||
'zipcode' => '4385 JM', | ||
'city' => 'Vlissingen', | ||
'country' => 'NL', | ||
], | ||
'email' => '[email protected]', | ||
], | ||
'articles' => [ | ||
[ | ||
'identifier' => 'Articlenumber1', | ||
'description' => 'Blue Toy Car', | ||
'vatPercentage' => '21', | ||
'quantity' => '2', | ||
'price' => '20.10', | ||
], | ||
[ | ||
'identifier' => 'Articlenumber2', | ||
'description' => 'Red Toy Car', | ||
'vatPercentage' => '21', | ||
'quantity' => '1', | ||
'price' => '10.10', | ||
], | ||
] | ||
]; | ||
|
||
if ($additional) { | ||
return array_merge($additional, $payload); | ||
} | ||
|
||
return $payload; | ||
} | ||
} |