Serializer::getAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Ipag\Classes\Serializer;
4
5
use Ipag\Classes\Contracts\Serializable;
6
use Ipag\Classes\Transaction;
7
8
class Serializer implements Serializable
9
{
10
    /**
11
     * @var Transaction
12
     */
13
    protected $transaction;
14
15
    /**
16
     * @var string
17
     */
18
    protected $action;
19
20
    /**
21
     * @var string
22
     */
23
    protected $operation;
24
25
    public function __construct(Transaction $transaction, $action, $operation)
26
    {
27
        $this->transaction = $transaction;
28
        $this->action = $action;
29
        $this->operation = $operation;
30
    }
31
32
    public function serialize()
33
    {
34
        $response = [
35
            'identificacao' => urlencode((string) $this->transaction->getIpag()->getAuthentication()->getIdentification()),
36
            'transId'       => urlencode((string) $this->transaction->getTid()),
37
            'numPedido'     => urlencode((string) $this->transaction->getNumPedido()),
38
            'retorno_tipo'  => urlencode('xml'),
39
        ];
40
41
        $amount = $this->transaction->getOrder()->getAmount();
42
        if (!empty($amount)) {
43
            $response['valor'] = $amount;
44
        }
45
46
        return $response;
47
    }
48
49
    /**
50
     * @return Transaction
51
     */
52
    public function getTransaction()
53
    {
54
        return $this->transaction;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getAction()
61
    {
62
        return $this->action;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getOperation()
69
    {
70
        return $this->operation;
71
    }
72
}
73