|
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
|
|
|
* You can find more information about us on https://bitbag.io and write us |
|
7
|
|
|
* an email on [email protected]. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace BitBag\SyliusMolliePlugin\Action; |
|
13
|
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Action\Api\BaseApiAwareAction; |
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Payments\PaymentTerms\Options; |
|
16
|
|
|
use BitBag\SyliusMolliePlugin\Request\Api\CreateOrder; |
|
17
|
|
|
use BitBag\SyliusMolliePlugin\Request\Api\CreatePayment; |
|
18
|
|
|
use BitBag\SyliusMolliePlugin\Request\Api\CreateRecurringSubscription; |
|
19
|
|
|
use BitBag\SyliusMolliePlugin\Request\Api\CreateSepaMandate; |
|
20
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
|
21
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
|
22
|
|
|
use Payum\Core\Exception\RuntimeException; |
|
23
|
|
|
use Payum\Core\GatewayAwareTrait; |
|
24
|
|
|
use Payum\Core\Request\Capture; |
|
25
|
|
|
use Payum\Core\Security\GenericTokenFactoryInterface; |
|
26
|
|
|
use Payum\Core\Security\TokenInterface; |
|
27
|
|
|
|
|
28
|
|
|
final class CaptureAction extends BaseApiAwareAction implements CaptureActionInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use GatewayAwareTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** @var GenericTokenFactoryInterface|null */ |
|
33
|
|
|
private $tokenFactory; |
|
34
|
|
|
|
|
35
|
|
|
public function setGenericTokenFactory(GenericTokenFactoryInterface $genericTokenFactory = null): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->tokenFactory = $genericTokenFactory; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** @param Capture $request */ |
|
41
|
|
|
public function execute($request): void |
|
42
|
|
|
{ |
|
43
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
|
44
|
|
|
|
|
45
|
|
|
$details = ArrayObject::ensureArrayObject($request->getModel()); |
|
46
|
|
|
|
|
47
|
|
|
if (true === isset($details['payment_mollie_id']) || |
|
48
|
|
|
true === isset($details['subscription_mollie_id']) || |
|
49
|
|
|
true === isset($details['order_mollie_id'])) { |
|
50
|
|
|
return; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** @var TokenInterface $token */ |
|
54
|
|
|
$token = $request->getToken(); |
|
55
|
|
|
|
|
56
|
|
|
if (null === $this->tokenFactory) { |
|
57
|
|
|
throw new RuntimeException(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$notifyToken = $this->tokenFactory->createNotifyToken($token->getGatewayName(), $token->getDetails()); |
|
61
|
|
|
$refundToken = $this->tokenFactory->createRefundToken($token->getGatewayName(), $token->getDetails()); |
|
62
|
|
|
|
|
63
|
|
|
$details['webhookUrl'] = $notifyToken->getTargetUrl(); |
|
64
|
|
|
$details['backurl'] = $token->getTargetUrl(); |
|
65
|
|
|
|
|
66
|
|
|
if (true === $this->mollieApiClient->isRecurringSubscription()) { |
|
67
|
|
|
$cancelToken = $this->tokenFactory->createToken( |
|
68
|
|
|
$token->getGatewayName(), |
|
69
|
|
|
$token->getDetails(), |
|
70
|
|
|
'bitbag_sylius_mollie_plugin_cancel_subscription_mollie', |
|
71
|
|
|
['orderId' => $details['metadata']['order_id']] |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$details['cancel_token'] = $cancelToken->getHash(); |
|
75
|
|
|
|
|
76
|
|
|
$this->gateway->execute(new CreateSepaMandate($details)); |
|
77
|
|
|
$this->gateway->execute(new CreateRecurringSubscription($details)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if (false === $this->mollieApiClient->isRecurringSubscription()) { |
|
81
|
|
|
$metadata = $details['metadata']; |
|
82
|
|
|
$metadata['refund_token'] = $refundToken->getHash(); |
|
83
|
|
|
$details['metadata'] = $metadata; |
|
84
|
|
|
|
|
85
|
|
|
if (isset($details['metadata']['methodType']) && $details['metadata']['methodType'] === Options::PAYMENT_API) { |
|
86
|
|
|
if (in_array($details['metadata']['molliePaymentMethods'], Options::getOnlyOrderAPIMethods())) { |
|
87
|
|
|
throw new \sprintf('Method %s is not allowed to use %s', |
|
|
|
|
|
|
88
|
|
|
$details['metadata']['molliePaymentMethods'], |
|
89
|
|
|
Options::PAYMENT_API |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$this->gateway->execute(new CreatePayment($details)); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if (isset($details['metadata']['methodType']) && $details['metadata']['methodType'] === Options::ORDER_API) { |
|
97
|
|
|
$this->gateway->execute(new CreateOrder($details)); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function supports($request): bool |
|
103
|
|
|
{ |
|
104
|
|
|
return |
|
105
|
|
|
$request instanceof Capture && |
|
106
|
|
|
$request->getModel() instanceof \ArrayAccess |
|
107
|
|
|
; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths