Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BA-557-fix-klarnakp-cancel-reserve-bug #192

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading