Completed
Push — master ( f2042d...10cdad )
by Kamil
29:04 queued 13:16
created

ExecuteSameRequestWithPaymentDetailsAction.php (1 issue)

Upgrade to new PHP Analysis Engine

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\Request\Generic;
20
use Sylius\Component\Payment\Model\PaymentInterface;
21
22
final class ExecuteSameRequestWithPaymentDetailsAction extends GatewayAwareAction
0 ignored issues
show
Deprecated Code introduced by
The class Payum\Core\Action\GatewayAwareAction has been deprecated with message: since 1.3 will be removed in 2.0. Use trait+interface in your classes.

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.

Loading history...
23
{
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @param Generic $request
28
     */
29
    public function execute($request): void
30
    {
31
        RequestNotSupportedException::assertSupports($this, $request);
32
33
        /** @var PaymentInterface $payment */
34
        $payment = $request->getModel();
35
        $details = ArrayObject::ensureArrayObject($payment->getDetails());
36
37
        try {
38
            $request->setModel($details);
39
40
            $this->gateway->execute($request);
41
        } finally {
42
            $payment->setDetails((array) $details);
43
        }
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function supports($request): bool
50
    {
51
        return
52
            $request instanceof Generic &&
53
            $request->getModel() instanceof PaymentInterface
54
        ;
55
    }
56
}
57