1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PayumTW\Ips\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\Ips\Action\Api\BaseApiAwareAction; |
12
|
|
|
use PayumTW\Ips\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['paymentResult']) === true) { |
36
|
1 |
|
$httpRequest->request = $this->api->parseResponse($httpRequest->request); |
37
|
1 |
|
if ($this->api->verifyHash($httpRequest->request) === false) { |
38
|
|
|
$httpRequest->request['RspCode'] = '-1'; |
39
|
|
|
} |
40
|
1 |
|
$details->replace($httpRequest->request); |
41
|
|
|
|
42
|
1 |
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
$token = $request->getToken(); |
46
|
1 |
|
$targetUrl = $token->getTargetUrl(); |
47
|
|
|
|
48
|
1 |
|
if (empty($details['Merchanturl']) === true) { |
49
|
1 |
|
$details['Merchanturl'] = $targetUrl; |
50
|
1 |
|
} |
51
|
|
|
|
52
|
1 |
|
if (empty($details['FailUrl']) === true) { |
53
|
1 |
|
$details['FailUrl'] = $targetUrl; |
54
|
1 |
|
} |
55
|
|
|
|
56
|
1 |
|
if (empty($details['ServerUrl']) === true) { |
57
|
1 |
|
$notifyToken = $this->tokenFactory->createNotifyToken( |
58
|
1 |
|
$token->getGatewayName(), |
59
|
1 |
|
$token->getDetails() |
60
|
1 |
|
); |
61
|
|
|
|
62
|
1 |
|
$details['ServerUrl'] = $notifyToken->getTargetUrl(); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
1 |
|
$this->gateway->execute(new CreateTransaction($details)); |
66
|
2 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
2 |
|
public function supports($request) |
72
|
|
|
{ |
73
|
|
|
return |
74
|
2 |
|
$request instanceof Capture && |
75
|
2 |
|
$request->getModel() instanceof \ArrayAccess; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|