-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKlarnaCOGatewayFactory.php
executable file
·86 lines (73 loc) · 3.45 KB
/
KlarnaCOGatewayFactory.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
85
86
<?php
namespace Pringuin\Payum\KlarnaCO;
use Klarna\Rest\Transport\ConnectorInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory;
use Pringuin\Payum\KlarnaCO\Action\Api\AckOrderAction;
use Pringuin\Payum\KlarnaCO\Action\Api\CaptureOrderAction;
use Pringuin\Payum\KlarnaCO\Action\Api\CreateOrderAction;
use Pringuin\Payum\KlarnaCO\Action\Api\FetchOrderAction;
use Pringuin\Payum\KlarnaCO\Action\Api\FetchOrderManagementOrderAction;
use Pringuin\Payum\KlarnaCO\Action\Api\UpdateOrderAction;
use Pringuin\Payum\KlarnaCO\Action\AuthorizeAction;
use Pringuin\Payum\KlarnaCO\Action\ConvertPaymentAction;
use Pringuin\Payum\KlarnaCO\Action\NotifyAction;
use Pringuin\Payum\KlarnaCO\Action\StatusAction;
use Pringuin\Payum\KlarnaCO\Action\SyncAction;
class KlarnaCOGatewayFactory extends GatewayFactory
{
/**
* {@inheritDoc}
*/
protected function populateConfig(ArrayObject $config)
{
if (!class_exists('\Klarna\Rest\Transport\Connector')) {
throw new \LogicException('You must install "klarna/kco_rest" library.');
}
$config->defaults(array(
'payum.factory_name' => 'klarna_co',
'payum.factory_title' => 'Klarna CO',
'payum.template.authorize' => '@PayumKlarnaCO/Action/capture.html.twig',
'sandbox' => true,
));
$config->defaults(array(
'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(),
'payum.action.api.ack_order' => new AckOrderAction(),
'payum.action.api.capture_order' => new CaptureOrderAction(),
'payum.action.api_order_management.fetch_order' => new FetchOrderManagementOrderAction(),
));
if (false == $config['payum.api']) {
$config['payum.default_options'] = array(
'merchant_id' => '',
'secret' => '',
'terms_uri' => '',
'checkout_uri' => '',
'sandbox' => true,
);
$config->defaults($config['payum.default_options']);
$config['payum.required_options'] = array('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->termsUri = $config['termsUri'] ?: $config['terms_uri'];
$klarnaConfig->checkoutUri = $config['checkoutUri'] ?: $config['checkout_uri'];
$klarnaConfig->baseUri = $config['sandbox'] ?
ConnectorInterface::EU_TEST_BASE_URL :
ConnectorInterface::EU_BASE_URL;
return $klarnaConfig;
};
}
$config['payum.paths'] = array_replace([
'PayumKlarnaCO' => __DIR__.'/Resources/views',
], $config['payum.paths'] ?: []);
}
}