Passed
Push — master ( 4c395d...8635c7 )
by João Felipe Magro
03:06 queued 14s
created

Transaction::getOrder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
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
    /**
25
     * @var string
26
     */
27
    private $numPedido;
28
29
    public function __construct(Ipag $ipag)
30
    {
31
        parent::__construct($ipag);
32
        $this->apiService = new Services\ApiActionService();
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getTid()
39
    {
40
        return $this->tid;
41
    }
42
43
    /**
44
     * @param string $tid
45
     */
46
    public function setTid($tid)
47
    {
48
        $this->tid = $tid;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getNumPedido()
57
    {
58
        return $this->numPedido;
59
    }
60
61
    /**
62
     * @param string $numPedido
63
     */
64
    public function setNumPedido($numPedido)
65
    {
66
        $this->numPedido = $numPedido;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @return Order
73
     */
74
    public function getOrder()
75
    {
76
        if (is_null($this->order)) {
77
            $this->order = new Order();
78
        }
79
80
        return $this->order;
81
    }
82
83
    /**
84
     * @param Order $order
85
     */
86
    public function setOrder(Order $order)
87
    {
88
        $this->order = $order;
89
90
        return $this;
91
    }
92
93
    /**
94
     * @param float $amount
95
     */
96
    public function setAmount($amount)
97
    {
98
        $this->getOrder()->setAmount($amount);
99
100
        return $this;
101
    }
102
103
    public function populate(stdClass $response)
104
    {
105
        return (new Services\TransactionResponseService())->populate($response);
106
    }
107
108
    public function execute()
109
    {
110
        return $this->apiService
111
            ->execute(new PaymentSerializer($this, Action::PAYMENT, Operation::PAYMENT));
112
    }
113
114
    public function consult()
115
    {
116
        return $this->apiService
117
            ->execute(new Serializer($this, Action::CONSULT, Operation::CONSULT));
118
    }
119
120
    public function cancel()
121
    {
122
        return $this->apiService
123
            ->execute(new Serializer($this, Action::CANCEL, Operation::CANCEL));
124
    }
125
126
    public function capture()
127
    {
128
        return $this->apiService
129
            ->execute(new Serializer($this, Action::CAPTURE, Operation::CAPTURE));
130
    }
131
132
    public function authenticate()
133
    {
134
        $authentication = $this->getIpag()->getAuthentication();
135
136
        $this->getOnlyPostClient()
137
            ->setUser($authentication->getIdentification())
138
            ->setPassword($authentication->getApiKey());
139
140
        return $this;
141
    }
142
}
143