1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Covery\Client\Envelopes; |
4
|
|
|
|
5
|
|
|
use Covery\Client\EnvelopeInterface; |
6
|
|
|
use Covery\Client\IdentityNodeInterface; |
7
|
|
|
|
8
|
|
|
class Builder |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private $type; |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $sequenceId; |
18
|
|
|
/** |
19
|
|
|
* @var IdentityNodeInterface[] |
20
|
|
|
*/ |
21
|
|
|
private $identities = array(); |
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private $data = array(); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Returns builder for confirmation event |
29
|
|
|
* |
30
|
|
|
* @param $sequenceId |
31
|
|
|
* @param $userId |
32
|
|
|
* @param int|null $timestamp If null provided, takes current time |
33
|
|
|
* @param bool|null $isEmailConfirmed |
34
|
|
|
* @param bool|null $idPhoneConfirmed |
35
|
|
|
* @return Builder |
36
|
|
|
*/ |
37
|
|
|
public static function confirmationEvent( |
38
|
|
|
$sequenceId, |
39
|
|
|
$userId, |
40
|
|
|
$timestamp = null, |
41
|
|
|
$isEmailConfirmed = null, |
42
|
|
|
$idPhoneConfirmed = null |
43
|
|
|
) { |
44
|
|
|
$builder = new self('confirmation', $sequenceId); |
45
|
|
|
if ($timestamp === null) { |
46
|
|
|
$timestamp = time(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $builder->addUserData( |
50
|
|
|
null, |
51
|
|
|
$userId, |
52
|
|
|
null, |
53
|
|
|
null, |
54
|
|
|
null, |
55
|
|
|
null, |
56
|
|
|
null, |
57
|
|
|
null, |
58
|
|
|
null, |
59
|
|
|
null, |
60
|
|
|
null, |
61
|
|
|
null, |
62
|
|
|
$timestamp, |
63
|
|
|
$isEmailConfirmed, |
|
|
|
|
64
|
|
|
$idPhoneConfirmed, |
|
|
|
|
65
|
|
|
null |
|
|
|
|
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Builder constructor. |
71
|
|
|
* |
72
|
|
|
* @param string $envelopeType |
73
|
|
|
* @param string $sequenceId |
74
|
|
|
*/ |
75
|
|
|
public function __construct($envelopeType, $sequenceId) |
76
|
|
|
{ |
77
|
|
|
if (!is_string($envelopeType)) { |
78
|
|
|
throw new \InvalidArgumentException('Envelope type must be string'); |
79
|
|
|
} |
80
|
|
|
if (!is_string($sequenceId)) { |
81
|
|
|
throw new \InvalidArgumentException('Sequence ID must be string'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->type = $envelopeType; |
85
|
|
|
$this->sequenceId = $sequenceId; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Returns built envelope |
90
|
|
|
* |
91
|
|
|
* @return EnvelopeInterface |
92
|
|
|
*/ |
93
|
|
|
public function build() |
94
|
|
|
{ |
95
|
|
|
return new Envelope( |
96
|
|
|
$this->type, |
97
|
|
|
$this->sequenceId, |
98
|
|
|
$this->identities, |
99
|
|
|
array_filter($this->data, function ($data) { |
100
|
|
|
return $data !== null; |
101
|
|
|
}) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Replaces value in internal array if provided value not empty |
107
|
|
|
* |
108
|
|
|
* @param string $key |
109
|
|
|
* @param string|int|float $value |
110
|
|
|
*/ |
111
|
|
|
private function replace($key, $value) |
112
|
|
|
{ |
113
|
|
|
if (!array_key_exists($key, $this->data) || !empty($value)) { |
114
|
|
|
$this->data[$key] = $value; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Adds identity node |
120
|
|
|
* |
121
|
|
|
* @param IdentityNodeInterface $identity |
122
|
|
|
* |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
|
|
public function addIdentity(IdentityNodeInterface $identity) |
126
|
|
|
{ |
127
|
|
|
$this->identities[] = $identity; |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Provides website URL to envelope |
133
|
|
|
* |
134
|
|
|
* @param string $websiteUrl |
135
|
|
|
* @return $this |
136
|
|
|
*/ |
137
|
|
|
public function addWebsiteData($websiteUrl = '') |
138
|
|
|
{ |
139
|
|
|
if (!is_string($websiteUrl)) { |
140
|
|
|
throw new \InvalidArgumentException('Website URL must be string'); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Provides IP information for envelope |
148
|
|
|
* |
149
|
|
|
* @param string $ip User's IP address |
150
|
|
|
* @param string $realIp User's real IP address, if available |
151
|
|
|
* @param string $merchantIp Your website's IP address |
152
|
|
|
* |
153
|
|
|
* @return $this |
154
|
|
|
*/ |
155
|
|
View Code Duplication |
public function addIpData($ip = '', $realIp = '', $merchantIp = '') |
|
|
|
|
156
|
|
|
{ |
157
|
|
|
if ($ip !== null && !is_string($ip)) { |
158
|
|
|
throw new \InvalidArgumentException('IP must be string'); |
159
|
|
|
} |
160
|
|
|
if ($realIp !== null && !is_string($realIp)) { |
161
|
|
|
throw new \InvalidArgumentException('Real IP must be string'); |
162
|
|
|
} |
163
|
|
|
if ($merchantIp !== null && !is_string($merchantIp)) { |
164
|
|
|
throw new \InvalidArgumentException('Merchant IP must be string'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$this->replace('ip', $ip); |
168
|
|
|
$this->replace('real_ip', $realIp); |
169
|
|
|
$this->replace('merchant_ip', $merchantIp); |
170
|
|
|
|
171
|
|
|
return $this; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Provides browser information for envelope |
176
|
|
|
* |
177
|
|
|
* @param string $deviceFingerprint |
178
|
|
|
* @param string $userAgent |
179
|
|
|
* @param string $cpuClass |
180
|
|
|
* @param string $screenOrientation |
181
|
|
|
* @param string $screenResolution |
182
|
|
|
* @param string $os |
183
|
|
|
* @param int|null $timezoneOffset |
184
|
|
|
* @param string $languages |
185
|
|
|
* @param string $language |
186
|
|
|
* @param string $languageBrowser |
187
|
|
|
* @param string $languageUser |
188
|
|
|
* @param string $languageSystem |
189
|
|
|
* @param bool $cookieEnabled |
190
|
|
|
* @param bool $doNotTrack |
191
|
|
|
* @param bool $ajaxValidation |
192
|
|
|
* |
193
|
|
|
* @return $this |
194
|
|
|
*/ |
195
|
|
|
public function addBrowserData( |
196
|
|
|
$deviceFingerprint = '', |
197
|
|
|
$userAgent = '', |
198
|
|
|
$cpuClass = '', |
199
|
|
|
$screenOrientation = '', |
200
|
|
|
$screenResolution = '', |
201
|
|
|
$os = '', |
202
|
|
|
$timezoneOffset = null, |
203
|
|
|
$languages = '', |
204
|
|
|
$language = '', |
205
|
|
|
$languageBrowser = '', |
206
|
|
|
$languageUser = '', |
207
|
|
|
$languageSystem = '', |
208
|
|
|
$cookieEnabled = false, |
209
|
|
|
$doNotTrack = false, |
210
|
|
|
$ajaxValidation = false |
211
|
|
|
) { |
212
|
|
|
if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) { |
213
|
|
|
throw new \InvalidArgumentException('Device fingerprint must be string'); |
214
|
|
|
} |
215
|
|
|
if ($userAgent !== null && !is_string($userAgent)) { |
216
|
|
|
throw new \InvalidArgumentException('User agent must be string'); |
217
|
|
|
} |
218
|
|
|
if ($cpuClass !== null && !is_string($cpuClass)) { |
219
|
|
|
throw new \InvalidArgumentException('CPU class must be string'); |
220
|
|
|
} |
221
|
|
|
if ($screenOrientation !== null && !is_string($screenOrientation)) { |
222
|
|
|
throw new \InvalidArgumentException('Screen orientation must be string'); |
223
|
|
|
} |
224
|
|
|
if ($screenResolution !== null && !is_string($screenResolution)) { |
225
|
|
|
throw new \InvalidArgumentException('Screen resolution must be string'); |
226
|
|
|
} |
227
|
|
|
if ($os !== null && !is_string($os)) { |
228
|
|
|
throw new \InvalidArgumentException('OS must be string'); |
229
|
|
|
} |
230
|
|
|
if ($timezoneOffset !== null && $timezoneOffset !== null && !is_int($timezoneOffset)) { |
231
|
|
|
throw new \InvalidArgumentException('Timezone offset must be integer or null'); |
232
|
|
|
} |
233
|
|
|
if ($languages !== null && !is_string($languages)) { |
234
|
|
|
throw new \InvalidArgumentException('Languages must be string'); |
235
|
|
|
} |
236
|
|
|
if ($language !== null && !is_string($language)) { |
237
|
|
|
throw new \InvalidArgumentException('Language must be string'); |
238
|
|
|
} |
239
|
|
|
if ($languageBrowser !== null && !is_string($languageBrowser)) { |
240
|
|
|
throw new \InvalidArgumentException('Browser language must be string'); |
241
|
|
|
} |
242
|
|
|
if ($languageUser !== null && !is_string($languageUser)) { |
243
|
|
|
throw new \InvalidArgumentException('User language must be string'); |
244
|
|
|
} |
245
|
|
|
if ($languageSystem !== null && !is_string($languageSystem)) { |
246
|
|
|
throw new \InvalidArgumentException('System language must be string'); |
247
|
|
|
} |
248
|
|
|
if ($cookieEnabled !== null && !is_bool($cookieEnabled)) { |
249
|
|
|
throw new \InvalidArgumentException('Cookie enabled flag must be boolean'); |
250
|
|
|
} |
251
|
|
|
if ($doNotTrack !== null && !is_bool($doNotTrack)) { |
252
|
|
|
throw new \InvalidArgumentException('DNT flag must be boolean'); |
253
|
|
|
} |
254
|
|
|
if ($ajaxValidation !== null && !is_bool($ajaxValidation)) { |
255
|
|
|
throw new \InvalidArgumentException('AJAX validation flag must be boolean'); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
$this->replace('device_fingerprint', $deviceFingerprint); |
259
|
|
|
$this->replace('user_agent', $userAgent); |
260
|
|
|
$this->replace('cpu_class', $cpuClass); |
261
|
|
|
$this->replace('screen_orientation', $screenOrientation); |
262
|
|
|
$this->replace('screen_resolution', $screenResolution); |
263
|
|
|
$this->replace('os', $os); |
264
|
|
|
$this->replace('timezone_offset', $timezoneOffset); |
265
|
|
|
$this->replace('languages', $languages); |
266
|
|
|
$this->replace('language', $language); |
267
|
|
|
$this->replace('language_browser', $languageBrowser); |
268
|
|
|
$this->replace('language_system', $languageSystem); |
269
|
|
|
$this->replace('language_user', $languageUser); |
270
|
|
|
$this->replace('cookie_enabled', $cookieEnabled); |
|
|
|
|
271
|
|
|
$this->replace('do_not_track', $doNotTrack); |
|
|
|
|
272
|
|
|
$this->replace('ajax_validation', $ajaxValidation); |
|
|
|
|
273
|
|
|
|
274
|
|
|
return $this; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Provides user data for envelope |
279
|
|
|
* |
280
|
|
|
* @param string $email |
281
|
|
|
* @param string $userId |
282
|
|
|
* @param string $phone |
283
|
|
|
* @param string $userName |
284
|
|
|
* @param string $firstName |
285
|
|
|
* @param string $lastName |
286
|
|
|
* @param string $gender |
287
|
|
|
* @param int $age |
288
|
|
|
* @param string $country |
289
|
|
|
* @param string $socialType |
290
|
|
|
* @param int $registrationTimestamp |
291
|
|
|
* @param int $loginTimeStamp |
292
|
|
|
* @param int $confirmationTimeStamp |
293
|
|
|
* @param bool $emailConfirmed |
294
|
|
|
* @param bool $phoneConfirmed |
295
|
|
|
* @param bool $loginFailed |
296
|
|
|
* |
297
|
|
|
* @return $this |
298
|
|
|
*/ |
299
|
|
|
public function addUserData( |
300
|
|
|
$email = '', |
301
|
|
|
$userId = '', |
302
|
|
|
$phone = '', |
303
|
|
|
$userName = '', |
304
|
|
|
$firstName = '', |
305
|
|
|
$lastName = '', |
306
|
|
|
$gender = '', |
307
|
|
|
$age = 0, |
308
|
|
|
$country = '', |
309
|
|
|
$socialType = '', |
310
|
|
|
$registrationTimestamp = 0, |
311
|
|
|
$loginTimeStamp = 0, |
312
|
|
|
$confirmationTimeStamp = 0, |
313
|
|
|
$emailConfirmed = false, |
314
|
|
|
$phoneConfirmed = false, |
315
|
|
|
$loginFailed = false |
316
|
|
|
) { |
317
|
|
|
if ($email !== null && !is_string($email)) { |
318
|
|
|
throw new \InvalidArgumentException('Email must be string'); |
319
|
|
|
} |
320
|
|
|
if (is_int($userId)) { |
321
|
|
|
$userId = strval($userId); |
322
|
|
|
} |
323
|
|
|
if ($userId !== null && !is_string($userId)) { |
324
|
|
|
throw new \InvalidArgumentException('UserId must be string or integer'); |
325
|
|
|
} |
326
|
|
|
if ($phone !== null && !is_string($phone)) { |
327
|
|
|
throw new \InvalidArgumentException('Phone must be string'); |
328
|
|
|
} |
329
|
|
|
if ($userName !== null && !is_string($userName)) { |
330
|
|
|
throw new \InvalidArgumentException('User name must be string'); |
331
|
|
|
} |
332
|
|
|
if ($firstName !== null && !is_string($firstName)) { |
333
|
|
|
throw new \InvalidArgumentException('First name must be string'); |
334
|
|
|
} |
335
|
|
|
if ($lastName !== null && !is_string($lastName)) { |
336
|
|
|
throw new \InvalidArgumentException('Last name must be string'); |
337
|
|
|
} |
338
|
|
|
if ($gender !== null && !is_string($gender)) { |
339
|
|
|
throw new \InvalidArgumentException('Gender must be string'); |
340
|
|
|
} |
341
|
|
|
if ($age !== null && !is_int($age)) { |
342
|
|
|
throw new \InvalidArgumentException('Age must be integer'); |
343
|
|
|
} |
344
|
|
|
if ($country !== null && !is_string($country)) { |
345
|
|
|
throw new \InvalidArgumentException('Country must be string'); |
346
|
|
|
} |
347
|
|
|
if ($socialType !== null && !is_string($socialType)) { |
348
|
|
|
throw new \InvalidArgumentException('Social type must be string'); |
349
|
|
|
} |
350
|
|
|
if ($registrationTimestamp !== null && !is_int($registrationTimestamp)) { |
351
|
|
|
throw new \InvalidArgumentException('Registration timestamp must be integer'); |
352
|
|
|
} |
353
|
|
|
if ($loginTimeStamp !== null && !is_int($loginTimeStamp)) { |
354
|
|
|
throw new \InvalidArgumentException('Login timestamp must be integer'); |
355
|
|
|
} |
356
|
|
|
if ($confirmationTimeStamp !== null && !is_int($confirmationTimeStamp)) { |
357
|
|
|
throw new \InvalidArgumentException('Confirmation timestamp must be integer'); |
358
|
|
|
} |
359
|
|
|
if ($emailConfirmed !== null && !is_bool($emailConfirmed)) { |
360
|
|
|
throw new \InvalidArgumentException('Email confirmed flag must be boolean'); |
361
|
|
|
} |
362
|
|
|
if ($phoneConfirmed !== null && !is_bool($phoneConfirmed)) { |
363
|
|
|
throw new \InvalidArgumentException('Phone confirmed flag must be boolean'); |
364
|
|
|
} |
365
|
|
|
if ($loginFailed !== null && !is_bool($loginFailed)) { |
366
|
|
|
throw new \InvalidArgumentException('Login failed flag must be boolean'); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
$this->replace('email', $email); |
370
|
|
|
$this->replace('user_merchant_id', $userId); |
371
|
|
|
$this->replace('phone', $phone); |
372
|
|
|
$this->replace('user_name', $userName); |
373
|
|
|
$this->replace('firstname', $firstName); |
374
|
|
|
$this->replace('lastname', $lastName); |
375
|
|
|
$this->replace('gender', $gender); |
376
|
|
|
$this->replace('age', $age); |
377
|
|
|
$this->replace('country', $country); |
378
|
|
|
$this->replace('social_type', $socialType); |
379
|
|
|
$this->replace('registration_timestamp', $registrationTimestamp); |
380
|
|
|
$this->replace('login_timestamp', $loginTimeStamp); |
381
|
|
|
$this->replace('confirmation_timestamp', $confirmationTimeStamp); |
382
|
|
|
$this->replace('email_confirmed', $emailConfirmed); |
|
|
|
|
383
|
|
|
$this->replace('phone_confirmed', $phoneConfirmed); |
|
|
|
|
384
|
|
|
$this->replace('login_failed', $loginFailed); |
|
|
|
|
385
|
|
|
|
386
|
|
|
return $this; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* Provides credit card data to envelope |
391
|
|
|
* |
392
|
|
|
* @param string $transactionId |
393
|
|
|
* @param string $transactionSource |
394
|
|
|
* @param string $transactionType |
395
|
|
|
* @param string $transactionMode |
396
|
|
|
* @param string $transactionTimestamp |
397
|
|
|
* @param string $transactionCurrency |
398
|
|
|
* @param string $transactionAmount |
399
|
|
|
* @param float $amountConverted |
400
|
|
|
* @param string $paymentMethod |
401
|
|
|
* @param string $paymentSystem |
402
|
|
|
* @param string $paymentMidName |
403
|
|
|
* |
404
|
|
|
* @return $this |
405
|
|
|
*/ |
406
|
|
|
public function addCCTransactionData( |
407
|
|
|
$transactionId, |
408
|
|
|
$transactionSource, |
409
|
|
|
$transactionType, |
410
|
|
|
$transactionMode, |
411
|
|
|
$transactionTimestamp, |
412
|
|
|
$transactionCurrency, |
413
|
|
|
$transactionAmount, |
414
|
|
|
$amountConverted = 0.0, |
415
|
|
|
$paymentMethod = '', |
416
|
|
|
$paymentSystem = '', |
417
|
|
|
$paymentMidName = '' |
418
|
|
|
) { |
419
|
|
|
if ($transactionId !== null && !is_string($transactionId)) { |
420
|
|
|
throw new \InvalidArgumentException('Transaction ID must be string'); |
421
|
|
|
} |
422
|
|
|
if ($transactionSource !== null && !is_string($transactionSource)) { |
423
|
|
|
throw new \InvalidArgumentException('Transaction source must be string'); |
424
|
|
|
} |
425
|
|
|
if ($transactionType !== null && !is_string($transactionType)) { |
426
|
|
|
throw new \InvalidArgumentException('Transaction type must be string'); |
427
|
|
|
} |
428
|
|
|
if ($transactionMode !== null && !is_string($transactionMode)) { |
429
|
|
|
throw new \InvalidArgumentException('Transaction mode must be string'); |
430
|
|
|
} |
431
|
|
|
if ($transactionTimestamp !== null && !is_int($transactionTimestamp)) { |
432
|
|
|
throw new \InvalidArgumentException('Transaction timestamp must be integer'); |
433
|
|
|
} |
434
|
|
|
if ($transactionAmount !== null && !is_int($transactionAmount) && !is_float($transactionAmount)) { |
435
|
|
|
throw new \InvalidArgumentException('Transaction amount must be float'); |
436
|
|
|
} |
437
|
|
|
if ($transactionCurrency !== null && !is_string($transactionCurrency)) { |
438
|
|
|
throw new \InvalidArgumentException('Transaction currency must be string'); |
439
|
|
|
} |
440
|
|
|
if ($paymentMethod !== null && !is_string($paymentMethod)) { |
441
|
|
|
throw new \InvalidArgumentException('Payment method must be string'); |
442
|
|
|
} |
443
|
|
|
if ($paymentSystem !== null && !is_string($paymentSystem)) { |
444
|
|
|
throw new \InvalidArgumentException('Payment system must be string'); |
445
|
|
|
} |
446
|
|
|
if ($paymentMidName !== null && !is_string($paymentMidName)) { |
447
|
|
|
throw new \InvalidArgumentException('Payment MID name must be string'); |
448
|
|
|
} |
449
|
|
|
if ($amountConverted !== null && !is_int($amountConverted) && !is_float($amountConverted)) { |
450
|
|
|
throw new \InvalidArgumentException('Transaction amount converted must be float'); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
$this->replace('transaction_id', $transactionId); |
454
|
|
|
$this->replace('transaction_source', $transactionSource); |
455
|
|
|
$this->replace('transaction_type', $transactionType); |
456
|
|
|
$this->replace('transaction_mode', $transactionMode); |
457
|
|
|
$this->replace('transaction_timestamp', $transactionTimestamp); |
458
|
|
|
$this->replace('transaction_amount', floatval($transactionAmount)); |
459
|
|
|
$this->replace('transaction_amount_converted', floatval($amountConverted)); |
460
|
|
|
$this->replace('transaction_currency', $transactionCurrency); |
461
|
|
|
$this->replace('payment_method', $paymentMethod); |
462
|
|
|
$this->replace('payment_system', $paymentSystem); |
463
|
|
|
$this->replace('payment_mid', $paymentMidName); |
464
|
|
|
|
465
|
|
|
return $this; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Provides Card data to envelope |
470
|
|
|
* |
471
|
|
|
* @param int $cardBin |
472
|
|
|
* @param string $cardLast4 |
473
|
|
|
* @param int $expirationMonth |
474
|
|
|
* @param int $expirationYear |
475
|
|
|
* @param string $cardId |
476
|
|
|
* |
477
|
|
|
* @return $this |
478
|
|
|
*/ |
479
|
|
|
public function addCardData( |
480
|
|
|
$cardBin, |
481
|
|
|
$cardLast4, |
482
|
|
|
$expirationMonth, |
483
|
|
|
$expirationYear, |
484
|
|
|
$cardId = '' |
485
|
|
|
) { |
486
|
|
|
if ($cardId !== null && !is_string($cardId)) { |
487
|
|
|
throw new \InvalidArgumentException('Card ID must be string'); |
488
|
|
|
} |
489
|
|
|
if ($cardBin !== null && !is_int($cardBin)) { |
490
|
|
|
throw new \InvalidArgumentException('Card BIN must be integer'); |
491
|
|
|
} |
492
|
|
|
if ($cardLast4 !== null && !is_string($cardLast4)) { |
493
|
|
|
throw new \InvalidArgumentException('Card last4 must be string'); |
494
|
|
|
} |
495
|
|
|
if ($expirationMonth !== null && !is_int($expirationMonth)) { |
496
|
|
|
throw new \InvalidArgumentException('Expiration month must be integer'); |
497
|
|
|
} |
498
|
|
|
if ($expirationYear !== null && !is_int($expirationYear)) { |
499
|
|
|
throw new \InvalidArgumentException('Expiration year must be integer'); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
$this->replace('card_id', $cardId); |
503
|
|
|
$this->replace('card_bin', $cardBin); |
504
|
|
|
$this->replace('card_last4', $cardLast4); |
505
|
|
|
$this->replace('expiration_month', $expirationMonth); |
506
|
|
|
$this->replace('expiration_year', $expirationYear); |
507
|
|
|
|
508
|
|
|
return $this; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* Provides billing data to envelope |
513
|
|
|
* |
514
|
|
|
* @param string $billingFirstName |
515
|
|
|
* @param string $billingLastName |
516
|
|
|
* @param string $billingFullName |
517
|
|
|
* @param string $billingCountry |
518
|
|
|
* @param string $billingState |
519
|
|
|
* @param string $billingCity |
520
|
|
|
* @param string $billingAddress |
521
|
|
|
* @param string $billingZip |
522
|
|
|
* |
523
|
|
|
* @return $this |
524
|
|
|
*/ |
525
|
|
|
public function addBillingData( |
526
|
|
|
$billingFirstName = '', |
527
|
|
|
$billingLastName = '', |
528
|
|
|
$billingFullName = '', |
529
|
|
|
$billingCountry = '', |
530
|
|
|
$billingState = '', |
531
|
|
|
$billingCity = '', |
532
|
|
|
$billingAddress = '', |
533
|
|
|
$billingZip = '' |
534
|
|
|
) { |
535
|
|
|
if ($billingFirstName !== null && !is_string($billingFirstName)) { |
536
|
|
|
throw new \InvalidArgumentException('Billing first name must be string'); |
537
|
|
|
} |
538
|
|
|
if ($billingLastName !== null && !is_string($billingLastName)) { |
539
|
|
|
throw new \InvalidArgumentException('Billing last name must be string'); |
540
|
|
|
} |
541
|
|
|
if ($billingFullName !== null && !is_string($billingFullName)) { |
542
|
|
|
throw new \InvalidArgumentException('Billing full name must be string'); |
543
|
|
|
} |
544
|
|
|
if ($billingCountry !== null && !is_string($billingCountry)) { |
545
|
|
|
throw new \InvalidArgumentException('Billing country name must be string'); |
546
|
|
|
} |
547
|
|
|
if ($billingState !== null && !is_string($billingState)) { |
548
|
|
|
throw new \InvalidArgumentException('Billing state must be string'); |
549
|
|
|
} |
550
|
|
|
if ($billingCity !== null && !is_string($billingCity)) { |
551
|
|
|
throw new \InvalidArgumentException('Billing city must be string'); |
552
|
|
|
} |
553
|
|
|
if ($billingAddress !== null && !is_string($billingAddress)) { |
554
|
|
|
throw new \InvalidArgumentException('Billing address must be string'); |
555
|
|
|
} |
556
|
|
|
if ($billingZip !== null && !is_string($billingZip)) { |
557
|
|
|
throw new \InvalidArgumentException('Billing zip must be string'); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
$this->replace('billing_firstname', $billingFirstName); |
561
|
|
|
$this->replace('billing_lastname', $billingLastName); |
562
|
|
|
$this->replace('billing_fullname', $billingFullName); |
563
|
|
|
$this->replace('billing_country', $billingCountry); |
564
|
|
|
$this->replace('billing_state', $billingState); |
565
|
|
|
$this->replace('billing_city', $billingCity); |
566
|
|
|
$this->replace('billing_address', $billingAddress); |
567
|
|
|
$this->replace('billing_zip', $billingZip); |
568
|
|
|
|
569
|
|
|
return $this; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
/** |
573
|
|
|
* Provides product information to envelope |
574
|
|
|
* |
575
|
|
|
* @param float $productQuantity |
576
|
|
|
* @param string $productName |
577
|
|
|
* @param string $productDescription |
578
|
|
|
* |
579
|
|
|
* @return $this |
580
|
|
|
*/ |
581
|
|
View Code Duplication |
public function addProductData( |
|
|
|
|
582
|
|
|
$productQuantity = 0.0, |
583
|
|
|
$productName = '', |
584
|
|
|
$productDescription = '' |
585
|
|
|
) { |
586
|
|
|
if ($productQuantity !== null && !is_int($productQuantity) && !is_float($productQuantity)) { |
587
|
|
|
throw new \InvalidArgumentException('Product quantity must be int or float'); |
588
|
|
|
} |
589
|
|
|
if ($productName !== null && !is_string($productName)) { |
590
|
|
|
throw new \InvalidArgumentException('Product name must be string'); |
591
|
|
|
} |
592
|
|
|
if ($productDescription !== null && !is_string($productDescription)) { |
593
|
|
|
throw new \InvalidArgumentException('Product description must be string'); |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
$this->replace('product_quantity', $productQuantity); |
597
|
|
|
$this->replace('product_name', $productName); |
598
|
|
|
$this->replace('product_description', $productDescription); |
599
|
|
|
|
600
|
|
|
return $this; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Adds custom data field to envelope |
605
|
|
|
* |
606
|
|
|
* @param string $name |
607
|
|
|
* @param string $value |
608
|
|
|
* |
609
|
|
|
* @return $this |
610
|
|
|
*/ |
611
|
|
|
public function addCustomField($name, $value) |
612
|
|
|
{ |
613
|
|
|
if (!is_string($name)) { |
614
|
|
|
throw new \InvalidArgumentException('Custom field name must be string'); |
615
|
|
|
} |
616
|
|
|
if (!is_string($value)) { |
617
|
|
|
throw new \InvalidArgumentException('Custom field value must be string'); |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
if (strlen($name) < 8 || substr($name, 0, 7) !== 'custom_') { |
621
|
|
|
$name = 'custom_' . $name; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
$this->replace($name, $value); |
625
|
|
|
return $this; |
626
|
|
|
} |
627
|
|
|
} |
628
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.