Skip to content

Commit

Permalink
- set fully payload on cancel reserve at klarna kp
Browse files Browse the repository at this point in the history
- update klarnakp tests
  • Loading branch information
vildanbina committed Oct 11, 2024
1 parent 438532d commit fe900ce
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 80 deletions.
2 changes: 2 additions & 0 deletions src/PaymentMethods/KlarnaKP/KlarnaKP.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function cancelReserve(): TransactionResponse

$this->setServiceList('CancelReservation', $cancel);

$this->setPayPayload();

return $this->dataRequest();
}

Expand Down
153 changes: 73 additions & 80 deletions tests/Buckaroo/Payments/KlarnaKPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace Tests\Buckaroo\Payments;

use Buckaroo\Resources\Constants\RecipientCategory;
use Tests\Buckaroo\BuckarooTestCase;

class KlarnaKPTest extends BuckarooTestCase
Expand All @@ -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());
}

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

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

0 comments on commit fe900ce

Please sign in to comment.