forked from Payum/PaypalRest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaypalRestGatewayFactory.php
58 lines (50 loc) · 2.15 KB
/
PaypalRestGatewayFactory.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
<?php
namespace Payum\Paypal\Rest;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory as CoreGatewayFactory;
use Payum\Core\GatewayFactory;
use Payum\Core\GatewayFactoryInterface;
use Payum\Paypal\Rest\Action\CaptureAction;
use Payum\Paypal\Rest\Action\StatusAction;
use Payum\Paypal\Rest\Action\SyncAction;
use Payum\Core\Exception\InvalidArgumentException;
class PaypalRestGatewayFactory extends GatewayFactory
{
/**
* {@inheritDoc}
*/
protected function populateConfig(ArrayObject $config)
{
if (!class_exists('\PayPal\Api\Payment')) {
throw new \LogicException('You must install "paypal/rest-api-sdk-php" library.');
}
$config->defaults(array(
'payum.factory_name' => 'paypal_rest',
'payum.factory_title' => 'PayPal Rest',
'payum.action.capture' => new CaptureAction(),
'payum.action.sync' => new SyncAction(),
'payum.action.status' => new StatusAction(),
));
if (false == $config['payum.api']) {
$config['payum.default_options'] = array(
'client_id' => '',
'client_secret' => '',
'config_path' => '',
);
$config->defaults($config['payum.default_options']);
$config['payum.required_options'] = array('client_id', 'client_secret', 'config_path');
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);
if (!defined('PP_CONFIG_PATH')) {
define('PP_CONFIG_PATH', $config['config_path']);
} elseif (PP_CONFIG_PATH !== $config['config_path']) {
throw new InvalidArgumentException(sprintf('Given "config_path" is invalid. Should be equal to the defined "PP_CONFIG_PATH": %s.', PP_CONFIG_PATH));
}
$credential = new OAuthTokenCredential($config['client_id'], $config['client_secret']);
$config['payum.api'] = new ApiContext($credential);
};
}
}
}