Skip to content
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: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "buckaroo/sdk",
"description": "Buckaroo payment SDK",
"license": "MIT",
"version": "1.22.1",
"version": "1.23.0",
"type": "library",
"require": {
"php": ">=7.4|^8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\PaymentMethods\KlarnaPay\Service\ParameterKeys;
namespace Buckaroo\Models;

use Buckaroo\Models\Adapters\ServiceParametersKeysAdapter;

class PhoneAdapter extends ServiceParametersKeysAdapter
class ShippingInfo extends Model
{
protected array $keys = [
'mobile' => 'Phone',
];
protected ?string $company;
protected ?string $trackingNumber;
protected ?string $shippingMethod;
}
108 changes: 108 additions & 0 deletions src/PaymentMethods/Klarna/Klarna.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
/*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to support@buckaroo.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact support@buckaroo.nl for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\PaymentMethods\Klarna;

use Buckaroo\Models\Model;
use Buckaroo\Models\Payload\DataRequestPayload;
use Buckaroo\PaymentMethods\Klarna\Models\Payload;
use Buckaroo\PaymentMethods\PayablePaymentMethod;
use Buckaroo\Transaction\Response\TransactionResponse;

class Klarna extends PayablePaymentMethod
{
/**
* @var string
*/
protected string $paymentName = 'klarna';

/**
* @param Model|null $model
* @return TransactionResponse
*/
public function pay(?Model $model = null): TransactionResponse
{
return parent::pay($model ?? new Payload($this->payload));
}

/**
* @return TransactionResponse
*/
public function reserve(): TransactionResponse
{
$this->payModel = DataRequestPayload::class;

$reserve = new Payload($this->payload);

$this->setServiceList('Reserve', $reserve);

$this->setPayPayload();

return $this->dataRequest();
}

/**
* @return TransactionResponse
*/
public function cancelReserve(): TransactionResponse
{
$this->payModel = DataRequestPayload::class;

$cancel = new Payload($this->payload);

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

$this->setPayPayload();

return $this->dataRequest();
}

/**
* @return TransactionResponse
*/
public function extendReserve(): TransactionResponse
{
$this->payModel = DataRequestPayload::class;

$extend = new Payload($this->payload);

$this->setServiceList('ExtendReservation', $extend);

$this->setPayPayload();

return $this->dataRequest();
}

/**
* @return TransactionResponse
*/
public function updateReserve(): TransactionResponse
{
$this->payModel = DataRequestPayload::class;

$update = new Payload($this->payload);

$this->setServiceList('UpdateReservation', $update);

$this->setPayPayload();

return $this->dataRequest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\PaymentMethods\KlarnaPay\Models;
namespace Buckaroo\PaymentMethods\Klarna\Models;

class PayPayload extends \Buckaroo\Models\Payload\PayPayload
class Article extends \Buckaroo\Models\Article
{
protected string $servicesSelectableByClient;
protected string $servicesExcludedForClient;
protected string $originalTransactionReference;
protected ?string $imageUrl;
protected ?string $productUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,40 @@
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\PaymentMethods\KlarnaPay\Models;
namespace Buckaroo\PaymentMethods\Klarna\Models;

use Buckaroo\Models\Article;
use Buckaroo\Models\ServiceParameter;
use Buckaroo\PaymentMethods\KlarnaPay\Service\ParameterKeys\ArticleAdapter;
use Buckaroo\PaymentMethods\Klarna\Service\ParameterKeys\ArticleAdapter;
use Buckaroo\PaymentMethods\Traits\CountableGroupKey;

class Pay extends ServiceParameter
class Payload extends ServiceParameter
{
use CountableGroupKey;

/**
* @var array|string[]
*/
private array $countableProperties = ['articles'];

/**
* @var Recipient
*/
protected array $articles = [];

protected Recipient $billingRecipient;
/**
* @var Recipient
*/
protected Recipient $shippingRecipient;

/**
* @var array
*/
protected array $articles = [];
protected ?ShippingInfo $shippingInfo;

protected int $gender;
protected string $operatingCountry;
protected string $pno;
protected string $dataRequestKey;
protected bool $shippingSameAsBilling = true;

/**
* @var array|\string[][]
*/
protected array $groupData = [
'articles' => [
'groupType' => 'Article',
],
'shippingInfo' => [
'groupType' => 'ShippingInfo',
],
];

/**
* @param $billing
* @return Recipient
*/
public function billing($billing = null)
{
if (is_array($billing)) {
Expand All @@ -71,23 +62,17 @@ public function billing($billing = null)
return $this->billingRecipient;
}

/**
* @param $shipping
* @return Recipient
*/
public function shipping($shipping = null)
{
if (is_array($shipping)) {
$this->shippingSameAsBilling = false;

$this->shippingRecipient = new Recipient('Shipping', $shipping);
}

return $this->shippingRecipient;
}

/**
* @param array|null $articles
* @return array
*/
public function articles(?array $articles = null)
{
if (is_array($articles)) {
Expand All @@ -98,4 +83,13 @@ public function articles(?array $articles = null)

return $this->articles;
}

public function shippingInfo($shippingInfo = null)
{
if (is_array($shippingInfo)) {
$this->shippingInfo = new ShippingInfo('ShippingInfo', $shippingInfo);
}

return $this->shippingInfo;
}
}
69 changes: 69 additions & 0 deletions src/PaymentMethods/Klarna/Models/Recipient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Buckaroo\PaymentMethods\Klarna\Models;

use Buckaroo\Models\Address;
use Buckaroo\Models\Email;
use Buckaroo\Models\Person;
use Buckaroo\Models\Phone;
use Buckaroo\Models\ServiceParameter;
use Buckaroo\PaymentMethods\Klarna\Service\ParameterKeys\AddressAdapter;
use Buckaroo\PaymentMethods\Klarna\Service\ParameterKeys\EmailAdapter;
use Buckaroo\PaymentMethods\Klarna\Service\ParameterKeys\PhoneAdapter;
use Buckaroo\PaymentMethods\Klarna\Service\ParameterKeys\RecipientAdapter;

class Recipient extends ServiceParameter
{
private string $type;

protected RecipientAdapter $recipient;

protected AddressAdapter $address;

protected PhoneAdapter $phone;

protected EmailAdapter $email;

public function __construct(string $type, ?array $values = null)
{
$this->type = $type;

parent::__construct($values);
}

public function phone($phone = null)
{
if (is_array($phone)) {
$this->phone = new PhoneAdapter(new Phone($phone), $this->type);
}

return $this->phone;
}

public function email($email = null)
{
if (is_string($email)) {
$this->email = new EmailAdapter(new Email($email), $this->type);
}

return $this->email;
}

public function address($address = null)
{
if (is_array($address)) {
$this->address = new AddressAdapter(new Address($address), $this->type);
}

return $this->address;
}

public function recipient($recipient = null)
{
if (is_array($recipient)) {
$this->recipient = new RecipientAdapter(new Person($recipient), $this->type);
}

return $this->recipient;
}
}
47 changes: 47 additions & 0 deletions src/PaymentMethods/Klarna/Models/ShippingInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to support@buckaroo.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact support@buckaroo.nl for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\PaymentMethods\Klarna\Models;

use Buckaroo\Models\ShippingInfo as ShippingInfoModel;
use Buckaroo\PaymentMethods\Klarna\Service\ParameterKeys\ShippingInfoAdapter;

class ShippingInfo extends \Buckaroo\Models\ShippingInfo
{
private string $type;

protected ?ShippingInfoAdapter $shippingInfo;

public function __construct(string $type, ?array $values = null)
{
$this->type = $type;

parent::__construct($values);
}

public function shippingInfo($shippingInfo = null)
{
if (is_array($shippingInfo)) {
$this->shippingInfo = new ShippingInfoAdapter(new ShippingInfoModel($shippingInfo), $this->type);
}

return $this->shippingInfo;
}
}
Loading