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\CommonSdk\Entity\EntityAbstract; |
19
|
|
|
use Gpupo\CommonSdk\Entity\EntityInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @method Gpupo\AdyenSdk\Payment\Request\Order\Order getOrder() Acesso a order |
23
|
|
|
* @method setOrder(Gpupo\AdyenSdk\Payment\Request\Order\Order $order) Define order |
24
|
|
|
* @method string getType() Acesso a type |
25
|
|
|
* @method setType(string $type) Define type |
26
|
|
|
* @method string getEncryptedData() Acesso a encryptedData |
27
|
|
|
* @method setEncryptedData(string $encryptedData) Define encryptedData |
28
|
|
|
* @method string getMerchantAccount() Acesso a merchantAccount |
29
|
|
|
* @method setMerchantAccount(string $merchantAccount) Define merchantAccount |
30
|
|
|
*/ |
31
|
|
|
class Request extends EntityAbstract implements EntityInterface |
32
|
|
|
{ |
33
|
9 |
|
public function getSchema() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
9 |
|
'order' => 'object', |
37
|
|
|
'type' => 'string', |
38
|
|
|
'encryptedData' => 'string', |
39
|
|
|
'merchantAccount' => 'string', |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
6 |
|
public function getDecoratorName() |
44
|
|
|
{ |
45
|
|
|
$dict = [ |
46
|
6 |
|
'credit-cart' => 'CreditCardDecorator', |
47
|
|
|
'cc' => 'CreditCardDecorator', |
48
|
|
|
'capture' => 'CaptureDecorator', |
49
|
|
|
'boleto' => 'BoletoDecorator', |
50
|
|
|
'refund' => 'RefundDecorator', |
51
|
|
|
'cancelOrRefund' => 'CancelOrRefundDecorator', |
52
|
|
|
]; |
53
|
|
|
|
54
|
6 |
|
if (!array_key_exists($this->getType(), $dict)) { |
55
|
|
|
throw new \InvalidArgumentException('Request type ['.$this->getType().']not exist!'); |
56
|
|
|
} |
57
|
|
|
|
58
|
6 |
|
return $dict[$this->getType()]; |
59
|
|
|
} |
60
|
|
|
|
61
|
6 |
|
protected function resolveDecorator() |
62
|
|
|
{ |
63
|
6 |
|
$className = Factory::PACKAGENAME |
64
|
6 |
|
.'Payment\Request\Decorator\\'.$this->getDecoratorName(); |
65
|
|
|
|
66
|
6 |
|
if (!class_exists($className)) { |
67
|
|
|
throw new \InvalidArgumentException('Request type ['.$className.'] not supported!'); |
68
|
|
|
} |
69
|
|
|
|
70
|
6 |
|
return $className; |
71
|
|
|
} |
72
|
|
|
|
73
|
6 |
|
public function toJson($route = null, $options = 0, $depth = 512) |
74
|
|
|
{ |
75
|
6 |
|
$decorator = $this->resolveDecorator(); |
76
|
6 |
|
$instance = new $decorator(); |
77
|
6 |
|
$instance->setRequest($this); |
78
|
|
|
|
79
|
6 |
|
return $instance->toJson(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|