|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PH\Behat; |
|
6
|
|
|
|
|
7
|
|
|
use PH\Component\Core\Factory\PaymentMethodFactoryInterface; |
|
8
|
|
|
use PH\Component\Core\Model\PaymentMethodInterface; |
|
9
|
|
|
use PH\Component\Core\Repository\PaymentMethodRepositoryInterface; |
|
10
|
|
|
|
|
11
|
|
|
trait PaymentMethodTrait |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var PaymentMethodRepositoryInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
private $paymentMethodRepository; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var PaymentMethodFactoryInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
private $paymentMethodFactory; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
private $gatewayFactories; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* PaymentContext constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param PaymentMethodRepositoryInterface $paymentMethodRepository |
|
32
|
|
|
* @param PaymentMethodFactoryInterface $paymentMethodFactory |
|
33
|
|
|
* @param array $gatewayFactories |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct( |
|
36
|
|
|
PaymentMethodRepositoryInterface $paymentMethodRepository, |
|
37
|
|
|
PaymentMethodFactoryInterface $paymentMethodFactory, |
|
38
|
|
|
array $gatewayFactories |
|
39
|
|
|
) { |
|
40
|
|
|
$this->paymentMethodRepository = $paymentMethodRepository; |
|
41
|
|
|
$this->paymentMethodFactory = $paymentMethodFactory; |
|
42
|
|
|
$this->gatewayFactories = $gatewayFactories; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $name |
|
47
|
|
|
* @param string $code |
|
48
|
|
|
* @param string $gatewayFactory |
|
49
|
|
|
* @param string $description |
|
50
|
|
|
* @param int|null $position |
|
51
|
|
|
* @param array $config |
|
52
|
|
|
* @param bool $supportsRecurring |
|
53
|
|
|
* |
|
54
|
|
|
* @return PaymentMethodInterface |
|
55
|
|
|
*/ |
|
56
|
|
|
public function createPaymentMethod( |
|
57
|
|
|
string $name, |
|
58
|
|
|
string $code, |
|
59
|
|
|
string $gatewayFactory = 'Offline', |
|
60
|
|
|
string $description = '', |
|
61
|
|
|
int $position = null, |
|
62
|
|
|
array $config = [], |
|
63
|
|
|
bool $supportsRecurring = false |
|
64
|
|
|
): PaymentMethodInterface { |
|
65
|
|
|
$gatewayFactory = array_search($gatewayFactory, $this->gatewayFactories); |
|
66
|
|
|
|
|
67
|
|
|
/** @var PaymentMethodInterface $paymentMethod */ |
|
68
|
|
|
$paymentMethod = $this->paymentMethodFactory->createWithGateway($gatewayFactory); |
|
69
|
|
|
$paymentMethod->setName(ucfirst($name)); |
|
70
|
|
|
$paymentMethod->setCode($code); |
|
71
|
|
|
$paymentMethod->setDescription($description); |
|
72
|
|
|
$paymentMethod->setEnabled(true); |
|
73
|
|
|
$paymentMethod->getGatewayConfig()->setGatewayName($gatewayFactory); |
|
74
|
|
|
$paymentMethod->getGatewayConfig()->setConfig($config); |
|
75
|
|
|
|
|
76
|
|
|
if ($supportsRecurring) { |
|
77
|
|
|
$paymentMethod->setSupportsRecurring(true); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if (null !== $position) { |
|
81
|
|
|
$paymentMethod->setPosition($position); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$this->paymentMethodRepository->add($paymentMethod); |
|
85
|
|
|
|
|
86
|
|
|
return $paymentMethod; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|