1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ipag\Classes; |
4
|
|
|
|
5
|
|
|
use Ipag\Classes\Enum\Action; |
6
|
|
|
use Ipag\Classes\Enum\Operation; |
7
|
|
|
use Ipag\Classes\Serializer\PaymentSerializer; |
8
|
|
|
use Ipag\Classes\Serializer\Serializer; |
9
|
|
|
use Ipag\Ipag; |
10
|
|
|
use stdClass; |
11
|
|
|
|
12
|
|
|
final class Transaction extends IpagResource |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Order |
16
|
|
|
*/ |
17
|
|
|
private $order; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $tid; |
23
|
|
|
|
24
|
|
|
public function __construct(Ipag $ipag) |
25
|
|
|
{ |
26
|
|
|
parent::__construct($ipag); |
27
|
|
|
$this->apiService = new Services\ApiActionService($this); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
|
|
public function getTid() |
34
|
|
|
{ |
35
|
|
|
return $this->tid; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $tid |
40
|
|
|
*/ |
41
|
|
|
public function setTid($tid) |
42
|
|
|
{ |
43
|
|
|
$this->tid = $tid; |
44
|
|
|
|
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return Order |
50
|
|
|
*/ |
51
|
|
|
public function getOrder() |
52
|
|
|
{ |
53
|
|
|
if (is_null($this->order)) { |
54
|
|
|
$this->order = new Order(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->order; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param Order $order |
62
|
|
|
*/ |
63
|
|
|
public function setOrder(Order $order) |
64
|
|
|
{ |
65
|
|
|
$this->order = $order; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function populate(stdClass $response) |
71
|
|
|
{ |
72
|
|
|
return (new Services\TransactionResponseService())->populate($response); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function execute() |
76
|
|
|
{ |
77
|
|
|
return $this->apiService |
78
|
|
|
->execute(new PaymentSerializer($this, Action::PAYMENT, Operation::PAYMENT)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function consult() |
82
|
|
|
{ |
83
|
|
|
return $this->apiService |
84
|
|
|
->execute(new Serializer($this, Action::CONSULT, Operation::CONSULT)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function cancel() |
88
|
|
|
{ |
89
|
|
|
return $this->apiService |
90
|
|
|
->execute(new Serializer($this, Action::CANCEL, Operation::CANCEL)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function capture() |
94
|
|
|
{ |
95
|
|
|
return $this->apiService |
96
|
|
|
->execute(new Serializer($this, Action::CAPTURE, Operation::CAPTURE)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private function authenticate() |
100
|
|
|
{ |
101
|
|
|
$authentication = $this->getIpag()->getAuthentication(); |
102
|
|
|
$this->getOnlyPostClient() |
103
|
|
|
->setUser($authentication->getIdentification()) |
|
|
|
|
104
|
|
|
->setPassword($authentication->getApiKey()); |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function sendHttpRequest($endpoint, $parameters) |
110
|
|
|
{ |
111
|
|
|
$this->authenticate(); |
112
|
|
|
|
113
|
|
|
return parent::sendHttpRequest($endpoint, $parameters); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.