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\Decorator; |
16
|
|
|
|
17
|
|
|
use Gpupo\AdyenSdk\Payment\Request\Request; |
18
|
|
|
use Gpupo\Common\Entity\CollectionAbstract; |
19
|
|
|
|
20
|
|
|
abstract class AbstractDecorator extends CollectionAbstract |
21
|
|
|
{ |
22
|
|
|
private $request; |
23
|
|
|
|
24
|
|
|
protected $name = 'generic'; |
25
|
|
|
|
26
|
5 |
|
protected function factoryReference() |
27
|
|
|
{ |
28
|
5 |
|
return 'payment-'.$this->name.$this->getOrder()->getId(); |
29
|
|
|
} |
30
|
|
|
|
31
|
8 |
|
public function setRequest(Request $request) |
32
|
|
|
{ |
33
|
8 |
|
$this->request = $request; |
34
|
8 |
|
} |
35
|
|
|
|
36
|
8 |
|
protected function getRequest() |
37
|
|
|
{ |
38
|
8 |
|
if (!$this->request instanceof Request) { |
39
|
|
|
throw new \InvalidArgumentException('Request ausente!'); |
40
|
|
|
} |
41
|
|
|
|
42
|
8 |
|
return $this->request; |
43
|
|
|
} |
44
|
|
|
|
45
|
8 |
|
protected function getOrder() |
46
|
|
|
{ |
47
|
8 |
|
return $this->getRequest()->getOrder(); |
48
|
|
|
} |
49
|
|
|
|
50
|
5 |
|
public function toArray() |
51
|
|
|
{ |
52
|
5 |
|
return array_merge($this->getGenericFields(), $this->getCustomFields()); |
53
|
|
|
} |
54
|
|
|
|
55
|
5 |
|
protected function getGenericFields() |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
5 |
|
'merchantAccount' => $this->getRequest()->getMerchantAccount(), |
59
|
5 |
|
'reference' => $this->factoryReference(), |
60
|
5 |
|
'amount' => ['currency' => 'BRL', 'value' => $this->getOrder()->getAmountInt()], |
61
|
5 |
|
'shopperEmail' => $this->getOrder()->getShopper()->getEmail(), |
62
|
5 |
|
'shopperIP' => $this->getOrder()->getShopper()->getIp(), |
63
|
5 |
|
'merchantOrderReference' => 'payment-'.$this->getOrder()->getId(), |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function getCustomFields() |
68
|
|
|
{ |
69
|
|
|
return []; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|