These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Sylius\Bundle\PayumBundle\Action; |
||
15 | |||
16 | use Payum\Core\Action\GatewayAwareAction; |
||
17 | use Payum\Core\Bridge\Spl\ArrayObject; |
||
18 | use Payum\Core\Exception\RequestNotSupportedException; |
||
19 | use Payum\Core\Model\Payment as PayumPayment; |
||
20 | use Payum\Core\Request\Capture; |
||
21 | use Payum\Core\Request\Convert; |
||
22 | use Sylius\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface; |
||
23 | use Sylius\Bundle\PayumBundle\Request\GetStatus; |
||
24 | use Sylius\Component\Core\Model\OrderInterface; |
||
25 | use Sylius\Component\Core\Model\PaymentInterface as SyliusPaymentInterface; |
||
26 | |||
27 | final class CapturePaymentAction extends GatewayAwareAction |
||
0 ignored issues
–
show
|
|||
28 | { |
||
29 | /** |
||
30 | * @var PaymentDescriptionProviderInterface |
||
31 | */ |
||
32 | private $paymentDescriptionProvider; |
||
33 | |||
34 | /** |
||
35 | * @param PaymentDescriptionProviderInterface $paymentDescriptionProvider |
||
36 | */ |
||
37 | public function __construct(PaymentDescriptionProviderInterface $paymentDescriptionProvider) |
||
38 | { |
||
39 | $this->paymentDescriptionProvider = $paymentDescriptionProvider; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | * |
||
45 | * @param Capture $request |
||
46 | */ |
||
47 | public function execute($request): void |
||
48 | { |
||
49 | RequestNotSupportedException::assertSupports($this, $request); |
||
50 | |||
51 | /** @var SyliusPaymentInterface $payment */ |
||
52 | $payment = $request->getModel(); |
||
53 | |||
54 | /** @var OrderInterface $order */ |
||
55 | $order = $payment->getOrder(); |
||
56 | |||
57 | $this->gateway->execute($status = new GetStatus($payment)); |
||
58 | if ($status->isNew()) { |
||
59 | try { |
||
60 | $this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken())); |
||
61 | $payment->setDetails($convert->getResult()); |
||
62 | } catch (RequestNotSupportedException $e) { |
||
63 | $totalAmount = $order->getTotal(); |
||
64 | $payumPayment = new PayumPayment(); |
||
65 | $payumPayment->setNumber($order->getNumber()); |
||
66 | $payumPayment->setTotalAmount($totalAmount); |
||
67 | $payumPayment->setCurrencyCode($order->getCurrencyCode()); |
||
68 | $payumPayment->setClientEmail($order->getCustomer()->getEmail()); |
||
69 | $payumPayment->setClientId($order->getCustomer()->getId()); |
||
70 | $payumPayment->setDescription($this->paymentDescriptionProvider->getPaymentDescription($payment)); |
||
71 | $payumPayment->setDetails($payment->getDetails()); |
||
72 | |||
73 | $this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken())); |
||
74 | $payment->setDetails($convert->getResult()); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | $details = ArrayObject::ensureArrayObject($payment->getDetails()); |
||
79 | |||
80 | try { |
||
81 | $request->setModel($details); |
||
82 | $this->gateway->execute($request); |
||
83 | } finally { |
||
84 | $payment->setDetails((array) $details); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function supports($request): bool |
||
92 | { |
||
93 | return |
||
94 | $request instanceof Capture && |
||
95 | $request->getModel() instanceof SyliusPaymentInterface |
||
96 | ; |
||
97 | } |
||
98 | } |
||
99 |
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.