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
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusPrzelewy24Plugin\Action; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusPrzelewy24Plugin\Bridge\Przelewy24BridgeInterface; |
16
|
|
|
use Payum\Core\Action\ActionInterface; |
17
|
|
|
use Payum\Core\ApiAwareInterface; |
18
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
19
|
|
|
use Payum\Core\Exception\UnsupportedApiException; |
20
|
|
|
use Payum\Core\GatewayAwareInterface; |
21
|
|
|
use Payum\Core\GatewayAwareTrait; |
22
|
|
|
use Payum\Core\Reply\HttpPostRedirect; |
23
|
|
|
use Payum\Core\Request\Capture; |
24
|
|
|
use Payum\Core\Security\GenericTokenFactoryAwareInterface; |
25
|
|
|
use Payum\Core\Security\GenericTokenFactoryInterface; |
26
|
|
|
use Payum\Core\Security\TokenInterface; |
27
|
|
|
|
28
|
|
|
final class CaptureAction implements ActionInterface, ApiAwareInterface, GenericTokenFactoryAwareInterface, GatewayAwareInterface |
29
|
|
|
{ |
30
|
|
|
use GatewayAwareTrait; |
31
|
|
|
|
32
|
|
|
/** @var GenericTokenFactoryInterface */ |
33
|
|
|
private $tokenFactory; |
34
|
|
|
|
35
|
|
|
/** @var Przelewy24BridgeInterface */ |
36
|
|
|
private $przelewy24Bridge; |
37
|
|
|
|
38
|
|
|
public function __construct(Przelewy24BridgeInterface $przelewy24Bridge) |
39
|
|
|
{ |
40
|
|
|
$this->przelewy24Bridge = $przelewy24Bridge; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function setApi($api): void |
44
|
|
|
{ |
45
|
|
|
if (false === is_array($api)) { |
46
|
|
|
throw new UnsupportedApiException('Not supported.Expected to be set as array.'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->przelewy24Bridge->setAuthorizationData($api['merchant_id'], $api['crc_key'], $api['environment']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function setGenericTokenFactory(GenericTokenFactoryInterface $genericTokenFactory = null): void |
53
|
|
|
{ |
54
|
|
|
$this->tokenFactory = $genericTokenFactory; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function execute($request): void |
58
|
|
|
{ |
59
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
60
|
|
|
|
61
|
|
|
$details = $request->getModel(); |
62
|
|
|
|
63
|
|
|
if (isset($details['p24_status'])) { |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** @var TokenInterface $token */ |
68
|
|
|
$token = $request->getToken(); |
69
|
|
|
$details['p24_session_id'] = uniqid(); |
70
|
|
|
$notifyToken = $this->tokenFactory->createNotifyToken($token->getGatewayName(), $token->getDetails()); |
71
|
|
|
$details['p24_url_return'] = $token->getAfterUrl(); |
72
|
|
|
$details['p24_url_cancel'] = $token->getAfterUrl() . '&' . http_build_query(['status' => Przelewy24BridgeInterface::CANCELLED_STATUS]); |
73
|
|
|
$details['p24_wait_for_result'] = '1'; |
74
|
|
|
$details['p24_url_status'] = $notifyToken->getTargetUrl(); |
75
|
|
|
$details['token'] = $this->przelewy24Bridge->trnRegister($details->toUnsafeArray()); |
|
|
|
|
76
|
|
|
$details['p24_status'] = Przelewy24BridgeInterface::CREATED_STATUS; |
77
|
|
|
|
78
|
|
|
throw new HttpPostRedirect( |
79
|
|
|
$this->przelewy24Bridge->getTrnRequestUrl($details['token']) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function supports($request): bool |
84
|
|
|
{ |
85
|
|
|
return |
86
|
|
|
$request instanceof Capture && |
87
|
|
|
$request->getModel() instanceof \ArrayAccess |
88
|
|
|
; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.