|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PayumTW\Ecpay\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\Ecpay\Action\Api\BaseApiAwareAction; |
|
12
|
|
|
use PayumTW\Ecpay\Request\Api\CreateTransaction; |
|
13
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
|
14
|
|
|
use Payum\Core\Security\GenericTokenFactoryAwareTrait; |
|
15
|
|
|
use Payum\Core\Security\GenericTokenFactoryAwareInterface; |
|
16
|
|
|
|
|
17
|
|
|
class CaptureLogisticsAction extends BaseApiAwareAction implements ActionInterface, GatewayAwareInterface, GenericTokenFactoryAwareInterface |
|
18
|
|
|
{ |
|
19
|
|
|
use GatewayAwareTrait; |
|
20
|
|
|
use GenericTokenFactoryAwareTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
* |
|
25
|
|
|
* @param Capture $request |
|
26
|
|
|
*/ |
|
27
|
3 |
|
public function execute($request) |
|
28
|
|
|
{ |
|
29
|
3 |
|
RequestNotSupportedException::assertSupports($this, $request); |
|
30
|
3 |
|
$details = ArrayObject::ensureArrayObject($request->getModel()); |
|
31
|
|
|
|
|
32
|
3 |
|
$httpRequest = new GetHttpRequest(); |
|
33
|
3 |
|
$this->gateway->execute($httpRequest); |
|
34
|
|
|
|
|
35
|
|
|
// CVS |
|
36
|
3 |
|
if (isset($httpRequest->request['CVSStoreID']) === true || |
|
37
|
2 |
|
isset($httpRequest->request['RtnCode']) === true || |
|
38
|
2 |
|
isset($httpRequest->request['ResCode']) === true || |
|
39
|
2 |
|
isset($httpRequest->request['RtnMerchantTradeNo']) === true && isset($httpRequest->request['RtnOrderNo']) === true || |
|
40
|
2 |
|
isset($httpRequest->request['CVSStoreID']) === true || |
|
41
|
2 |
|
isset($httpRequest->request['ErrorMessage']) === true |
|
42
|
3 |
|
) { |
|
43
|
1 |
|
$details->replace($httpRequest->request); |
|
44
|
|
|
|
|
45
|
1 |
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
2 |
|
$token = $request->getToken(); |
|
49
|
2 |
|
$targetUrl = $token->getTargetUrl(); |
|
50
|
|
|
|
|
51
|
2 |
|
if (empty($details['GoodsAmount']) === true) { |
|
52
|
1 |
|
if (empty($details['ServerReplyURL']) === true) { |
|
53
|
1 |
|
$details['ServerReplyURL'] = $targetUrl; |
|
54
|
1 |
|
} |
|
55
|
1 |
|
$this->gateway->execute(new CreateTransaction($details)); |
|
56
|
|
|
|
|
57
|
1 |
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
View Code Duplication |
if (empty($details['ServerReplyURL']) === true) { |
|
61
|
1 |
|
$notifyToken = $this->tokenFactory->createNotifyToken( |
|
62
|
1 |
|
$token->getGatewayName(), $token->getDetails() |
|
63
|
1 |
|
); |
|
64
|
1 |
|
$details['ServerReplyURL'] = $notifyToken->getTargetUrl(); |
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
if (empty($details['LogisticsC2CReplyURL']) === true) { |
|
68
|
1 |
|
$details['LogisticsC2CReplyURL'] = $details['ServerReplyURL']; |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
if (empty($details['ClientReplyURL']) === true) { |
|
72
|
1 |
|
$details['ClientReplyURL'] = $targetUrl; |
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
$this->gateway->execute(new CreateTransaction($details)); |
|
76
|
1 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
3 |
|
public function supports($request) |
|
82
|
|
|
{ |
|
83
|
|
|
return |
|
84
|
3 |
|
$request instanceof Capture && |
|
85
|
3 |
|
$request->getModel() instanceof \ArrayAccess; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|