|
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\Authorize; |
|
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 AuthorizePaymentAction extends GatewayAwareAction |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var PaymentDescriptionProviderInterface */ |
|
30
|
|
|
private $paymentDescriptionProvider; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(PaymentDescriptionProviderInterface $paymentDescriptionProvider) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->paymentDescriptionProvider = $paymentDescriptionProvider; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
* |
|
40
|
|
|
* @param Authorize $request |
|
41
|
|
|
*/ |
|
42
|
|
|
public function execute($request): void |
|
43
|
|
|
{ |
|
44
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
|
45
|
|
|
/** @var SyliusPaymentInterface $payment */ |
|
46
|
|
|
$payment = $request->getModel(); |
|
47
|
|
|
/** @var OrderInterface $order */ |
|
48
|
|
|
$order = $payment->getOrder(); |
|
49
|
|
|
$this->gateway->execute($status = new GetStatus($payment)); |
|
50
|
|
|
if ($status->isNew()) { |
|
51
|
|
|
try { |
|
52
|
|
|
$this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken())); |
|
53
|
|
|
$payment->setDetails($convert->getResult()); |
|
54
|
|
|
} catch (RequestNotSupportedException $e) { |
|
|
|
|
|
|
55
|
|
|
$payumPayment = new PayumPayment(); |
|
56
|
|
|
$payumPayment->setNumber($order->getNumber()); |
|
57
|
|
|
$payumPayment->setTotalAmount($payment->getAmount()); |
|
58
|
|
|
$payumPayment->setCurrencyCode($order->getCurrencyCode()); |
|
59
|
|
|
$payumPayment->setClientEmail($order->getCustomer()->getEmail()); |
|
60
|
|
|
$payumPayment->setClientId($order->getCustomer()->getId()); |
|
61
|
|
|
$payumPayment->setDescription($this->paymentDescriptionProvider->getPaymentDescription($payment)); |
|
62
|
|
|
$payumPayment->setDetails($payment->getDetails()); |
|
63
|
|
|
$this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken())); |
|
64
|
|
|
$payment->setDetails($convert->getResult()); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
$details = ArrayObject::ensureArrayObject($payment->getDetails()); |
|
68
|
|
|
|
|
69
|
|
|
try { |
|
70
|
|
|
$request->setModel($details); |
|
71
|
|
|
$this->gateway->execute($request); |
|
72
|
|
|
} finally { |
|
73
|
|
|
$payment->setDetails((array) $details); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
public function supports($request): bool |
|
81
|
|
|
{ |
|
82
|
|
|
return |
|
83
|
|
|
$request instanceof Authorize && |
|
|
|
|
|
|
84
|
|
|
$request->getModel() instanceof SyliusPaymentInterface; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.