Test Failed
Pull Request — master (#18)
by
unknown
02:56
created

PaymentRequest   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 250
Duplicated Lines 0 %

Test Coverage

Coverage 58.78%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 34
eloc 101
c 5
b 0
f 1
dl 0
loc 250
ccs 77
cts 131
cp 0.5878
rs 9.68

26 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setNotificationEmail() 0 6 2
A withNotificationEmail() 0 3 1
A setTotal() 0 4 1
A setConfirmationSpeed() 0 4 1
A setCustomer() 0 5 1
A setSuccessUrl() 0 6 2
A lowRiskConfirmation() 0 3 1
A withCustomPaymentId() 0 3 1
A withSuccessUrl() 0 3 1
A toArray() 0 26 2
A withCancelUrl() 0 3 1
A confirmationSpeed() 0 3 1
A setCallbackData() 0 10 3
A setIpnUrl() 0 6 2
A fromResponse() 0 24 2
A setQuickConfirmation() 0 3 1
A withIpnUrl() 0 3 1
A balancedConfirmation() 0 3 1
A withCallbackData() 0 3 1
A setBalancedConfirmation() 0 3 1
A setCustomPaymentId() 0 3 1
A quickConfirmation() 0 3 1
A setLowRiskConfirmation() 0 3 1
A setCurrency() 0 4 1
A setCancelUrl() 0 6 2
1
<?php
2
3
namespace GloBee\PaymentApi\Models;
4
5
use GloBee\PaymentApi\Exceptions\Validation\ValidationException;
6
7
class PaymentRequest extends Model
8
{
9
    protected $total;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
10
    protected $currency;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
11
    protected $customPaymentId;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
12
    protected $callbackData;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
13
    protected $customerName;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
14
    protected $customerEmail;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
15
    protected $successUrl;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
16
    protected $cancelUrl;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
17
    protected $ipnUrl;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
18
    protected $notificationEmail;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
19
    protected $confirmationSpeed = 'medium';
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
20
    protected $id;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
21
    protected $status;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
22
    protected $redirectUrl;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
23
    protected $expiresAt;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
24
    protected $createdAt;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
25
26 18
    public function __construct($customerEmail, $total, $currency = 'USD', $customerName = null)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
27
    {
28 18
        $this->setTotal($total);
29 16
        $this->setCurrency($currency);
30 14
        $this->setCustomer($customerEmail, $customerName);
31 13
    }
32
33 18
    protected function setTotal($total)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
34
    {
35 18
        Validator::validateNumberAboveMinimum('total', $total, 0);
36 16
        $this->total = $total;
37 16
    }
38
39 16
    protected function setCurrency($currency)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
40
    {
41 16
        Validator::validateStringLength('currency', $currency, 3);
42 14
        $this->currency = strtoupper($currency);
43 14
    }
44
45 14
    protected function setCustomer($customerEmail, $customerName = null)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
46
    {
47 14
        Validator::validateEmail('customer.email', $customerEmail);
48 13
        $this->customerEmail = $customerEmail;
49 13
        $this->customerName = $customerName;
50 13
    }
51
52 1
    public function setSuccessUrl($successUrl)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
53
    {
54 1
        if ($successUrl !== null) {
55 1
            Validator::validateUrl('success_url', $successUrl);
56
        }
57
        $this->successUrl = $successUrl;
58
    }
59
60 1
    public function setCancelUrl($cancelUrl)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
61
    {
62 1
        if ($cancelUrl !== null) {
63 1
            Validator::validateUrl('cancel_url', $cancelUrl);
64
        }
65
        $this->cancelUrl = $cancelUrl;
66
    }
67
68
    public function setCallbackData($callbackData)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
69
    {
70
        $callbackDataString = $callbackData;
71
        if (!is_string($callbackData)) {
72
            $callbackDataString = json_encode($callbackData);
73
        }
74
        if (strlen($callbackDataString) > 150) {
75
            throw new ValidationException([], 'Callback Data must be less than 150 characters long.');
76
        }
77
        $this->callbackData = $callbackData;
78
    }
79
80 1
    public function setIpnUrl($ipnUrl)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
81
    {
82 1
        if ($ipnUrl !== null) {
83 1
            Validator::validateUrl('ipn_url', $ipnUrl);
84
        }
85
        $this->ipnUrl = $ipnUrl;
86
    }
87
88
    public function setCustomPaymentId($customPaymentId)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
89
    {
90
        $this->customPaymentId = $customPaymentId;
91
    }
92
93 1
    public function setNotificationEmail($notificationEmail)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
94
    {
95 1
        if ($notificationEmail !== null) {
96 1
            Validator::validateEmail('notification_email', $notificationEmail);
97
        }
98
        $this->notificationEmail = $notificationEmail;
99
    }
100
101
    public function setLowRiskConfirmation()
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
102
    {
103
        $this->confirmationSpeed = 'low';
104
    }
105
106
    public function setBalancedConfirmation()
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
107
    {
108
        $this->confirmationSpeed = 'medium';
109
    }
110
111
    public function setQuickConfirmation()
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
112
    {
113
        $this->confirmationSpeed = 'high';
114
    }
115
116
    public function setConfirmationSpeed($confirmationSpeed)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
117
    {
118
        Validator::validateOptions('confirmation_speed', $confirmationSpeed, ['low', 'medium', 'high']);
119
        $this->confirmationSpeed = $confirmationSpeed;
120
    }
121
122 6
    public static function fromResponse(array $data)
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
123
    {
124 6
        $self = new self($data['customer']['email'], $data['total']);
125
126 6
        $callbackData = json_decode($data['callback_data'], true);
127 6
        if (json_last_error() !== JSON_ERROR_NONE) {
128 5
            $callbackData = $data['callback_data'];
129
        }
130 6
        $self->id = $data['id'];
131 6
        $self->status = $data['status'];
132 6
        $self->currency = $data['currency'];
133 6
        $self->customPaymentId = $data['custom_payment_id'];
134 6
        $self->callbackData = $callbackData;
135 6
        $self->customerName = $data['customer']['name'];
136 6
        $self->redirectUrl = $data['redirect_url'];
137 6
        $self->successUrl = $data['success_url'];
138 6
        $self->cancelUrl = $data['cancel_url'];
139 6
        $self->ipnUrl = $data['ipn_url'];
140 6
        $self->notificationEmail = $data['notification_email'];
141 6
        $self->confirmationSpeed = $data['confirmation_speed'];
142 6
        $self->expiresAt = $data['expires_at'];
143 6
        $self->createdAt = $data['created_at'];
144
145 6
        return $self;
146
    }
147
148 2
    public function toArray()
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
149
    {
150 2
        $callbackData = $this->callbackData;
151 2
        if (is_array($callbackData)) {
152
            $callbackData = json_encode($callbackData);
153
        }
154
155
        return [
156 2
            'id' => $this->id,
157 2
            'status' => $this->status,
158 2
            'total' => $this->total,
159 2
            'currency' => $this->currency,
160 2
            'custom_payment_id' => $this->customPaymentId,
161 2
            'callback_data' => $callbackData,
162
            'customer' => [
163 2
                'name' => $this->customerName,
164 2
                'email' => $this->customerEmail,
165
            ],
166 2
            'redirect_url' => $this->redirectUrl,
167 2
            'success_url' => $this->successUrl,
168 2
            'cancel_url' => $this->cancelUrl,
169 2
            'ipn_url' => $this->ipnUrl,
170 2
            'notification_email' => $this->notificationEmail,
171 2
            'confirmation_speed' => $this->confirmationSpeed,
172 2
            'expires_at' => $this->expiresAt,
173 2
            'created_at' => $this->createdAt,
174
        ];
175
    }
176
177
    // The below methods are deprecated ----------------------------------------------------------------------------- //
178
179
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$successUrl" missing
Loading history...
180
     * @deprecated
181
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
182 1
    public function withSuccessUrl($successUrl)
183
    {
184 1
        $this->setSuccessUrl($successUrl);
185
    }
186
187
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$cancelUrl" missing
Loading history...
188
     * @deprecated
189
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
190 1
    public function withCancelUrl($cancelUrl)
191
    {
192 1
        $this->setCancelUrl($cancelUrl);
193
    }
194
195
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$callbackData" missing
Loading history...
196
     * @deprecated
197
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
198
    public function withCallbackData($callbackData)
199
    {
200
        $this->setCallbackData($callbackData);
201
    }
202
203
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$ipnUrl" missing
Loading history...
204
     * @deprecated
205
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
206 1
    public function withIpnUrl($ipnUrl)
207
    {
208 1
        $this->setIpnUrl($ipnUrl);
209
    }
210
211
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$customPaymentId" missing
Loading history...
212
     * @deprecated
213
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
214
    public function withCustomPaymentId($customPaymentId)
215
    {
216
        $this->setCustomPaymentId($customPaymentId);
217
    }
218
219
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$notificationEmail" missing
Loading history...
220
     * @deprecated
221
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
222 1
    public function withNotificationEmail($notificationEmail)
223
    {
224 1
        $this->setNotificationEmail($notificationEmail);
225
    }
226
227
    /**
228
     * @deprecated
229
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
230
    public function lowRiskConfirmation()
231
    {
232
        $this->setLowRiskConfirmation();
233
    }
234
235
    /**
236
     * @deprecated
237
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
238
    public function balancedConfirmation()
239
    {
240
        $this->setBalancedConfirmation();
241
    }
242
243
    /**
244
     * @deprecated
245
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
246
    public function quickConfirmation()
247
    {
248
        $this->setQuickConfirmation();
249
    }
250
251
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$confirmationSpeed" missing
Loading history...
252
     * @deprecated
253
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
254
    public function confirmationSpeed($confirmationSpeed)
255
    {
256
        $this->confirmationSpeed($confirmationSpeed);
0 ignored issues
show
Deprecated Code introduced by
The function GloBee\PaymentApi\Models...st::confirmationSpeed() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

256
        /** @scrutinizer ignore-deprecated */ $this->confirmationSpeed($confirmationSpeed);
Loading history...
257
    }
258
}
259