1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PH\Bundle\PayumBundle\Action; |
6
|
|
|
|
7
|
|
|
use Payum\Core\Action\GatewayAwareAction; |
8
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
9
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
10
|
|
|
use Payum\Core\Model\Payment as PayumPayment; |
11
|
|
|
use Payum\Core\Request\Capture; |
12
|
|
|
use Payum\Core\Request\Convert; |
13
|
|
|
use PH\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface; |
14
|
|
|
use PH\Component\Core\Model\SubscriptionInterface; |
15
|
|
|
use PH\Component\Core\Model\PaymentInterface; |
16
|
|
|
use Sylius\Bundle\PayumBundle\Request\GetStatus; |
17
|
|
|
|
18
|
|
|
final class CapturePaymentAction extends GatewayAwareAction |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var PaymentDescriptionProviderInterface |
22
|
|
|
*/ |
23
|
|
|
private $descriptionProvider; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* CapturePaymentAction constructor. |
27
|
|
|
* |
28
|
|
|
* @param PaymentDescriptionProviderInterface $descriptionProvider |
29
|
|
|
*/ |
30
|
|
|
public function __construct(PaymentDescriptionProviderInterface $descriptionProvider) |
31
|
|
|
{ |
32
|
|
|
$this->descriptionProvider = $descriptionProvider; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function execute($request) |
39
|
|
|
{ |
40
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
41
|
|
|
|
42
|
|
|
/** @var PaymentInterface $payment */ |
43
|
|
|
$payment = $request->getModel(); |
44
|
|
|
$paymentMethodConfig = $payment->getMethod()->getGatewayConfig()->getConfig(); |
|
|
|
|
45
|
|
|
|
46
|
|
|
/** @var SubscriptionInterface $subscription */ |
47
|
|
|
$subscription = $payment->getSubscription(); |
48
|
|
|
|
49
|
|
|
$this->gateway->execute($status = new GetStatus($payment)); |
50
|
|
|
|
51
|
|
|
if ($status->isNew()) { |
52
|
|
|
try { |
53
|
|
|
$this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken())); |
54
|
|
|
$payment->setDetails($convert->getResult()); |
55
|
|
|
} catch (RequestNotSupportedException $e) { |
56
|
|
|
$totalAmount = $subscription->getTotal(); |
57
|
|
|
$payumPayment = new PayumPayment(); |
58
|
|
|
$payumPayment->setTotalAmount($totalAmount); |
59
|
|
|
$payumPayment->setCurrencyCode($subscription->getCurrencyCode()); |
60
|
|
|
$payumPayment->setDescription($this->descriptionProvider->getPaymentDescription($payment)); |
61
|
|
|
|
62
|
|
|
$startDate = $subscription->getStartDate(); |
63
|
|
|
if (null === $startDate) { |
64
|
|
|
$startDate = new \DateTime(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$details = [ |
68
|
|
|
'interval' => $subscription->getInterval(), |
69
|
|
|
'startDate' => $startDate->format('Y-m-d'), |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
if (isset($paymentMethodConfig['method'])) { |
73
|
|
|
$details['method'] = $paymentMethodConfig['method']; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$details['type'] = $subscription->getType(); |
77
|
|
|
|
78
|
|
|
$payumPayment->setDetails(array_merge($payment->getDetails(), $details)); |
79
|
|
|
$this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken())); |
80
|
|
|
$payment->setDetails($convert->getResult()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$details = ArrayObject::ensureArrayObject($payment->getDetails()); |
85
|
|
|
|
86
|
|
|
try { |
87
|
|
|
$request->setModel($details); |
88
|
|
|
$this->gateway->execute($request); |
89
|
|
|
} finally { |
90
|
|
|
$payment->setDetails((array) $details); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function supports($request) |
98
|
|
|
{ |
99
|
|
|
return |
100
|
|
|
$request instanceof Capture && |
101
|
|
|
$request->getModel() instanceof PaymentInterface |
102
|
|
|
; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.