1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PayumTW\Allpay\Action; |
4
|
|
|
|
5
|
|
|
use Payum\Core\Request\Capture; |
6
|
|
|
use Payum\Core\GatewayAwareTrait; |
7
|
|
|
use Payum\Core\GatewayAwareInterface; |
8
|
|
|
use Payum\Core\Action\ActionInterface; |
9
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
10
|
|
|
use Payum\Core\Request\GetHttpRequest; |
11
|
|
|
use PayumTW\Allpay\Action\Api\BaseApiAwareAction; |
12
|
|
|
use PayumTW\Allpay\Request\Api\CreateTransaction; |
13
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
14
|
|
|
use Payum\Core\Security\GenericTokenFactoryAwareTrait; |
15
|
|
|
use Payum\Core\Security\GenericTokenFactoryAwareInterface; |
16
|
|
|
|
17
|
|
|
class CaptureAction extends BaseApiAwareAction implements ActionInterface, GatewayAwareInterface, GenericTokenFactoryAwareInterface |
18
|
|
|
{ |
19
|
|
|
use GatewayAwareTrait; |
20
|
|
|
use GenericTokenFactoryAwareTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
* |
25
|
|
|
* @param Capture $request |
26
|
|
|
*/ |
27
|
2 |
|
public function execute($request) |
28
|
|
|
{ |
29
|
2 |
|
RequestNotSupportedException::assertSupports($this, $request); |
30
|
2 |
|
$details = ArrayObject::ensureArrayObject($request->getModel()); |
31
|
|
|
|
32
|
2 |
|
$httpRequest = new GetHttpRequest(); |
33
|
2 |
|
$this->gateway->execute($httpRequest); |
34
|
|
|
|
35
|
2 |
|
if (isset($httpRequest->request['RtnCode']) === true) { |
36
|
1 |
|
if ($this->api->verifyHash($httpRequest->request) === false) { |
37
|
1 |
|
$httpRequest->request['RtnCode'] = '10400002'; |
38
|
|
|
} |
39
|
1 |
|
$details->replace($httpRequest->request); |
40
|
|
|
|
41
|
1 |
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
$token = $request->getToken(); |
45
|
1 |
|
$targetUrl = $token->getTargetUrl(); |
46
|
|
|
|
47
|
1 |
|
if (empty($details['OrderResultURL']) === true) { |
48
|
1 |
|
$details['OrderResultURL'] = $targetUrl; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
if (empty($details['ReturnURL']) === true) { |
52
|
1 |
|
$notifyToken = $this->tokenFactory->createNotifyToken( |
53
|
1 |
|
$token->getGatewayName(), $token->getDetails() |
54
|
|
|
); |
55
|
|
|
|
56
|
1 |
|
$details['ReturnURL'] = $notifyToken->getTargetUrl(); |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
$this->gateway->execute(new CreateTransaction($details)); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
2 |
|
public function supports($request) |
66
|
|
|
{ |
67
|
|
|
return |
68
|
2 |
|
$request instanceof Capture && |
69
|
2 |
|
$request->getModel() instanceof \ArrayAccess; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|