Passed
Pull Request — master (#22)
by Lucas
05:54
created

Transaction::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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