|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/adyen-sdk |
|
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
|
6
|
|
|
* For the information of copyright and license you should read the file |
|
7
|
|
|
* LICENSE which is distributed with this source code. |
|
8
|
|
|
* Para a informação dos direitos autorais e de licença você deve ler o arquivo |
|
9
|
|
|
* LICENSE que é distribuído com este código-fonte. |
|
10
|
|
|
* Para obtener la información de los derechos de autor y la licencia debe leer |
|
11
|
|
|
* el archivo LICENSE que se distribuye con el código fuente. |
|
12
|
|
|
* For more information, see <https://opensource.gpupo.com/>. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Gpupo\AdyenSdk\Payment\Request; |
|
16
|
|
|
|
|
17
|
|
|
use Gpupo\AdyenSdk\Factory; |
|
18
|
|
|
use Gpupo\AdyenSdk\Payment\Response\Decorator\ErrorDecorator; |
|
19
|
|
|
use Gpupo\AdyenSdk\Payment\Response\Decorator\ProblematicDecorator; |
|
20
|
|
|
use Gpupo\Common\Interfaces\OptionsInterface; |
|
21
|
|
|
use Gpupo\Common\Traits\OptionsTrait; |
|
22
|
|
|
use Gpupo\CommonSdk\Entity\EntityInterface; |
|
23
|
|
|
use Gpupo\CommonSdk\Entity\ManagerAbstract; |
|
24
|
|
|
use Gpupo\CommonSdk\Response; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Gerenciamento de Transações Adyen. |
|
28
|
|
|
*/ |
|
29
|
|
|
class Manager extends ManagerAbstract implements OptionsInterface |
|
30
|
|
|
{ |
|
31
|
|
|
use OptionsTrait; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @internal |
|
35
|
|
|
*/ |
|
36
|
|
|
public function update(EntityInterface $entity, EntityInterface $existent) |
|
37
|
|
|
{ |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected $entity = 'Request'; |
|
41
|
|
|
|
|
42
|
|
|
protected $maps = [ |
|
43
|
|
|
'submit' => ['POST', '/authorise'], |
|
44
|
|
|
'capture' => ['POST', '/capture'], |
|
45
|
|
|
'refund' => ['POST', '/refund'], |
|
46
|
|
|
'cancelOrRefund' => ['POST', '/cancelOrRefund'], |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
6 |
|
protected function preExecute(Request $request) |
|
50
|
|
|
{ |
|
51
|
6 |
|
$request->setMerchantAccount($this->getOptions()->get('merchant_account')); |
|
52
|
|
|
|
|
53
|
6 |
|
return $request; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
6 |
|
protected function call(Request $request, $route) |
|
57
|
|
|
{ |
|
58
|
6 |
|
$response = $this->execute($this->factoryMap($route), $request->toJson()); |
|
59
|
|
|
|
|
60
|
6 |
|
return $this->processExecute($request, $response); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
6 |
|
public function blow(Request $request, $route) |
|
64
|
|
|
{ |
|
65
|
6 |
|
$request = $this->preExecute($request); |
|
66
|
|
|
try { |
|
67
|
6 |
|
return $this->call($request, $route); |
|
68
|
|
|
} catch (\Exception $exception) { |
|
69
|
|
|
return new ErrorDecorator($exception); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
3 |
|
public function submit(Request $request) |
|
74
|
|
|
{ |
|
75
|
3 |
|
return $this->blow($request, 'submit'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
public function capture(Request $request) |
|
79
|
|
|
{ |
|
80
|
1 |
|
$request->setType('capture'); |
|
81
|
|
|
|
|
82
|
1 |
|
return $this->blow($request, 'capture'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
1 |
|
public function refund(Request $request, $modificationValue) |
|
86
|
|
|
{ |
|
87
|
1 |
|
$request->setType('refund'); |
|
88
|
1 |
|
$request->getOrder()->setModificationValue($modificationValue); |
|
89
|
|
|
|
|
90
|
1 |
|
return $this->blow($request, 'refund'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
public function cancelOrRefund(Request $request) |
|
94
|
|
|
{ |
|
95
|
1 |
|
$request->setType('cancelOrRefund'); |
|
96
|
|
|
|
|
97
|
1 |
|
return $this->blow($request, 'cancelOrRefund'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
6 |
|
protected function processExecute(Request $request, Response $response) |
|
101
|
|
|
{ |
|
102
|
6 |
|
if (300 > $response->getHttpStatusCode()) { |
|
103
|
5 |
|
$decorator = $this->resolveDecorator($request); |
|
104
|
|
|
} else { |
|
105
|
1 |
|
$decorator = $this->getFullyQualifiedDecoratorName('ProblematicDecorator'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
6 |
|
$data = $response->getData()->toArray(); |
|
109
|
6 |
|
$instance = new $decorator($data); |
|
110
|
6 |
|
$instance->setCode($response->getHttpStatusCode()); |
|
111
|
|
|
|
|
112
|
6 |
|
return $instance; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
6 |
|
protected function getFullyQualifiedDecoratorName($name) |
|
116
|
|
|
{ |
|
117
|
6 |
|
return Factory::PACKAGENAME.'Payment\Response\Decorator\\'.$name; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
5 |
|
protected function resolveDecorator(Request $request) |
|
121
|
|
|
{ |
|
122
|
5 |
|
$className = $this->getFullyQualifiedDecoratorName($request->getDecoratorName()); |
|
123
|
|
|
|
|
124
|
5 |
|
if (!class_exists($className)) { |
|
125
|
|
|
throw new \InvalidArgumentException('Response type ['.$request->getType().'] not supported!'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
5 |
|
return $className; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: