1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ipag\Classes; |
4
|
|
|
|
5
|
|
|
use Ipag\Classes\Serializer\CancelSerializer; |
6
|
|
|
use Ipag\Classes\Serializer\CaptureSerializer; |
7
|
|
|
use Ipag\Classes\Serializer\ConsultSerializer; |
8
|
|
|
use Ipag\Classes\Serializer\Serializer; |
9
|
|
|
use stdClass; |
10
|
|
|
|
11
|
|
|
final class Transaction extends IpagResource |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Order |
15
|
|
|
*/ |
16
|
|
|
private $order; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $tid; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public function getTid() |
27
|
|
|
{ |
28
|
|
|
return $this->tid; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $tid |
33
|
|
|
*/ |
34
|
|
|
public function setTid($tid) |
35
|
|
|
{ |
36
|
|
|
$this->tid = $tid; |
37
|
|
|
|
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return Order |
43
|
|
|
*/ |
44
|
|
|
public function getOrder() |
45
|
|
|
{ |
46
|
|
|
if (is_null($this->order)) { |
47
|
|
|
$this->order = new Order(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->order; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Order $order |
55
|
|
|
*/ |
56
|
|
|
public function setOrder(Order $order) |
57
|
|
|
{ |
58
|
|
|
$this->order = $order; |
59
|
|
|
|
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function populate(stdClass $response) |
64
|
|
|
{ |
65
|
|
|
return (new Services\TransactionResponseService())->populate($response); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function execute() |
69
|
|
|
{ |
70
|
|
|
return (new Services\PaymentService($this))->execute(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function consult() |
74
|
|
|
{ |
75
|
|
|
return (new Services\ConsultService($this))->execute(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function cancel() |
79
|
|
|
{ |
80
|
|
|
return (new Services\CancelService($this))->execute(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function capture() |
84
|
|
|
{ |
85
|
|
|
return (new Services\CaptureService($this))->execute(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
private function authenticate() |
89
|
|
|
{ |
90
|
|
|
$authentication = $this->getIpag()->getAuthentication(); |
91
|
|
|
$this->getOnlyPostClient() |
92
|
|
|
->setUser($authentication->getIdentification()) |
93
|
|
|
->setPassword($authentication->getApiKey()); |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
final public function sendHttpRequest($endpoint, $parameters) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$this->authenticate(); |
101
|
|
|
|
102
|
|
|
return parent::sendHttpRequest($endpoint, $parameters); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|