Completed
Push — master ( ae809f...3d25d5 )
by Vladimir
06:15
created

PurchaseRequest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 2
cbo 2
dl 0
loc 174
ccs 72
cts 72
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getPhone() 0 4 1
A setPhone() 0 4 1
A getCf2() 0 4 1
A setCf2() 0 4 1
A getCf3() 0 4 1
A setCf3() 0 4 1
A getCallbackUrl() 0 4 1
A setCallbackUrl() 0 4 1
B getData() 0 67 6
A getRequestToken() 0 4 1
1
<?php
2
3
namespace Omnipay\AcquiroPay\Message;
4
5
/**
6
 * Purchase Request.
7
 *
8
 * @method Response send()
9
 */
10
class PurchaseRequest extends AuthorizeRequest
11
{
12
    /**
13
     * Get phone.
14
     *
15
     * @return string
16
     */
17 27
    public function getPhone()
18
    {
19 27
        return $this->getParameter('phone');
20
    }
21
22
    /**
23
     * Set phone.
24
     *
25
     * @param string $value
26
     *
27
     * @return static|\Omnipay\Common\Message\AbstractRequest
28
     */
29 6
    public function setPhone($value)
30
    {
31 6
        return $this->setParameter('phone', $value);
32
    }
33
34
    /**
35
     * Get custom field 2.
36
     *
37
     * @return string
38
     */
39 15
    public function getCf2()
40
    {
41 15
        return $this->getParameter('cf2');
42
    }
43
44
    /**
45
     * Set custom field 2.
46
     *
47
     * @param string $value
48
     *
49
     * @return static|\Omnipay\Common\Message\AbstractRequest
50
     */
51 6
    public function setCf2($value)
52
    {
53 6
        return $this->setParameter('cf2', $value);
54
    }
55
56
    /**
57
     * Get custom field 3.
58
     *
59
     * @return string
60
     */
61 15
    public function getCf3()
62
    {
63 15
        return $this->getParameter('cf3');
64
    }
65
66
    /**
67
     * Set custom field 3.
68
     *
69
     * @param string $value
70
     *
71
     * @return static|\Omnipay\Common\Message\AbstractRequest
72
     */
73 6
    public function setCf3($value)
74
    {
75 6
        return $this->setParameter('cf3', $value);
76
    }
77
78
    /**
79
     * Get callback URL.
80
     *
81
     * @return string
82
     */
83 15
    public function getCallbackUrl()
84
    {
85 15
        return $this->getParameter('callbackUrl');
86
    }
87
88
    /**
89
     * Set callback URL.
90
     *
91
     * @param string $value
92
     *
93
     * @return static|\Omnipay\Common\Message\AbstractRequest
94
     */
95 6
    public function setCallbackUrl($value)
96
    {
97 6
        return $this->setParameter('callbackUrl', $value);
98
    }
99
100
    /**
101
     * Get the raw data array for this message. The format of this varies from gateway to
102
     * gateway, but will usually be either an associative array, or a SimpleXMLElement.
103
     *
104
     * @return array
105
     */
106 15
    public function getData()
107
    {
108 15
        if ($this->getCardReference() !== null) {
109 3
            $this->validate(
110 3
                'amount',
111 3
                'card',
112 3
                'cardReference',
113 3
                'transactionId',
114 3
                'clientIp',
115
                'returnUrl'
116 3
            );
117
118
            $data = array(
119 3
                'opcode'      => 21,
120 3
                'product_id'  => $this->getProductId(),
121 3
                'payment_id'  => $this->getCardReference(),
122 3
                'amount'      => $this->getAmount(),
123 3
                'cf'          => $this->getTransactionId(),
124 3
                'ip_address'  => $this->getClientIp(),
125 3
                'cvv'         => $this->getCard()->getCvv(),
126 3
                'pp_identity' => 'card',
127 3
                'token'       => $this->getRequestToken(),
128 3
            );
129 3
        } else {
130 12
            $this->validate(
131 12
                'amount',
132 12
                'card',
133 12
                'transactionId',
134 12
                'clientIp',
135
                'returnUrl'
136 12
            );
137
138 12
            $card = $this->getCard();
139
140 12
            $card->validate();
141
142
            $data = array(
143 12
                'opcode'      => 0,
144 12
                'product_id'  => $this->getProductId(),
145 12
                'amount'      => $this->getAmount(),
146 12
                'cf'          => $this->getTransactionId(),
147 12
                'ip_address'  => $this->getClientIp(),
148 12
                'pan'         => $card->getNumber(),
149 12
                'cardholder'  => $card->getName(),
150 12
                'exp_month'   => $card->getExpiryMonth(),
151 12
                'exp_year'    => $card->getExpiryYear(),
152 12
                'cvv'         => $card->getCvv(),
153 12
                'pp_identity' => 'card',
154 12
                'token'       => $this->getRequestToken(),
155 12
            );
156
        }
157
158 15
        if ($this->getPhone()) {
159 6
            $data['phone'] = $this->getPhone();
160 6
        }
161 15
        if ($this->getCf2()) {
162 6
            $data['cf2'] = $this->getCf2();
163 6
        }
164 15
        if ($this->getCf3()) {
165 6
            $data['cf3'] = $this->getCf3();
166 6
        }
167 15
        if ($this->getCallbackUrl()) {
168 6
            $data['cb_url'] = $this->getCallbackUrl();
169 6
        }
170
171 15
        return $data;
172
    }
173
174
    /**
175
     * Get a request token.
176
     *
177
     * @return string
178
     */
179 27
    public function getRequestToken()
180
    {
181 27
        return md5($this->getMerchantId().$this->getProductId().$this->getAmount().$this->getTransactionId().$this->getPhone().$this->getSecretWord());
182
    }
183
}
184