diff --git a/src/PaymentMethods/KlarnaKP/KlarnaKP.php b/src/PaymentMethods/KlarnaKP/KlarnaKP.php index 3792adf0..00b53684 100644 --- a/src/PaymentMethods/KlarnaKP/KlarnaKP.php +++ b/src/PaymentMethods/KlarnaKP/KlarnaKP.php @@ -69,6 +69,8 @@ public function cancelReserve(): TransactionResponse $this->setServiceList('CancelReservation', $cancel); + $this->setPayPayload(); + return $this->dataRequest(); } diff --git a/tests/Buckaroo/Payments/KlarnaKPTest.php b/tests/Buckaroo/Payments/KlarnaKPTest.php index 4439d085..1395746f 100644 --- a/tests/Buckaroo/Payments/KlarnaKPTest.php +++ b/tests/Buckaroo/Payments/KlarnaKPTest.php @@ -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' => 'youremail@example.nl', - ], - 'shipping' => [ - 'recipient' => [ - 'firstName' => 'John', - 'lastName' => 'Do', - ], - 'address' => [ - 'street' => 'Rosenburglaan', - 'houseNumber' => '216', - 'zipcode' => '4385 JM', - 'city' => 'Vlissingen', - 'country' => 'NL', - ], - 'email' => 'test@buckaroo.nl', - ], - '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' => 'youremail@example.nl', + ], + 'shipping' => [ + 'recipient' => [ + 'firstName' => 'John', + 'lastName' => 'Do', + ], + 'address' => [ + 'street' => 'Rosenburglaan', + 'houseNumber' => '216', + 'zipcode' => '4385 JM', + 'city' => 'Vlissingen', + 'country' => 'NL', + ], + 'email' => 'test@buckaroo.nl', + ], + '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; + } }