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