Passed
Push — master ( 087d19...7095a3 )
by Joao
04:17
created

WSVoidRequest::getPreAuth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Omnipay\Komerci\Message;
4
5
/**
6
 * Komerci Authorize Request
7
 */
8
class WSVoidRequest extends WSAbstractRequest
9
{
10
    use \Omnipay\Komerci\TraitRequest;
11
12
    public function getPreAuth()
13
    {
14
        return $this->getParameter('preauth');
15
    }
16
17
    public function setPreAuth($value)
18
    {
19
        return $this->setParameter('preauth', $value);
20
    }
21
    
22
    public function getData()
23
    {
24
        $this->validate('apikey', 'amount', 'transactionReference', 'numautor', 'username', 'password', 'installments');
25
26
        if ($this->getPreAuth()) {
27
            return $this->getVoidPreAuthData();
28
        } else {
29
            return $this->getVoidPurchaseData();
30
        }
31
    }
32
33
    protected function getVoidPurchaseData()
34
    {
35
        $data = array(
36
            'Total' => sprintf("%.2F", round($this->getAmount() * 100) / 100),
37
            'Filiacao' => $this->getApiKey(),
38
            'NumCv' => $this->getTransactionReference(),
39
            'NumAutor' => $this->getNumAutor(),
40
            'Concentrador' => '',
41
            'Usr' => $this->getUsername(),
42
            'Pwd' => $this->getPassword()
43
        );
44
45
        return $data;
46
    }
47
48
    protected function getVoidPreAuthData()
49
    {
50
        $data = $this->getVoidPurchaseData();
51
52
        if ($this->getTestMode()) {
53
            $data['Distribuidor'] = '';
54
        }
55
        $data['Parcelas'] = $this->getFormattedInstallments();
56
        $data['Data'] = date('Ymd');
57
58
        return $data;
59
    }
60
61
    public function sendData($data)
62
    {
63
        if ($this->getPreAuth()) {
64
            $httpResponse = $this->prepareSendData($data, 'VoidConfPreAuthorization.');
65
        } else {
66
            $httpResponse = $this->prepareSendData($data, 'VoidTransaction');
67
        }
68
        return $this->response = new WSConfPreAuthResponse($this, $httpResponse->xml());
0 ignored issues
show
Bug introduced by
The method xml() does not seem to exist on object<Omnipay\Common\Message\RequestInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
    }
70
}
71