-
Notifications
You must be signed in to change notification settings - Fork 2
/
KlarnaCheckoutGatewayFactory.php
84 lines (71 loc) · 3.3 KB
/
KlarnaCheckoutGatewayFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Payum\Klarna\Checkout;
use Klarna_Checkout_Order;
use LogicException;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory;
use Payum\Klarna\Checkout\Action\Api\CreateOrderAction;
use Payum\Klarna\Checkout\Action\Api\FetchOrderAction;
use Payum\Klarna\Checkout\Action\Api\UpdateOrderAction;
use Payum\Klarna\Checkout\Action\AuthorizeAction;
use Payum\Klarna\Checkout\Action\AuthorizeRecurringAction;
use Payum\Klarna\Checkout\Action\ConvertPaymentAction;
use Payum\Klarna\Checkout\Action\NotifyAction;
use Payum\Klarna\Checkout\Action\StatusAction;
use Payum\Klarna\Checkout\Action\SyncAction;
class KlarnaCheckoutGatewayFactory extends GatewayFactory
{
protected function populateConfig(ArrayObject $config): void
{
if (! class_exists(Klarna_Checkout_Order::class)) {
throw new LogicException('You must install "klarna/checkout" library.');
}
$config->defaults([
'payum.factory_name' => 'klarna_checkout',
'payum.factory_title' => 'Klarna Checkout',
'payum.template.authorize' => '@PayumKlarnaCheckout/Action/capture.html.twig',
'contentType' => Constants::CONTENT_TYPE_AGGREGATED_ORDER_V2,
'sandbox' => true,
]);
$config->defaults([
'payum.action.authorize_recurring' => new AuthorizeRecurringAction(),
// must be before authorize.
'payum.action.authorize' => new AuthorizeAction($config['payum.template.authorize']),
'payum.action.notify' => new NotifyAction(),
'payum.action.status' => new StatusAction(),
'payum.action.sync' => new SyncAction(),
'payum.action.convert_payment' => new ConvertPaymentAction(),
'payum.action.api.create_order' => new CreateOrderAction(),
'payum.action.api.update_order' => new UpdateOrderAction(),
'payum.action.api.fetch_order' => new FetchOrderAction(),
]);
if (! $config['payum.api']) {
$config['payum.default_options'] = [
'merchant_id' => '',
'secret' => '',
'terms_uri' => '',
'checkout_uri' => '',
'sandbox' => true,
];
$config->defaults($config['payum.default_options']);
$config['payum.required_options'] = ['merchant_id', 'secret'];
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);
$klarnaConfig = new Config();
$klarnaConfig->merchantId = $config['merchant_id'];
$klarnaConfig->secret = $config['secret'];
$klarnaConfig->contentType = $config['contentType'];
$klarnaConfig->termsUri = $config['termsUri'] ?: $config['terms_uri'];
$klarnaConfig->checkoutUri = $config['checkoutUri'] ?: $config['checkout_uri'];
$klarnaConfig->baseUri = $config['sandbox'] ?
Constants::BASE_URI_SANDBOX :
Constants::BASE_URI_LIVE
;
return $klarnaConfig;
};
}
$config['payum.paths'] = array_replace([
'PayumKlarnaCheckout' => __DIR__ . '/Resources/views',
], $config['payum.paths'] ?: []);
}
}