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

[WIP] Klarna Checkout v3 #750

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"authorizenet/authorizenet": "^1.8.1",
"sofort/sofortlib-php": "^3.0",
"paypal/rest-api-sdk-php" : "~1.0",
"klarna/checkout": "^1.1 || ^2.0",
"klarna/checkout": "~1|~2.0",
"klarna/kco_rest": "^3.0",
"fp/klarna-invoice": "0.1.*",
"stripe/stripe-php": "~2.0 || ~3.0",
"php-http/guzzle6-adapter": "^1.1.1",
Expand Down
9 changes: 9 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,18 @@
<testsuite name="Payum KlarnaCheckout Component Test Suite">
<directory>./src/Payum/Klarna/Checkout/Tests</directory>
</testsuite>
<testsuite name="Payum KlarnaCommon Component Test Suite">
<directory>./src/Payum/Klarna/Common/Tests</directory>
</testsuite>
<testsuite name="Payum KlarnaCheckoutRest Component Test Suite">
<directory>./src/Payum/Klarna/CheckoutRest/Tests</directory>
</testsuite>
<testsuite name="Payum KlarnaInvoice Component Test Suite">
<directory>./src/Payum/Klarna/Invoice/Tests</directory>
</testsuite>
<testsuite name="Payum KlarnaPayments Component Test Suite">
<directory>./src/Payum/Klarna/Payments/Tests</directory>
</testsuite>
<testsuite name="Payum Stripe Component Test Suite">
<directory>./src/Payum/Stripe/Tests</directory>
</testsuite>
Expand Down
3 changes: 3 additions & 0 deletions src/Payum/Core/Bridge/Twig/TwigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Payum\Klarna\CheckoutRest\KlarnaCheckoutRestGatewayFactory;


/**
* @deprecated since 1.0.0-BETA4
Expand All @@ -18,6 +20,7 @@ public static function createGenericPaths()
'PayumCore' => self::guessViewsPath('Payum\Core\Gateway'),
'PayumStripe' => self::guessViewsPath('Payum\Stripe\StripeJsGatewayFactory'),
'PayumKlarnaCheckout' => self::guessViewsPath('Payum\Klarna\Checkout\KlarnaCheckoutGatewayFactory'),
'PayumKlarnaCheckoutRest' => self::guessViewsPath(KlarnaCheckoutRestGatewayFactory::class),
'PayumSymfonyBridge' => self::guessViewsPath('Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter'),
)));
}
Expand Down
4 changes: 4 additions & 0 deletions src/Payum/Core/PayumBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
use Payum\Core\Storage\FilesystemStorage;
use Payum\Core\Storage\StorageInterface;
use Payum\Klarna\Checkout\KlarnaCheckoutGatewayFactory;
use Payum\Klarna\CheckoutRest\KlarnaCheckoutRestGatewayFactory;
use Payum\Klarna\Invoice\KlarnaInvoiceGatewayFactory;
use Payum\Klarna\Payments\KlarnaPaymentsGatewayFactory;
use Payum\Offline\OfflineGatewayFactory;
use Payum\OmnipayBridge\OmnipayGatewayFactory;
use Payum\OmnipayV3Bridge\OmnipayGatewayFactory as OmnipayV3GatewayFactory;
Expand Down Expand Up @@ -556,7 +558,9 @@ protected function buildGatewayFactories(GatewayFactoryInterface $coreGatewayFac
'be2bill_direct' => Be2BillDirectGatewayFactory::class,
'be2bill_offsite' => Be2BillOffsiteGatewayFactory::class,
'klarna_checkout' => KlarnaCheckoutGatewayFactory::class,
'klarna_checkout_rest' => KlarnaCheckoutRestGatewayFactory::class,
'klarna_invoice' => KlarnaInvoiceGatewayFactory::class,
'klarna_payments' => KlarnaPaymentsGatewayFactory::class,
'offline' => OfflineGatewayFactory::class,
'payex' => PayexGatewayFactory::class,
'stripe_checkout' => StripeCheckoutGatewayFactory::class,
Expand Down
3 changes: 3 additions & 0 deletions src/Payum/Core/Tests/Bridge/Twig/TwigFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function shouldAllowCreateGenericPaths()
$this->assertArrayHasKey('PayumKlarnaCheckout', $paths);
$this->assertStringEndsWith('Payum/Klarna/Checkout/Resources/views', $paths['PayumKlarnaCheckout']);

$this->assertArrayHasKey('PayumKlarnaCheckoutRest', $paths);
$this->assertStringEndsWith('Payum/Klarna/CheckoutRest/Resources/views', $paths['PayumKlarnaCheckoutRest']);

$this->assertArrayHasKey('PayumStripe', $paths);
$this->assertStringEndsWith('Payum/Stripe/Resources/views', $paths['PayumStripe']);

Expand Down
8 changes: 8 additions & 0 deletions src/Payum/Core/Tests/PayumBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
use Payum\Core\Security\TokenFactoryInterface;
use Payum\Core\Storage\StorageInterface;
use Payum\Klarna\Checkout\KlarnaCheckoutGatewayFactory;
use Payum\Klarna\CheckoutRest\KlarnaCheckoutRestGatewayFactory;
use Payum\Klarna\Invoice\KlarnaInvoiceGatewayFactory;
use Payum\Klarna\Payments\KlarnaPaymentsGatewayFactory;
use Payum\Offline\OfflineGatewayFactory;
use Payum\OmnipayV3Bridge\OmnipayGatewayFactory;
use Payum\Payex\PayexGatewayFactory;
Expand Down Expand Up @@ -119,9 +121,15 @@ public function shouldBuildDefaultPayum()
$this->assertArrayHasKey('klarna_checkout', $factories);
$this->assertInstanceOf(KlarnaCheckoutGatewayFactory::class, $factories['klarna_checkout']);

$this->assertArrayHasKey('klarna_checkout_rest', $factories);
$this->assertInstanceOf(KlarnaCheckoutRestGatewayFactory::class, $factories['klarna_checkout_rest']);

$this->assertArrayHasKey('klarna_invoice', $factories);
$this->assertInstanceOf(KlarnaInvoiceGatewayFactory::class, $factories['klarna_invoice']);

$this->assertArrayHasKey('klarna_payments', $factories);
$this->assertInstanceOf(KlarnaPaymentsGatewayFactory::class, $factories['klarna_payments']);

$this->assertArrayHasKey('offline', $factories);
$this->assertInstanceOf(OfflineGatewayFactory::class, $factories['offline']);

Expand Down
32 changes: 18 additions & 14 deletions src/Payum/Klarna/Checkout/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,37 @@ language: php
sudo: false

git:
depth: 10
depth: 1

cache:
directories:
- $HOME/.composer/cache

matrix:
include:
- php: 5.5
env: SYMFONY_VERSION=2.8.*
- php: 5.6
env: SYMFONY_VERSION=2.8.*
- php: 7.0
env: SYMFONY_VERSION=v3
- php: 7.1
env: SYMFONY_VERSION=v3
- php: 7.2
env: SYMFONY_VERSION=v3
- php: 7.1
env: SYMFONY_VERSION=v4
- php: 7.2
env: SYMFONY_VERSION=v4
- php: 7.3
env: SYMFONY_VERSION=v5
env: SYMFONY_VERSION=2.8.*
- php: 5.5
env: SYMFONY_VERSION=3.0.*
- php: 5.6
env: SYMFONY_VERSION=3.0.*
- php: 7.0
env: SYMFONY_VERSION=3.0.*
- php: hhvm
env: SYMFONY_VERSION=2.8.*
allow_failures:
- php: hhvm

before_install:
- composer self-update
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; else INI_FILE=/etc/hhvm/php.ini; fi;

install:
- composer require dunglas/symfony-lock:${SYMFONY_VERSION} --no-update
- composer require "php-http/guzzle6-adapter:^1.0" --no-update
- composer require symfony/symfony:${SYMFONY_VERSION} --no-update
- composer install --prefer-source

script:
Expand Down
17 changes: 5 additions & 12 deletions src/Payum/Klarna/Checkout/Action/Api/BaseApiAwareAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@

use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Klarna\Checkout\Config;

abstract class BaseApiAwareAction implements ActionInterface, ApiAwareInterface
{
use ApiAwareTrait {
setApi as _setApi;
}

/**
* @deprecated BC. will be removed in 2.x. Use $this->api
*
* @var Config
*/
protected $config;
Expand All @@ -27,19 +21,18 @@ abstract class BaseApiAwareAction implements ActionInterface, ApiAwareInterface
public function __construct(\Klarna_Checkout_ConnectorInterface $connector = null)
{
$this->connector = $connector;

// BC. will be removed in 2.x. Use $this->api
$this->apiClass = Config::class;
}

/**
* {@inheritDoc}
*/
public function setApi($api)
{
$this->_setApi($api);
if (false == $api instanceof Config) {
throw new UnsupportedApiException('Not supported. Expected Payum\Klarna\Checkout\Config instance to be set as api.');
}

$this->config = $this->api;
$this->config = $api;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Payum/Klarna/Checkout/Action/Api/CreateOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function execute($request)

$this->addMerchantId($model);

$this->callWithRetry(function () use ($model, $request) {
$this->callWithRetry(function() use ($model, $request) {
$order = new \Klarna_Checkout_Order($this->getConnector());
$order->create($model->toUnsafeArray());

Expand Down
2 changes: 1 addition & 1 deletion src/Payum/Klarna/Checkout/Action/Api/FetchOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function execute($request)
throw new LogicException('Location has to be provided to fetch an order');
}

$this->callWithRetry(function () use ($model, $request) {
$this->callWithRetry(function() use ($model, $request) {
$order = new \Klarna_Checkout_Order($this->getConnector(), $model['location']);
$order->fetch();

Expand Down
2 changes: 1 addition & 1 deletion src/Payum/Klarna/Checkout/Action/Api/UpdateOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function execute($request)

$model = ArrayObject::ensureArrayObject($request->getModel());

$this->callWithRetry(function () use ($model, $request) {
$this->callWithRetry(function() use ($model, $request) {
$order = new \Klarna_Checkout_Order($this->getConnector(), $model['location']);

$data = $model->toUnsafeArray();
Expand Down
2 changes: 1 addition & 1 deletion src/Payum/Klarna/Checkout/Action/AuthorizeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function execute($request)

if (Constants::STATUS_CHECKOUT_INCOMPLETE == $model['status']) {
$renderTemplate = new RenderTemplate($this->templateName, array(
'snippet' => isset($model['gui']['snippet']) ? $model['gui']['snippet'] : null,
'snippet' => $model['gui']['snippet'],
));
$this->gateway->execute($renderTemplate);

Expand Down
51 changes: 17 additions & 34 deletions src/Payum/Klarna/Checkout/Action/AuthorizeRecurringAction.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,33 @@
<?php
namespace Payum\Klarna\Checkout\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Core\Request\Authorize;
use Payum\Klarna\Checkout\Config;
use Payum\Klarna\Checkout\Constants;
use Payum\Klarna\Checkout\Request\Api\CreateOrder;

/**
* @param Config $api
* @param Config $config
*/
class AuthorizeRecurringAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface
class AuthorizeRecurringAction extends GatewayAwareAction implements ApiAwareInterface
{
use ApiAwareTrait {
setApi as _setApi;
}
use GatewayAwareTrait;

/**
* @deprecated BC. will be removed in 2.x. Use $this->api
*
* @var Config
*/
protected $config;

public function __construct()
{
$this->apiClass = Config::class;
}

/**
* {@inheritDoc}
*/
public function setApi($api)
{
$this->_setApi($api);
if (false == $api instanceof Config) {
throw new UnsupportedApiException('Not supported. Expected Payum\Klarna\Checkout\Config instance to be set as api.');
}

// BC. will be removed in 2.x. Use $this->api
$this->config = $this->api;
$this->config = $api;
}

/**
Expand All @@ -64,7 +47,7 @@ public function execute($request)

$model['activate'] = false;

$backupConfig = clone $this->api;
$backupConfig = clone $this->config;

$token = $model['recurring_token'];

Expand All @@ -76,17 +59,17 @@ public function execute($request)
Constants::BASE_URI_RECURRING_SANDBOX
;

$this->api->contentType = Constants::CONTENT_TYPE_RECURRING_ORDER_V1;
$this->api->acceptHeader = Constants::ACCEPT_HEADER_RECURRING_ORDER_ACCEPTED_V1;
$this->api->baseUri = str_replace('{recurring_token}', $token, $baseUri);
$this->config->contentType = Constants::CONTENT_TYPE_RECURRING_ORDER_V1;
$this->config->acceptHeader = Constants::ACCEPT_HEADER_RECURRING_ORDER_ACCEPTED_V1;
$this->config->baseUri = str_replace('{recurring_token}', $token, $baseUri);

$this->gateway->execute($createOrderRequest = new CreateOrder($model));

$model->replace($createOrderRequest->getOrder()->marshal());
} catch (\Exception $e) {
$this->api->contentType = $backupConfig->contentType;
$this->api->acceptHeader = $backupConfig->acceptHeader;
$this->api->baseUri = $backupConfig->baseUri;
$this->config->contentType = $backupConfig->contentType;
$this->config->acceptHeader = $backupConfig->acceptHeader;
$this->config->baseUri = $backupConfig->baseUri;

$model['recurring_token'] = $token;

Expand All @@ -95,9 +78,9 @@ public function execute($request)

$model['recurring_token'] = $token;

$this->api->contentType = $backupConfig->contentType;
$this->api->acceptHeader = $backupConfig->acceptHeader;
$this->api->baseUri = $backupConfig->baseUri;
$this->config->contentType = $backupConfig->contentType;
$this->config->acceptHeader = $backupConfig->acceptHeader;
$this->config->baseUri = $backupConfig->baseUri;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Payum/Klarna/Checkout/Action/ConvertPaymentAction.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
namespace Payum\Klarna\Checkout\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Model\PaymentInterface;
use Payum\Core\Request\Convert;

class ConvertPaymentAction implements ActionInterface
class ConvertPaymentAction extends GatewayAwareAction
{
/**
* {@inheritDoc}
Expand Down
8 changes: 2 additions & 6 deletions src/Payum/Klarna/Checkout/Action/NotifyAction.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?php
namespace Payum\Klarna\Checkout\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\Request\Notify;
use Payum\Core\Request\Sync;
use Payum\Klarna\Checkout\Constants;
use Payum\Klarna\Checkout\Request\Api\UpdateOrder;

class NotifyAction implements ActionInterface, GatewayAwareInterface
class NotifyAction extends GatewayAwareAction
{
use GatewayAwareTrait;

/**
* {@inheritDoc}
*
Expand Down
8 changes: 2 additions & 6 deletions src/Payum/Klarna/Checkout/Action/SyncAction.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<?php
namespace Payum\Klarna\Checkout\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Action\GatewayAwareAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayAwareTrait;
use Payum\Core\Request\Sync;
use Payum\Klarna\Checkout\Request\Api\FetchOrder;

class SyncAction implements ActionInterface, GatewayAwareInterface
class SyncAction extends GatewayAwareAction
{
use GatewayAwareTrait;

/**
* {@inheritDoc}
*
Expand Down