1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusBraintreePlugin; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusBraintreePlugin\Action\Api\DoSaleAction; |
16
|
|
|
use BitBag\SyliusBraintreePlugin\Action\Api\FindPaymentMethodNonceAction; |
17
|
|
|
use BitBag\SyliusBraintreePlugin\Action\Api\GenerateClientTokenAction; |
18
|
|
|
use BitBag\SyliusBraintreePlugin\Action\CaptureAction; |
19
|
|
|
use BitBag\SyliusBraintreePlugin\Action\ConvertPaymentAction; |
20
|
|
|
use BitBag\SyliusBraintreePlugin\Action\ObtainCardholderAuthenticationAction; |
21
|
|
|
use BitBag\SyliusBraintreePlugin\Action\ObtainPaymentMethodNonceAction; |
22
|
|
|
use BitBag\SyliusBraintreePlugin\Action\PurchaseAction; |
23
|
|
|
use BitBag\SyliusBraintreePlugin\Action\StatusAction; |
24
|
|
|
use BitBag\SyliusBraintreePlugin\ApiClient\BraintreeApiClientInterface; |
25
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
26
|
|
|
use Payum\Core\GatewayFactory; |
27
|
|
|
|
28
|
|
|
final class BraintreeGatewayFactory extends GatewayFactory |
29
|
|
|
{ |
30
|
|
|
public const FACTORY_NAME = 'braintree'; |
31
|
|
|
|
32
|
|
|
protected function populateConfig(ArrayObject $config) |
33
|
|
|
{ |
34
|
|
|
$config->defaults([ |
35
|
|
|
'payum.factory_name' => self::FACTORY_NAME, |
36
|
|
|
'payum.factory_title' => 'braintree', |
37
|
|
|
|
38
|
|
|
'payum.http_client' => '@bitbag_sylius_braintree_plugin.api_client.braintree', |
39
|
|
|
|
40
|
|
|
'payum.template.obtain_payment_method_nonce' => '@BitBagSyliusBraintreePlugin/Action/obtain_payment_method_nonce.html.twig', |
41
|
|
|
'payum.template.obtain_cardholder_authentication' => '@BitBagSyliusBraintreePlugin/Action/obtain_cardholder_authentication.html.twig', |
42
|
|
|
|
43
|
|
|
'payum.action.capture' => new CaptureAction(), |
44
|
|
|
|
45
|
|
|
'payum.action.purchase' => function (ArrayObject $config) { |
46
|
|
|
$action = new PurchaseAction(); |
47
|
|
|
$action->setCardholderAuthenticationRequired($config['cardholderAuthenticationRequired']); |
48
|
|
|
|
49
|
|
|
return $action; |
50
|
|
|
}, |
51
|
|
|
|
52
|
|
|
'payum.action.convert_payment' => new ConvertPaymentAction(), |
53
|
|
|
|
54
|
|
|
'payum.action.obtain_payment_method_nonce' => function (ArrayObject $config) { |
55
|
|
|
$action = new ObtainPaymentMethodNonceAction($config['payum.template.obtain_payment_method_nonce']); |
56
|
|
|
$action->setCardholderAuthenticationRequired($config['cardholderAuthenticationRequired']); |
57
|
|
|
|
58
|
|
|
return $action; |
59
|
|
|
}, |
60
|
|
|
|
61
|
|
|
'payum.action.obtain_cardholder_authentication' => function (ArrayObject $config) { |
62
|
|
|
return new ObtainCardholderAuthenticationAction($config['payum.template.obtain_cardholder_authentication']); |
63
|
|
|
}, |
64
|
|
|
|
65
|
|
|
'payum.action.status' => new StatusAction(), |
66
|
|
|
|
67
|
|
|
'payum.action.api.generate_client_token' => new GenerateClientTokenAction(), |
68
|
|
|
'payum.action.api.find_payment_method_nonce' => new FindPaymentMethodNonceAction(), |
69
|
|
|
'payum.action.api.do_sale' => new DoSaleAction(), |
70
|
|
|
|
71
|
|
|
'cardholderAuthenticationRequired' => true, |
72
|
|
|
]); |
73
|
|
|
|
74
|
|
|
if (false == $config['payum.api']) { |
75
|
|
|
$config['payum.default_options'] = [ |
76
|
|
|
'sandbox' => true, |
77
|
|
|
'storeInVault' => null, |
78
|
|
|
'storeInVaultOnSuccess' => null, |
79
|
|
|
'storeShippingAddressInVault' => null, |
80
|
|
|
'addBillingAddressToPaymentMethod' => null, |
81
|
|
|
]; |
82
|
|
|
$config->defaults($config['payum.default_options']); |
83
|
|
|
$config['payum.required_options'] = []; |
84
|
|
|
|
85
|
|
|
$config['payum.api'] = function (ArrayObject $config) { |
86
|
|
|
// $config->validateNotEmpty($config['payum.required_options']); |
87
|
|
|
// |
88
|
|
|
// return new Api((array) $config, $config['payum.http_client'], $config['httplug.message_factory']); |
89
|
|
|
|
90
|
|
|
/** @var BraintreeApiClientInterface $apiClient */ |
91
|
|
|
$apiClient = $config['payum.http_client']; |
92
|
|
|
|
93
|
|
|
$apiClient->initialise((array) $config); |
94
|
|
|
|
95
|
|
|
return $apiClient; |
96
|
|
|
}; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$config['payum.paths'] = [ |
100
|
|
|
'PayumBraintree' => __DIR__ . '/Resources/views', |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|