Passed
Push — master ( 8baa4a...fa5dd9 )
by João Felipe Magro
01:17
created

Transaction::sendHttpRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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();
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
    public function authenticate()
100
    {
101
        $authentication = $this->getIpag()->getAuthentication();
102
103
        $this->getOnlyPostClient()
104
            ->setUser($authentication->getIdentification())
105
            ->setPassword($authentication->getApiKey());
106
107
        return $this;
108
    }
109
}
110