Passed
Push — master ( 7a1ddd...97e541 )
by Steeven
54s queued 10s
created
src/Rajaongkir.php 2 patches
Indentation   +800 added lines, -800 removed lines patch added patch discarded remove patch
@@ -44,804 +44,804 @@
 block discarded – undo
44 44
  * @package Steevenz
45 45
  */
46 46
 class Rajaongkir {
47
-	use ErrorCollectorTrait;
48
-
49
-	/**
50
-	 * Constant Account Type
51
-	 *
52
-	 * @access  public
53
-	 * @type    string
54
-	 */
55
-	const ACCOUNT_STARTER = 'starter';
56
-	const ACCOUNT_BASIC = 'basic';
57
-	const ACCOUNT_PRO = 'pro';
58
-
59
-	/**
60
-	 * Rajaongkir::$accountType
61
-	 *
62
-	 * Rajaongkir Account Type.
63
-	 *
64
-	 * @access  protected
65
-	 * @type    string
66
-	 */
67
-	protected $accountType = 'starter';
68
-
69
-	/**
70
-	 * Rajaongkir::$apiKey
71
-	 *
72
-	 * Rajaongkir API key.
73
-	 *
74
-	 * @access  protected
75
-	 * @type    string
76
-	 */
77
-	protected $apiKey = null;
78
-
79
-	/**
80
-	 * List of Supported Account Types
81
-	 *
82
-	 * @access  protected
83
-	 * @type    array
84
-	 */
85
-	protected $supportedAccountTypes = [
86
-		'starter',
87
-		'basic',
88
-		'pro',
89
-	];
90
-
91
-	/**
92
-	 * Supported Couriers
93
-	 *
94
-	 * @access  protected
95
-	 * @type    array
96
-	 */
97
-	protected $supportedCouriers = [
98
-		'starter' => [
99
-			'jne',
100
-			'pos',
101
-			'tiki',
102
-		],
103
-		'basic'   => [
104
-			'jne',
105
-			'pos',
106
-			'tiki',
107
-			'pcp',
108
-			'esl',
109
-			'rpx',
110
-		],
111
-		'pro'     => [
112
-			'jne',
113
-			'pos',
114
-			'tiki',
115
-			'rpx',
116
-			'pandu',
117
-			'wahana',
118
-			'sicepat',
119
-			'jnt',
120
-			'pahala',
121
-			'sap',
122
-			'jet',
123
-			'indah',
124
-			'dse',
125
-			'slis',
126
-			'first',
127
-			'ncs',
128
-			'star',
129
-			'ninja',
130
-			'lion',
131
-			'idl',
132
-			'rex',
133
-			'ide',
134
-			'sentral'
135
-		],
136
-	];
137
-
138
-	/**
139
-	 * Rajaongkir::$supportedWaybills
140
-	 *
141
-	 * Rajaongkir supported couriers waybills.
142
-	 *
143
-	 * @access  protected
144
-	 * @type    array
145
-	 */
146
-	protected $supportedWayBills = [
147
-		'starter' => [],
148
-		'basic'   => [
149
-			'jne',
150
-		],
151
-		'pro'     => [
152
-			'jne',
153
-			'pos',
154
-			'tiki',
155
-			'pcp',
156
-			'rpx',
157
-			'wahana',
158
-			'sicepat',
159
-			'j&t',
160
-			'sap',
161
-			'jet',
162
-			'dse',
163
-			'first',
164
-		],
165
-	];
166
-
167
-	/**
168
-	 * Rajaongkir::$couriersList
169
-	 *
170
-	 * Rajaongkir courier list.
171
-	 *
172
-	 * @access  protected
173
-	 * @type array
174
-	 */
175
-	protected $couriersList = [
176
-		'jne'       => 'Jalur Nugraha Ekakurir (JNE)',
177
-		'pos'       => 'POS Indonesia (POS)',
178
-		'tiki'      => 'Citra Van Titipan Kilat (TIKI)',
179
-		'pcp'       => 'Priority Cargo and Package (PCP)',
180
-		'esl'       => 'Eka Sari Lorena (ESL)',
181
-		'rpx'       => 'RPX Holding (RPX)',
182
-		'pandu'     => 'Pandu Logistics (PANDU)',
183
-		'wahana'    => 'Wahana Prestasi Logistik (WAHANA)',
184
-		'sicepat'   => 'SiCepat Express (SICEPAT)',
185
-		'j&t'       => 'J&T Express (J&T)',
186
-		'pahala'    => 'Pahala Kencana Express (PAHALA)',
187
-		'cahaya'    => 'Cahaya Logistik (CAHAYA)',
188
-		'sap'       => 'SAP Express (SAP)',
189
-		'jet'       => 'JET Express (JET)',
190
-		'indah'     => 'Indah Logistic (INDAH)',
191
-		'slis'      => 'Solusi Express (SLIS)',
192
-		'expedito*' => 'Expedito*',
193
-		'dse'       => '21 Express (DSE)',
194
-		'first'     => 'First Logistics (FIRST)',
195
-		'ncs'       => 'Nusantara Card Semesta (NCS)',
196
-		'star'      => 'Star Cargo (STAR)',
197
-	];
198
-
199
-	/**
200
-	 * Rajaongkir::$response
201
-	 *
202
-	 * Rajaongkir response.
203
-	 *
204
-	 * @access  protected
205
-	 * @type    mixed
206
-	 */
207
-	protected $response;
208
-
209
-	// ------------------------------------------------------------------------
210
-
211
-	/**
212
-	 * Rajaongkir::__construct
213
-	 *
214
-	 * @access  public
215
-	 * @throws  \InvalidArgumentException
216
-	 */
217
-	public function __construct( $apiKey = null, $accountType = null ) {
218
-		if ( isset( $apiKey ) ) {
219
-			if ( is_array( $apiKey ) ) {
220
-				if ( isset( $apiKey['api_key'] ) ) {
221
-					$this->apiKey = $apiKey['api_key'];
222
-				}
223
-
224
-				if ( isset( $apiKey['account_type'] ) ) {
225
-					$accountType = $apiKey['account_type'];
226
-				}
227
-			} elseif ( is_string( $apiKey ) ) {
228
-				$this->apiKey = $apiKey;
229
-			}
230
-		}
231
-
232
-		if ( isset( $accountType ) ) {
233
-			$this->setAccountType( $accountType );
234
-		}
235
-	}
236
-
237
-	// ------------------------------------------------------------------------
238
-
239
-	/**
240
-	 * Rajaongkir::setApiKey
241
-	 *
242
-	 * Set Rajaongkir API Key.
243
-	 *
244
-	 * @param string $apiKey Rajaongkir API Key
245
-	 *
246
-	 * @access  public
247
-	 * @return  static
248
-	 */
249
-	public function setApiKey( $apiKey ) {
250
-		$this->apiKey = $apiKey;
251
-
252
-		return $this;
253
-	}
254
-
255
-	// ------------------------------------------------------------------------
256
-
257
-	/**
258
-	 * Rajaongkir::setAccountType
259
-	 *
260
-	 * Set Rajaongkir account type.
261
-	 *
262
-	 * @param string $accountType RajaOngkir Account Type, can be starter, basic or pro
263
-	 *
264
-	 * @access  public
265
-	 * @return  static
266
-	 * @throws  \InvalidArgumentException
267
-	 */
268
-	public function setAccountType( $accountType ) {
269
-		$accountType = strtolower( $accountType );
270
-
271
-		if ( in_array( $accountType, $this->supportedAccountTypes ) ) {
272
-			$this->accountType = $accountType;
273
-		} else {
274
-			throw new \InvalidArgumentException( 'Rajaongkir: Invalid Account Type' );
275
-		}
276
-
277
-		return $this;
278
-	}
279
-
280
-	// ------------------------------------------------------------------------
281
-
282
-	/**
283
-	 * Rajaongkir::request
284
-	 *
285
-	 * Curl request API caller.
286
-	 *
287
-	 * @param string $path
288
-	 * @param array $params
289
-	 * @param string $type
290
-	 *
291
-	 * @access  protected
292
-	 * @return  array|bool Returns FALSE if failed.
293
-	 */
294
-	protected function request( $path, $params = [], $type = 'GET' ) {
295
-		$apiUrl = 'https://api.rajaongkir.com';
296
-
297
-		switch ( $this->accountType ) {
298
-			default:
299
-			case 'starter':
300
-				$path = 'starter/' . $path;
301
-				break;
302
-
303
-			case 'basic':
304
-				$path = 'basic/' . $path;
305
-				break;
306
-
307
-			case 'pro':
308
-				$apiUrl = 'https://pro.rajaongkir.com';
309
-				$path   = 'api/' . $path;
310
-				break;
311
-		}
312
-
313
-		$uri     = ( new Uri( $apiUrl ) )->withPath( $path );
314
-		$request = new Curl\Request();
315
-		$request->setHeaders( [
316
-			'key' => $this->apiKey,
317
-		] );
318
-
319
-		switch ( $type ) {
320
-			default:
321
-			case 'GET':
322
-				$this->response = $request->setUri( $uri )->get( $params );
323
-				break;
324
-
325
-			case 'POST':
326
-				$request->addHeader( 'content-type', 'application/x-www-form-urlencoded' );
327
-				$this->response = $request->setUri( $uri )->post( $params );
328
-				break;
329
-		}
330
-
331
-		// Try to get curl error
332
-		if ( false !== ( $error = $this->response->getError() ) ) {
333
-			$this->addErrors( $error->getArrayCopy() );
334
-		} else {
335
-			$body = $this->response->getBody();
336
-
337
-			if ( $body instanceof \DOMDocument ) {
338
-				$this->errors[404] = 'Page Not Found!';
339
-			} else {
340
-				$body   = $body->rajaongkir;
341
-				$status = $body['status'];
342
-
343
-				if ( $status['code'] == 200 ) {
344
-					if ( isset( $body['results'] ) ) {
345
-						if ( count( $body['results'] ) == 1 && isset( $body['results'][0] ) ) {
346
-							return $body['results'][0];
347
-						} elseif ( count( $body['results'] ) ) {
348
-							return $body['results'];
349
-						}
350
-					} elseif ( isset( $body['result'] ) ) {
351
-						return $body['result'];
352
-					}
353
-				} else {
354
-					$this->errors[ $status['code'] ] = $status['description'];
355
-				}
356
-			}
357
-		}
358
-
359
-		return false;
360
-	}
361
-
362
-	// ------------------------------------------------------------------------
363
-
364
-	/**
365
-	 * Rajaongkir::getCouriersList
366
-	 *
367
-	 * Get list of supported couriers.
368
-	 *
369
-	 * @access  public
370
-	 * @return  array|bool Returns FALSE if failed.
371
-	 */
372
-	public function getCouriersList() {
373
-		return $this->couriersList;
374
-	}
375
-
376
-	// ------------------------------------------------------------------------
377
-
378
-	/**
379
-	 * Rajaongkir::getProvinces
380
-	 *
381
-	 * Get list of provinces.
382
-	 *
383
-	 * @access  public
384
-	 * @return  array|bool Returns FALSE if failed.
385
-	 */
386
-	public function getProvinces() {
387
-		return $this->request( 'province' );
388
-	}
389
-
390
-	// ------------------------------------------------------------------------
391
-
392
-	/**
393
-	 * Rajaongkir::getProvince
394
-	 *
395
-	 * Get detail of single province.
396
-	 *
397
-	 * @param int $idProvince Province ID
398
-	 *
399
-	 * @access  public
400
-	 * @return  array|bool Returns FALSE if failed.
401
-	 */
402
-	public function getProvince( $idProvince ) {
403
-		return $this->request( 'province', [ 'id' => $idProvince ] );
404
-	}
405
-
406
-	// ------------------------------------------------------------------------
407
-
408
-	/**
409
-	 * Rajaongkir::getCities
410
-	 *
411
-	 * Get list of province cities.
412
-	 *
413
-	 * @param int $idProvince Province ID
414
-	 *
415
-	 * @access  public
416
-	 * @return  array|bool Returns FALSE if failed.
417
-	 */
418
-	public function getCities( $idProvince = null ) {
419
-		$params = [];
420
-
421
-		if ( ! is_null( $idProvince ) ) {
422
-			$params['province'] = $idProvince;
423
-		}
424
-
425
-		return $this->request( 'city', $params );
426
-	}
427
-
428
-	// ------------------------------------------------------------------------
429
-
430
-	/**
431
-	 * Rajaongkir::getCity
432
-	 *
433
-	 * Get detail of single city.
434
-	 *
435
-	 * @param int $idCity City ID
436
-	 *
437
-	 * @access  public
438
-	 * @return  array|bool Returns FALSE if failed.
439
-	 */
440
-	public function getCity( $idCity ) {
441
-		return $this->request( 'city', [ 'id' => $idCity ] );
442
-	}
443
-
444
-	// ------------------------------------------------------------------------
445
-
446
-	/**
447
-	 * Rajaongkir::getSubdistricts
448
-	 *
449
-	 * Get list of city subdisctricts.
450
-	 *
451
-	 * @param int $idCity City ID
452
-	 *
453
-	 * @access  public
454
-	 * @return  array|bool Returns FALSE if failed.
455
-	 */
456
-	public function getSubdistricts( $idCity ) {
457
-		if ( $this->accountType === 'starter' ) {
458
-			$this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.';
459
-
460
-			return false;
461
-		} elseif ( $this->accountType === 'basic' ) {
462
-			$this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.';
463
-
464
-			return false;
465
-		}
466
-
467
-		return $this->request( 'subdistrict', [ 'city' => $idCity ] );
468
-	}
469
-
470
-	// ------------------------------------------------------------------------
471
-
472
-	/**
473
-	 * Rajaongkir::getSubdistrict
474
-	 *
475
-	 * Get detail of single subdistrict.
476
-	 *
477
-	 * @param int $idSubdistrict Subdistrict ID
478
-	 *
479
-	 * @access  public
480
-	 * @return  array|bool Returns FALSE if failed.
481
-	 */
482
-	public function getSubdistrict( $idSubdistrict ) {
483
-		if ( $this->accountType === 'starter' ) {
484
-			$this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.';
485
-
486
-			return false;
487
-		} elseif ( $this->accountType === 'basic' ) {
488
-			$this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.';
489
-
490
-			return false;
491
-		}
492
-
493
-		return $this->request( 'subdistrict', [ 'id' => $idSubdistrict ] );
494
-	}
495
-
496
-	// ------------------------------------------------------------------------
497
-
498
-	/**
499
-	 * Rajaongkir::getInternationalOrigins
500
-	 *
501
-	 * Get list of supported international origins.
502
-	 *
503
-	 * @param int $idProvince Province ID
504
-	 *
505
-	 * @access  public
506
-	 * @return  array|bool Returns FALSE if failed.
507
-	 */
508
-	public function getInternationalOrigins( $idProvince = null ) {
509
-		if ( $this->accountType === 'starter' ) {
510
-			$this->errors[301] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.';
511
-
512
-			return false;
513
-		}
514
-
515
-		$params = [];
516
-
517
-		if ( isset( $idProvince ) ) {
518
-			$params['province'] = $idProvince;
519
-		}
520
-
521
-		return $this->request( 'v2/internationalOrigin', $params );
522
-	}
523
-
524
-	// ------------------------------------------------------------------------
525
-
526
-	/**
527
-	 * Rajaongkir::getInternationalOrigin
528
-	 *
529
-	 * Get list of supported international origins by city and province.
530
-	 *
531
-	 * @param int $idCity City ID
532
-	 * @param int $idProvince Province ID
533
-	 *
534
-	 * @access  public
535
-	 * @return  array|bool Returns FALSE if failed.
536
-	 */
537
-	public function getInternationalOrigin( $idCity = null, $idProvince = null ) {
538
-		if ( $this->accountType === 'starter' ) {
539
-			$this->errors[301] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.';
540
-
541
-			return false;
542
-		}
543
-
544
-		if ( isset( $idCity ) ) {
545
-			$params['id'] = $idCity;
546
-		}
547
-
548
-		if ( isset( $idProvince ) ) {
549
-			$params['province'] = $idProvince;
550
-		}
551
-
552
-		return $this->request( 'v2/internationalOrigin', $params );
553
-	}
554
-
555
-	// ------------------------------------------------------------------------
556
-
557
-	/**
558
-	 * Rajaongkir::getInternationalDestinations
559
-	 *
560
-	 * Get list of international destinations.
561
-	 *
562
-	 * @param int $id_country Country ID
563
-	 *
564
-	 * @access  public
565
-	 * @return  array|bool Returns FALSE if failed.
566
-	 */
567
-	public function getInternationalDestinations() {
568
-		if ( $this->accountType === 'starter' ) {
569
-			$this->errors[301] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.';
570
-
571
-			return false;
572
-		}
573
-
574
-		return $this->request( 'v2/internationalDestination' );
575
-	}
576
-
577
-	// ------------------------------------------------------------------------
578
-
579
-	/**
580
-	 * Rajaongkir::getInternationalDestination
581
-	 *
582
-	 * Get International Destination
583
-	 *
584
-	 * @param int $idCountry Country ID
585
-	 *
586
-	 * @access  public
587
-	 * @return  array|bool Returns FALSE if failed.
588
-	 */
589
-	public function getInternationalDestination( $idCountry = null ) {
590
-		if ( $this->accountType === 'starter' ) {
591
-			$this->errors[301] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.';
592
-
593
-			return false;
594
-		}
595
-
596
-		$params = [];
597
-
598
-		if ( isset( $idCountry ) ) {
599
-			$params['id'] = $idCountry;
600
-		}
601
-
602
-		return $this->request( 'v2/internationalDestination', $params );
603
-	}
604
-
605
-	// ------------------------------------------------------------------------
606
-
607
-	/**
608
-	 * Rajaongkir::getCost
609
-	 *
610
-	 * Get cost calculation.
611
-	 *
612
-	 * @param array $origin City, District or Subdistrict Origin
613
-	 * @param array $destination City, District or Subdistrict Destination
614
-	 * @param array $metrics Array of Specification
615
-	 *                                  weight      int     weight in gram (required)
616
-	 *                                  length      number  package length dimension
617
-	 *                                  width       number  package width dimension
618
-	 *                                  height      number  package height dimension
619
-	 *                                  diameter    number  package diameter
620
-	 * @param string $courier Courier Code
621
-	 *
622
-	 * @access   public
623
-	 * @return  array|bool Returns FALSE if failed.
624
-	 * @see      http://rajaongkir.com/dokumentasi/pro
625
-	 *
626
-	 * @example
627
-	 * $rajaongkir->getCost(
628
-	 *      ['city' => 1],
629
-	 *      ['subdistrict' => 12],
630
-	 *      ['weight' => 100, 'length' => 100, 'width' => 100, 'height' => 100, 'diameter' => 100],
631
-	 *      'jne'
632
-	 * );
633
-	 *
634
-	 */
635
-	public function getCost( array $origin, array $destination, $metrics, $courier ) {
636
-		$params['courier'] = strtolower( $courier );
637
-
638
-		$params['originType']      = strtolower( key( $origin ) );
639
-		$params['destinationType'] = strtolower( key( $destination ) );
640
-
641
-		if ( $params['originType'] !== 'city' ) {
642
-			$params['originType'] = 'subdistrict';
643
-		}
644
-
645
-		if ( ! in_array( $params['destinationType'], [ 'city', 'country' ] ) ) {
646
-			$params['destinationType'] = 'subdistrict';
647
-		}
648
-
649
-		if ( is_array( $metrics ) ) {
650
-			if ( ! isset( $metrics['weight'] ) and
651
-			     isset( $metrics['length'] ) and
652
-			     isset( $metrics['width'] ) and
653
-			     isset( $metrics['height'] )
654
-			) {
655
-				$metrics['weight'] = ( ( $metrics['length'] * $metrics['width'] * $metrics['height'] ) / 6000 ) * 1000;
656
-			} elseif ( isset( $metrics['weight'] ) and
657
-			           isset( $metrics['length'] ) and
658
-			           isset( $metrics['width'] ) and
659
-			           isset( $metrics['height'] )
660
-			) {
661
-				$weight = ( ( $metrics['length'] * $metrics['width'] * $metrics['height'] ) / 6000 ) * 1000;
662
-
663
-				if ( $weight > $metrics['weight'] ) {
664
-					$metrics['weight'] = $weight;
665
-				}
666
-			}
667
-
668
-			foreach ( $metrics as $key => $value ) {
669
-				$params[ $key ] = $value;
670
-			}
671
-		} elseif ( is_numeric( $metrics ) ) {
672
-			$params['weight'] = $metrics;
673
-		}
674
-
675
-		switch ( $this->accountType ) {
676
-			case 'starter':
677
-
678
-				if ( $params['destinationType'] === 'country' ) {
679
-					$this->errors[301] = 'Unsupported International Destination. Tipe akun starter tidak mendukung pengecekan destinasi international.';
680
-
681
-					return false;
682
-				} elseif ( $params['originType'] === 'subdistrict' or $params['destinationType'] === 'subdistrict' ) {
683
-					$this->errors[302] = 'Unsupported Subdistrict Origin-Destination. Tipe akun starter tidak mendukung pengecekan ongkos kirim sampai kecamatan.';
684
-
685
-					return false;
686
-				}
687
-
688
-				if ( ! isset( $params['weight'] ) and
689
-				     isset( $params['length'] ) and
690
-				     isset( $params['width'] ) and
691
-				     isset( $params['height'] )
692
-				) {
693
-					$this->errors[304] = 'Unsupported Dimension. Tipe akun starter tidak mendukung pengecekan biaya kirim berdasarkan dimensi.';
694
-
695
-					return false;
696
-				} elseif ( isset( $params['weight'] ) and $params['weight'] > 30000 ) {
697
-					$this->errors[305] = 'Unsupported Weight. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).';
698
-
699
-					return false;
700
-				}
701
-
702
-				if ( ! in_array( $params['courier'], $this->supportedCouriers[ $this->accountType ] ) ) {
703
-					$this->errors[303] = 'Unsupported Courier. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[ $courier ] . '.';
704
-
705
-					return false;
706
-				}
707
-
708
-				break;
709
-
710
-			case 'basic':
711
-
712
-				if ( $params['originType'] === 'subdistrict' or $params['destinationType'] === 'subdistrict' ) {
713
-					$this->errors[302] = 'Unsupported Subdistrict Origin-Destination. Tipe akun basic tidak mendukung pengecekan ongkos kirim sampai kecamatan.';
714
-
715
-					return false;
716
-				}
717
-
718
-				if ( ! isset( $params['weight'] ) and
719
-				     isset( $params['length'] ) and
720
-				     isset( $params['width'] ) and
721
-				     isset( $params['height'] )
722
-				) {
723
-					$this->errors[304] = 'Unsupported Dimension. Tipe akun basic tidak mendukung pengecekan biaya kirim berdasarkan dimensi.';
724
-
725
-					return false;
726
-				} elseif ( isset( $params['weight'] ) and $params['weight'] > 30000 ) {
727
-					$this->errors[305] = 'Unsupported Weight. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).';
728
-
729
-					return false;
730
-				} elseif ( isset( $params['weight'] ) and $params['weight'] < 30000 ) {
731
-					unset( $params['length'], $params['width'], $params['height'] );
732
-				}
733
-
734
-				if ( ! in_array( $params['courier'], $this->supportedCouriers[ $this->accountType ] ) ) {
735
-					$this->errors[303] = 'Unsupported Courier. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[ $courier ] . '.';
736
-
737
-					return false;
738
-				}
739
-
740
-				break;
741
-		}
742
-
743
-		$params['origin']      = $origin[ key( $origin ) ];
744
-		$params['destination'] = $destination[ key( $destination ) ];
745
-
746
-		$path = key( $destination ) === 'country' ? 'internationalCost' : 'cost';
747
-
748
-		return $this->request( $path, $params, 'POST' );
749
-	}
750
-
751
-	// ------------------------------------------------------------------------
752
-
753
-	/**
754
-	 * Rajaongkir::getWaybill
755
-	 *
756
-	 * Get detail of waybill.
757
-	 *
758
-	 * @param int $idWaybill Receipt ID
759
-	 * @param null|string $courier Courier Code
760
-	 *
761
-	 * @access  public
762
-	 * @return  array|bool Returns FALSE if failed.
763
-	 */
764
-	public function getWaybill( $idWaybill, $courier ) {
765
-		$courier = strtolower( $courier );
766
-
767
-		if ( in_array( $courier, $this->supportedWayBills[ $this->accountType ] ) ) {
768
-			return $this->request( 'waybill', [
769
-				'key'     => $this->apiKey,
770
-				'waybill' => $idWaybill,
771
-				'courier' => $courier,
772
-			], 'POST' );
773
-		}
774
-
775
-		return false;
776
-	}
777
-
778
-	// ------------------------------------------------------------------------
779
-
780
-	/**
781
-	 * Rajaongkir::getCurrency
782
-	 *
783
-	 * Get Rajaongkir currency.
784
-	 *
785
-	 * @access  public
786
-	 * @return  array|bool Returns FALSE if failed.
787
-	 */
788
-	public function getCurrency() {
789
-		if ( $this->accountType !== 'starter' ) {
790
-			return $this->request( 'currency' );
791
-		}
792
-
793
-		$this->errors[301] = 'Unsupported Get Currency. Tipe akun starter tidak mendukung pengecekan currency.';
794
-
795
-		return false;
796
-	}
797
-
798
-	// ------------------------------------------------------------------------
799
-
800
-	/**
801
-	 * Rajaongkir::getSupportedCouriers
802
-	 *
803
-	 * Gets list of supported couriers by your account.
804
-	 *
805
-	 * @return array|bool Returns FALSE if failed.
806
-	 */
807
-	public function getSupportedCouriers() {
808
-		if ( isset( $this->supportedCouriers[ $this->accountType ] ) ) {
809
-			return $this->supportedCouriers[ $this->accountType ];
810
-		}
811
-
812
-		return false;
813
-	}
814
-
815
-	// ------------------------------------------------------------------------
816
-
817
-	/**
818
-	 * Rajaongkir::getSupportedWayBills
819
-	 *
820
-	 * Gets list of supported way bills based on account type.
821
-	 *
822
-	 * @return array|bool Returns FALSE if failed.
823
-	 */
824
-	public function getSupportedWayBills() {
825
-		if ( isset( $this->supportedWayBills[ $this->accountType ] ) ) {
826
-			return $this->supportedWayBills[ $this->accountType ];
827
-		}
828
-
829
-		return false;
830
-	}
831
-
832
-	// ------------------------------------------------------------------------
833
-
834
-	/**
835
-	 * Rajaongkir::getResponse
836
-	 *
837
-	 * Get original response object.
838
-	 *
839
-	 * @param string $offset Response Offset Object
840
-	 *
841
-	 * @access  public
842
-	 * @return  \O2System\Curl\Response|bool Returns FALSE if failed.
843
-	 */
844
-	public function getResponse() {
845
-		return $this->response;
846
-	}
47
+    use ErrorCollectorTrait;
48
+
49
+    /**
50
+     * Constant Account Type
51
+     *
52
+     * @access  public
53
+     * @type    string
54
+     */
55
+    const ACCOUNT_STARTER = 'starter';
56
+    const ACCOUNT_BASIC = 'basic';
57
+    const ACCOUNT_PRO = 'pro';
58
+
59
+    /**
60
+     * Rajaongkir::$accountType
61
+     *
62
+     * Rajaongkir Account Type.
63
+     *
64
+     * @access  protected
65
+     * @type    string
66
+     */
67
+    protected $accountType = 'starter';
68
+
69
+    /**
70
+     * Rajaongkir::$apiKey
71
+     *
72
+     * Rajaongkir API key.
73
+     *
74
+     * @access  protected
75
+     * @type    string
76
+     */
77
+    protected $apiKey = null;
78
+
79
+    /**
80
+     * List of Supported Account Types
81
+     *
82
+     * @access  protected
83
+     * @type    array
84
+     */
85
+    protected $supportedAccountTypes = [
86
+        'starter',
87
+        'basic',
88
+        'pro',
89
+    ];
90
+
91
+    /**
92
+     * Supported Couriers
93
+     *
94
+     * @access  protected
95
+     * @type    array
96
+     */
97
+    protected $supportedCouriers = [
98
+        'starter' => [
99
+            'jne',
100
+            'pos',
101
+            'tiki',
102
+        ],
103
+        'basic'   => [
104
+            'jne',
105
+            'pos',
106
+            'tiki',
107
+            'pcp',
108
+            'esl',
109
+            'rpx',
110
+        ],
111
+        'pro'     => [
112
+            'jne',
113
+            'pos',
114
+            'tiki',
115
+            'rpx',
116
+            'pandu',
117
+            'wahana',
118
+            'sicepat',
119
+            'jnt',
120
+            'pahala',
121
+            'sap',
122
+            'jet',
123
+            'indah',
124
+            'dse',
125
+            'slis',
126
+            'first',
127
+            'ncs',
128
+            'star',
129
+            'ninja',
130
+            'lion',
131
+            'idl',
132
+            'rex',
133
+            'ide',
134
+            'sentral'
135
+        ],
136
+    ];
137
+
138
+    /**
139
+     * Rajaongkir::$supportedWaybills
140
+     *
141
+     * Rajaongkir supported couriers waybills.
142
+     *
143
+     * @access  protected
144
+     * @type    array
145
+     */
146
+    protected $supportedWayBills = [
147
+        'starter' => [],
148
+        'basic'   => [
149
+            'jne',
150
+        ],
151
+        'pro'     => [
152
+            'jne',
153
+            'pos',
154
+            'tiki',
155
+            'pcp',
156
+            'rpx',
157
+            'wahana',
158
+            'sicepat',
159
+            'j&t',
160
+            'sap',
161
+            'jet',
162
+            'dse',
163
+            'first',
164
+        ],
165
+    ];
166
+
167
+    /**
168
+     * Rajaongkir::$couriersList
169
+     *
170
+     * Rajaongkir courier list.
171
+     *
172
+     * @access  protected
173
+     * @type array
174
+     */
175
+    protected $couriersList = [
176
+        'jne'       => 'Jalur Nugraha Ekakurir (JNE)',
177
+        'pos'       => 'POS Indonesia (POS)',
178
+        'tiki'      => 'Citra Van Titipan Kilat (TIKI)',
179
+        'pcp'       => 'Priority Cargo and Package (PCP)',
180
+        'esl'       => 'Eka Sari Lorena (ESL)',
181
+        'rpx'       => 'RPX Holding (RPX)',
182
+        'pandu'     => 'Pandu Logistics (PANDU)',
183
+        'wahana'    => 'Wahana Prestasi Logistik (WAHANA)',
184
+        'sicepat'   => 'SiCepat Express (SICEPAT)',
185
+        'j&t'       => 'J&T Express (J&T)',
186
+        'pahala'    => 'Pahala Kencana Express (PAHALA)',
187
+        'cahaya'    => 'Cahaya Logistik (CAHAYA)',
188
+        'sap'       => 'SAP Express (SAP)',
189
+        'jet'       => 'JET Express (JET)',
190
+        'indah'     => 'Indah Logistic (INDAH)',
191
+        'slis'      => 'Solusi Express (SLIS)',
192
+        'expedito*' => 'Expedito*',
193
+        'dse'       => '21 Express (DSE)',
194
+        'first'     => 'First Logistics (FIRST)',
195
+        'ncs'       => 'Nusantara Card Semesta (NCS)',
196
+        'star'      => 'Star Cargo (STAR)',
197
+    ];
198
+
199
+    /**
200
+     * Rajaongkir::$response
201
+     *
202
+     * Rajaongkir response.
203
+     *
204
+     * @access  protected
205
+     * @type    mixed
206
+     */
207
+    protected $response;
208
+
209
+    // ------------------------------------------------------------------------
210
+
211
+    /**
212
+     * Rajaongkir::__construct
213
+     *
214
+     * @access  public
215
+     * @throws  \InvalidArgumentException
216
+     */
217
+    public function __construct( $apiKey = null, $accountType = null ) {
218
+        if ( isset( $apiKey ) ) {
219
+            if ( is_array( $apiKey ) ) {
220
+                if ( isset( $apiKey['api_key'] ) ) {
221
+                    $this->apiKey = $apiKey['api_key'];
222
+                }
223
+
224
+                if ( isset( $apiKey['account_type'] ) ) {
225
+                    $accountType = $apiKey['account_type'];
226
+                }
227
+            } elseif ( is_string( $apiKey ) ) {
228
+                $this->apiKey = $apiKey;
229
+            }
230
+        }
231
+
232
+        if ( isset( $accountType ) ) {
233
+            $this->setAccountType( $accountType );
234
+        }
235
+    }
236
+
237
+    // ------------------------------------------------------------------------
238
+
239
+    /**
240
+     * Rajaongkir::setApiKey
241
+     *
242
+     * Set Rajaongkir API Key.
243
+     *
244
+     * @param string $apiKey Rajaongkir API Key
245
+     *
246
+     * @access  public
247
+     * @return  static
248
+     */
249
+    public function setApiKey( $apiKey ) {
250
+        $this->apiKey = $apiKey;
251
+
252
+        return $this;
253
+    }
254
+
255
+    // ------------------------------------------------------------------------
256
+
257
+    /**
258
+     * Rajaongkir::setAccountType
259
+     *
260
+     * Set Rajaongkir account type.
261
+     *
262
+     * @param string $accountType RajaOngkir Account Type, can be starter, basic or pro
263
+     *
264
+     * @access  public
265
+     * @return  static
266
+     * @throws  \InvalidArgumentException
267
+     */
268
+    public function setAccountType( $accountType ) {
269
+        $accountType = strtolower( $accountType );
270
+
271
+        if ( in_array( $accountType, $this->supportedAccountTypes ) ) {
272
+            $this->accountType = $accountType;
273
+        } else {
274
+            throw new \InvalidArgumentException( 'Rajaongkir: Invalid Account Type' );
275
+        }
276
+
277
+        return $this;
278
+    }
279
+
280
+    // ------------------------------------------------------------------------
281
+
282
+    /**
283
+     * Rajaongkir::request
284
+     *
285
+     * Curl request API caller.
286
+     *
287
+     * @param string $path
288
+     * @param array $params
289
+     * @param string $type
290
+     *
291
+     * @access  protected
292
+     * @return  array|bool Returns FALSE if failed.
293
+     */
294
+    protected function request( $path, $params = [], $type = 'GET' ) {
295
+        $apiUrl = 'https://api.rajaongkir.com';
296
+
297
+        switch ( $this->accountType ) {
298
+            default:
299
+            case 'starter':
300
+                $path = 'starter/' . $path;
301
+                break;
302
+
303
+            case 'basic':
304
+                $path = 'basic/' . $path;
305
+                break;
306
+
307
+            case 'pro':
308
+                $apiUrl = 'https://pro.rajaongkir.com';
309
+                $path   = 'api/' . $path;
310
+                break;
311
+        }
312
+
313
+        $uri     = ( new Uri( $apiUrl ) )->withPath( $path );
314
+        $request = new Curl\Request();
315
+        $request->setHeaders( [
316
+            'key' => $this->apiKey,
317
+        ] );
318
+
319
+        switch ( $type ) {
320
+            default:
321
+            case 'GET':
322
+                $this->response = $request->setUri( $uri )->get( $params );
323
+                break;
324
+
325
+            case 'POST':
326
+                $request->addHeader( 'content-type', 'application/x-www-form-urlencoded' );
327
+                $this->response = $request->setUri( $uri )->post( $params );
328
+                break;
329
+        }
330
+
331
+        // Try to get curl error
332
+        if ( false !== ( $error = $this->response->getError() ) ) {
333
+            $this->addErrors( $error->getArrayCopy() );
334
+        } else {
335
+            $body = $this->response->getBody();
336
+
337
+            if ( $body instanceof \DOMDocument ) {
338
+                $this->errors[404] = 'Page Not Found!';
339
+            } else {
340
+                $body   = $body->rajaongkir;
341
+                $status = $body['status'];
342
+
343
+                if ( $status['code'] == 200 ) {
344
+                    if ( isset( $body['results'] ) ) {
345
+                        if ( count( $body['results'] ) == 1 && isset( $body['results'][0] ) ) {
346
+                            return $body['results'][0];
347
+                        } elseif ( count( $body['results'] ) ) {
348
+                            return $body['results'];
349
+                        }
350
+                    } elseif ( isset( $body['result'] ) ) {
351
+                        return $body['result'];
352
+                    }
353
+                } else {
354
+                    $this->errors[ $status['code'] ] = $status['description'];
355
+                }
356
+            }
357
+        }
358
+
359
+        return false;
360
+    }
361
+
362
+    // ------------------------------------------------------------------------
363
+
364
+    /**
365
+     * Rajaongkir::getCouriersList
366
+     *
367
+     * Get list of supported couriers.
368
+     *
369
+     * @access  public
370
+     * @return  array|bool Returns FALSE if failed.
371
+     */
372
+    public function getCouriersList() {
373
+        return $this->couriersList;
374
+    }
375
+
376
+    // ------------------------------------------------------------------------
377
+
378
+    /**
379
+     * Rajaongkir::getProvinces
380
+     *
381
+     * Get list of provinces.
382
+     *
383
+     * @access  public
384
+     * @return  array|bool Returns FALSE if failed.
385
+     */
386
+    public function getProvinces() {
387
+        return $this->request( 'province' );
388
+    }
389
+
390
+    // ------------------------------------------------------------------------
391
+
392
+    /**
393
+     * Rajaongkir::getProvince
394
+     *
395
+     * Get detail of single province.
396
+     *
397
+     * @param int $idProvince Province ID
398
+     *
399
+     * @access  public
400
+     * @return  array|bool Returns FALSE if failed.
401
+     */
402
+    public function getProvince( $idProvince ) {
403
+        return $this->request( 'province', [ 'id' => $idProvince ] );
404
+    }
405
+
406
+    // ------------------------------------------------------------------------
407
+
408
+    /**
409
+     * Rajaongkir::getCities
410
+     *
411
+     * Get list of province cities.
412
+     *
413
+     * @param int $idProvince Province ID
414
+     *
415
+     * @access  public
416
+     * @return  array|bool Returns FALSE if failed.
417
+     */
418
+    public function getCities( $idProvince = null ) {
419
+        $params = [];
420
+
421
+        if ( ! is_null( $idProvince ) ) {
422
+            $params['province'] = $idProvince;
423
+        }
424
+
425
+        return $this->request( 'city', $params );
426
+    }
427
+
428
+    // ------------------------------------------------------------------------
429
+
430
+    /**
431
+     * Rajaongkir::getCity
432
+     *
433
+     * Get detail of single city.
434
+     *
435
+     * @param int $idCity City ID
436
+     *
437
+     * @access  public
438
+     * @return  array|bool Returns FALSE if failed.
439
+     */
440
+    public function getCity( $idCity ) {
441
+        return $this->request( 'city', [ 'id' => $idCity ] );
442
+    }
443
+
444
+    // ------------------------------------------------------------------------
445
+
446
+    /**
447
+     * Rajaongkir::getSubdistricts
448
+     *
449
+     * Get list of city subdisctricts.
450
+     *
451
+     * @param int $idCity City ID
452
+     *
453
+     * @access  public
454
+     * @return  array|bool Returns FALSE if failed.
455
+     */
456
+    public function getSubdistricts( $idCity ) {
457
+        if ( $this->accountType === 'starter' ) {
458
+            $this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.';
459
+
460
+            return false;
461
+        } elseif ( $this->accountType === 'basic' ) {
462
+            $this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.';
463
+
464
+            return false;
465
+        }
466
+
467
+        return $this->request( 'subdistrict', [ 'city' => $idCity ] );
468
+    }
469
+
470
+    // ------------------------------------------------------------------------
471
+
472
+    /**
473
+     * Rajaongkir::getSubdistrict
474
+     *
475
+     * Get detail of single subdistrict.
476
+     *
477
+     * @param int $idSubdistrict Subdistrict ID
478
+     *
479
+     * @access  public
480
+     * @return  array|bool Returns FALSE if failed.
481
+     */
482
+    public function getSubdistrict( $idSubdistrict ) {
483
+        if ( $this->accountType === 'starter' ) {
484
+            $this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.';
485
+
486
+            return false;
487
+        } elseif ( $this->accountType === 'basic' ) {
488
+            $this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.';
489
+
490
+            return false;
491
+        }
492
+
493
+        return $this->request( 'subdistrict', [ 'id' => $idSubdistrict ] );
494
+    }
495
+
496
+    // ------------------------------------------------------------------------
497
+
498
+    /**
499
+     * Rajaongkir::getInternationalOrigins
500
+     *
501
+     * Get list of supported international origins.
502
+     *
503
+     * @param int $idProvince Province ID
504
+     *
505
+     * @access  public
506
+     * @return  array|bool Returns FALSE if failed.
507
+     */
508
+    public function getInternationalOrigins( $idProvince = null ) {
509
+        if ( $this->accountType === 'starter' ) {
510
+            $this->errors[301] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.';
511
+
512
+            return false;
513
+        }
514
+
515
+        $params = [];
516
+
517
+        if ( isset( $idProvince ) ) {
518
+            $params['province'] = $idProvince;
519
+        }
520
+
521
+        return $this->request( 'v2/internationalOrigin', $params );
522
+    }
523
+
524
+    // ------------------------------------------------------------------------
525
+
526
+    /**
527
+     * Rajaongkir::getInternationalOrigin
528
+     *
529
+     * Get list of supported international origins by city and province.
530
+     *
531
+     * @param int $idCity City ID
532
+     * @param int $idProvince Province ID
533
+     *
534
+     * @access  public
535
+     * @return  array|bool Returns FALSE if failed.
536
+     */
537
+    public function getInternationalOrigin( $idCity = null, $idProvince = null ) {
538
+        if ( $this->accountType === 'starter' ) {
539
+            $this->errors[301] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.';
540
+
541
+            return false;
542
+        }
543
+
544
+        if ( isset( $idCity ) ) {
545
+            $params['id'] = $idCity;
546
+        }
547
+
548
+        if ( isset( $idProvince ) ) {
549
+            $params['province'] = $idProvince;
550
+        }
551
+
552
+        return $this->request( 'v2/internationalOrigin', $params );
553
+    }
554
+
555
+    // ------------------------------------------------------------------------
556
+
557
+    /**
558
+     * Rajaongkir::getInternationalDestinations
559
+     *
560
+     * Get list of international destinations.
561
+     *
562
+     * @param int $id_country Country ID
563
+     *
564
+     * @access  public
565
+     * @return  array|bool Returns FALSE if failed.
566
+     */
567
+    public function getInternationalDestinations() {
568
+        if ( $this->accountType === 'starter' ) {
569
+            $this->errors[301] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.';
570
+
571
+            return false;
572
+        }
573
+
574
+        return $this->request( 'v2/internationalDestination' );
575
+    }
576
+
577
+    // ------------------------------------------------------------------------
578
+
579
+    /**
580
+     * Rajaongkir::getInternationalDestination
581
+     *
582
+     * Get International Destination
583
+     *
584
+     * @param int $idCountry Country ID
585
+     *
586
+     * @access  public
587
+     * @return  array|bool Returns FALSE if failed.
588
+     */
589
+    public function getInternationalDestination( $idCountry = null ) {
590
+        if ( $this->accountType === 'starter' ) {
591
+            $this->errors[301] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.';
592
+
593
+            return false;
594
+        }
595
+
596
+        $params = [];
597
+
598
+        if ( isset( $idCountry ) ) {
599
+            $params['id'] = $idCountry;
600
+        }
601
+
602
+        return $this->request( 'v2/internationalDestination', $params );
603
+    }
604
+
605
+    // ------------------------------------------------------------------------
606
+
607
+    /**
608
+     * Rajaongkir::getCost
609
+     *
610
+     * Get cost calculation.
611
+     *
612
+     * @param array $origin City, District or Subdistrict Origin
613
+     * @param array $destination City, District or Subdistrict Destination
614
+     * @param array $metrics Array of Specification
615
+     *                                  weight      int     weight in gram (required)
616
+     *                                  length      number  package length dimension
617
+     *                                  width       number  package width dimension
618
+     *                                  height      number  package height dimension
619
+     *                                  diameter    number  package diameter
620
+     * @param string $courier Courier Code
621
+     *
622
+     * @access   public
623
+     * @return  array|bool Returns FALSE if failed.
624
+     * @see      http://rajaongkir.com/dokumentasi/pro
625
+     *
626
+     * @example
627
+     * $rajaongkir->getCost(
628
+     *      ['city' => 1],
629
+     *      ['subdistrict' => 12],
630
+     *      ['weight' => 100, 'length' => 100, 'width' => 100, 'height' => 100, 'diameter' => 100],
631
+     *      'jne'
632
+     * );
633
+     *
634
+     */
635
+    public function getCost( array $origin, array $destination, $metrics, $courier ) {
636
+        $params['courier'] = strtolower( $courier );
637
+
638
+        $params['originType']      = strtolower( key( $origin ) );
639
+        $params['destinationType'] = strtolower( key( $destination ) );
640
+
641
+        if ( $params['originType'] !== 'city' ) {
642
+            $params['originType'] = 'subdistrict';
643
+        }
644
+
645
+        if ( ! in_array( $params['destinationType'], [ 'city', 'country' ] ) ) {
646
+            $params['destinationType'] = 'subdistrict';
647
+        }
648
+
649
+        if ( is_array( $metrics ) ) {
650
+            if ( ! isset( $metrics['weight'] ) and
651
+                 isset( $metrics['length'] ) and
652
+                 isset( $metrics['width'] ) and
653
+                 isset( $metrics['height'] )
654
+            ) {
655
+                $metrics['weight'] = ( ( $metrics['length'] * $metrics['width'] * $metrics['height'] ) / 6000 ) * 1000;
656
+            } elseif ( isset( $metrics['weight'] ) and
657
+                       isset( $metrics['length'] ) and
658
+                       isset( $metrics['width'] ) and
659
+                       isset( $metrics['height'] )
660
+            ) {
661
+                $weight = ( ( $metrics['length'] * $metrics['width'] * $metrics['height'] ) / 6000 ) * 1000;
662
+
663
+                if ( $weight > $metrics['weight'] ) {
664
+                    $metrics['weight'] = $weight;
665
+                }
666
+            }
667
+
668
+            foreach ( $metrics as $key => $value ) {
669
+                $params[ $key ] = $value;
670
+            }
671
+        } elseif ( is_numeric( $metrics ) ) {
672
+            $params['weight'] = $metrics;
673
+        }
674
+
675
+        switch ( $this->accountType ) {
676
+            case 'starter':
677
+
678
+                if ( $params['destinationType'] === 'country' ) {
679
+                    $this->errors[301] = 'Unsupported International Destination. Tipe akun starter tidak mendukung pengecekan destinasi international.';
680
+
681
+                    return false;
682
+                } elseif ( $params['originType'] === 'subdistrict' or $params['destinationType'] === 'subdistrict' ) {
683
+                    $this->errors[302] = 'Unsupported Subdistrict Origin-Destination. Tipe akun starter tidak mendukung pengecekan ongkos kirim sampai kecamatan.';
684
+
685
+                    return false;
686
+                }
687
+
688
+                if ( ! isset( $params['weight'] ) and
689
+                     isset( $params['length'] ) and
690
+                     isset( $params['width'] ) and
691
+                     isset( $params['height'] )
692
+                ) {
693
+                    $this->errors[304] = 'Unsupported Dimension. Tipe akun starter tidak mendukung pengecekan biaya kirim berdasarkan dimensi.';
694
+
695
+                    return false;
696
+                } elseif ( isset( $params['weight'] ) and $params['weight'] > 30000 ) {
697
+                    $this->errors[305] = 'Unsupported Weight. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).';
698
+
699
+                    return false;
700
+                }
701
+
702
+                if ( ! in_array( $params['courier'], $this->supportedCouriers[ $this->accountType ] ) ) {
703
+                    $this->errors[303] = 'Unsupported Courier. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[ $courier ] . '.';
704
+
705
+                    return false;
706
+                }
707
+
708
+                break;
709
+
710
+            case 'basic':
711
+
712
+                if ( $params['originType'] === 'subdistrict' or $params['destinationType'] === 'subdistrict' ) {
713
+                    $this->errors[302] = 'Unsupported Subdistrict Origin-Destination. Tipe akun basic tidak mendukung pengecekan ongkos kirim sampai kecamatan.';
714
+
715
+                    return false;
716
+                }
717
+
718
+                if ( ! isset( $params['weight'] ) and
719
+                     isset( $params['length'] ) and
720
+                     isset( $params['width'] ) and
721
+                     isset( $params['height'] )
722
+                ) {
723
+                    $this->errors[304] = 'Unsupported Dimension. Tipe akun basic tidak mendukung pengecekan biaya kirim berdasarkan dimensi.';
724
+
725
+                    return false;
726
+                } elseif ( isset( $params['weight'] ) and $params['weight'] > 30000 ) {
727
+                    $this->errors[305] = 'Unsupported Weight. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).';
728
+
729
+                    return false;
730
+                } elseif ( isset( $params['weight'] ) and $params['weight'] < 30000 ) {
731
+                    unset( $params['length'], $params['width'], $params['height'] );
732
+                }
733
+
734
+                if ( ! in_array( $params['courier'], $this->supportedCouriers[ $this->accountType ] ) ) {
735
+                    $this->errors[303] = 'Unsupported Courier. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[ $courier ] . '.';
736
+
737
+                    return false;
738
+                }
739
+
740
+                break;
741
+        }
742
+
743
+        $params['origin']      = $origin[ key( $origin ) ];
744
+        $params['destination'] = $destination[ key( $destination ) ];
745
+
746
+        $path = key( $destination ) === 'country' ? 'internationalCost' : 'cost';
747
+
748
+        return $this->request( $path, $params, 'POST' );
749
+    }
750
+
751
+    // ------------------------------------------------------------------------
752
+
753
+    /**
754
+     * Rajaongkir::getWaybill
755
+     *
756
+     * Get detail of waybill.
757
+     *
758
+     * @param int $idWaybill Receipt ID
759
+     * @param null|string $courier Courier Code
760
+     *
761
+     * @access  public
762
+     * @return  array|bool Returns FALSE if failed.
763
+     */
764
+    public function getWaybill( $idWaybill, $courier ) {
765
+        $courier = strtolower( $courier );
766
+
767
+        if ( in_array( $courier, $this->supportedWayBills[ $this->accountType ] ) ) {
768
+            return $this->request( 'waybill', [
769
+                'key'     => $this->apiKey,
770
+                'waybill' => $idWaybill,
771
+                'courier' => $courier,
772
+            ], 'POST' );
773
+        }
774
+
775
+        return false;
776
+    }
777
+
778
+    // ------------------------------------------------------------------------
779
+
780
+    /**
781
+     * Rajaongkir::getCurrency
782
+     *
783
+     * Get Rajaongkir currency.
784
+     *
785
+     * @access  public
786
+     * @return  array|bool Returns FALSE if failed.
787
+     */
788
+    public function getCurrency() {
789
+        if ( $this->accountType !== 'starter' ) {
790
+            return $this->request( 'currency' );
791
+        }
792
+
793
+        $this->errors[301] = 'Unsupported Get Currency. Tipe akun starter tidak mendukung pengecekan currency.';
794
+
795
+        return false;
796
+    }
797
+
798
+    // ------------------------------------------------------------------------
799
+
800
+    /**
801
+     * Rajaongkir::getSupportedCouriers
802
+     *
803
+     * Gets list of supported couriers by your account.
804
+     *
805
+     * @return array|bool Returns FALSE if failed.
806
+     */
807
+    public function getSupportedCouriers() {
808
+        if ( isset( $this->supportedCouriers[ $this->accountType ] ) ) {
809
+            return $this->supportedCouriers[ $this->accountType ];
810
+        }
811
+
812
+        return false;
813
+    }
814
+
815
+    // ------------------------------------------------------------------------
816
+
817
+    /**
818
+     * Rajaongkir::getSupportedWayBills
819
+     *
820
+     * Gets list of supported way bills based on account type.
821
+     *
822
+     * @return array|bool Returns FALSE if failed.
823
+     */
824
+    public function getSupportedWayBills() {
825
+        if ( isset( $this->supportedWayBills[ $this->accountType ] ) ) {
826
+            return $this->supportedWayBills[ $this->accountType ];
827
+        }
828
+
829
+        return false;
830
+    }
831
+
832
+    // ------------------------------------------------------------------------
833
+
834
+    /**
835
+     * Rajaongkir::getResponse
836
+     *
837
+     * Get original response object.
838
+     *
839
+     * @param string $offset Response Offset Object
840
+     *
841
+     * @access  public
842
+     * @return  \O2System\Curl\Response|bool Returns FALSE if failed.
843
+     */
844
+    public function getResponse() {
845
+        return $this->response;
846
+    }
847 847
 }
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -214,23 +214,23 @@  discard block
 block discarded – undo
214 214
 	 * @access  public
215 215
 	 * @throws  \InvalidArgumentException
216 216
 	 */
217
-	public function __construct( $apiKey = null, $accountType = null ) {
218
-		if ( isset( $apiKey ) ) {
219
-			if ( is_array( $apiKey ) ) {
220
-				if ( isset( $apiKey['api_key'] ) ) {
217
+	public function __construct($apiKey = null, $accountType = null) {
218
+		if (isset($apiKey)) {
219
+			if (is_array($apiKey)) {
220
+				if (isset($apiKey['api_key'])) {
221 221
 					$this->apiKey = $apiKey['api_key'];
222 222
 				}
223 223
 
224
-				if ( isset( $apiKey['account_type'] ) ) {
224
+				if (isset($apiKey['account_type'])) {
225 225
 					$accountType = $apiKey['account_type'];
226 226
 				}
227
-			} elseif ( is_string( $apiKey ) ) {
227
+			} elseif (is_string($apiKey)) {
228 228
 				$this->apiKey = $apiKey;
229 229
 			}
230 230
 		}
231 231
 
232
-		if ( isset( $accountType ) ) {
233
-			$this->setAccountType( $accountType );
232
+		if (isset($accountType)) {
233
+			$this->setAccountType($accountType);
234 234
 		}
235 235
 	}
236 236
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 	 * @access  public
247 247
 	 * @return  static
248 248
 	 */
249
-	public function setApiKey( $apiKey ) {
249
+	public function setApiKey($apiKey) {
250 250
 		$this->apiKey = $apiKey;
251 251
 
252 252
 		return $this;
@@ -265,13 +265,13 @@  discard block
 block discarded – undo
265 265
 	 * @return  static
266 266
 	 * @throws  \InvalidArgumentException
267 267
 	 */
268
-	public function setAccountType( $accountType ) {
269
-		$accountType = strtolower( $accountType );
268
+	public function setAccountType($accountType) {
269
+		$accountType = strtolower($accountType);
270 270
 
271
-		if ( in_array( $accountType, $this->supportedAccountTypes ) ) {
271
+		if (in_array($accountType, $this->supportedAccountTypes)) {
272 272
 			$this->accountType = $accountType;
273 273
 		} else {
274
-			throw new \InvalidArgumentException( 'Rajaongkir: Invalid Account Type' );
274
+			throw new \InvalidArgumentException('Rajaongkir: Invalid Account Type');
275 275
 		}
276 276
 
277 277
 		return $this;
@@ -291,10 +291,10 @@  discard block
 block discarded – undo
291 291
 	 * @access  protected
292 292
 	 * @return  array|bool Returns FALSE if failed.
293 293
 	 */
294
-	protected function request( $path, $params = [], $type = 'GET' ) {
294
+	protected function request($path, $params = [], $type = 'GET') {
295 295
 		$apiUrl = 'https://api.rajaongkir.com';
296 296
 
297
-		switch ( $this->accountType ) {
297
+		switch ($this->accountType) {
298 298
 			default:
299 299
 			case 'starter':
300 300
 				$path = 'starter/' . $path;
@@ -310,48 +310,48 @@  discard block
 block discarded – undo
310 310
 				break;
311 311
 		}
312 312
 
313
-		$uri     = ( new Uri( $apiUrl ) )->withPath( $path );
313
+		$uri     = (new Uri($apiUrl))->withPath($path);
314 314
 		$request = new Curl\Request();
315
-		$request->setHeaders( [
315
+		$request->setHeaders([
316 316
 			'key' => $this->apiKey,
317
-		] );
317
+		]);
318 318
 
319
-		switch ( $type ) {
319
+		switch ($type) {
320 320
 			default:
321 321
 			case 'GET':
322
-				$this->response = $request->setUri( $uri )->get( $params );
322
+				$this->response = $request->setUri($uri)->get($params);
323 323
 				break;
324 324
 
325 325
 			case 'POST':
326
-				$request->addHeader( 'content-type', 'application/x-www-form-urlencoded' );
327
-				$this->response = $request->setUri( $uri )->post( $params );
326
+				$request->addHeader('content-type', 'application/x-www-form-urlencoded');
327
+				$this->response = $request->setUri($uri)->post($params);
328 328
 				break;
329 329
 		}
330 330
 
331 331
 		// Try to get curl error
332
-		if ( false !== ( $error = $this->response->getError() ) ) {
333
-			$this->addErrors( $error->getArrayCopy() );
332
+		if (false !== ($error = $this->response->getError())) {
333
+			$this->addErrors($error->getArrayCopy());
334 334
 		} else {
335 335
 			$body = $this->response->getBody();
336 336
 
337
-			if ( $body instanceof \DOMDocument ) {
337
+			if ($body instanceof \DOMDocument) {
338 338
 				$this->errors[404] = 'Page Not Found!';
339 339
 			} else {
340 340
 				$body   = $body->rajaongkir;
341 341
 				$status = $body['status'];
342 342
 
343
-				if ( $status['code'] == 200 ) {
344
-					if ( isset( $body['results'] ) ) {
345
-						if ( count( $body['results'] ) == 1 && isset( $body['results'][0] ) ) {
343
+				if ($status['code'] == 200) {
344
+					if (isset($body['results'])) {
345
+						if (count($body['results']) == 1 && isset($body['results'][0])) {
346 346
 							return $body['results'][0];
347
-						} elseif ( count( $body['results'] ) ) {
347
+						} elseif (count($body['results'])) {
348 348
 							return $body['results'];
349 349
 						}
350
-					} elseif ( isset( $body['result'] ) ) {
350
+					} elseif (isset($body['result'])) {
351 351
 						return $body['result'];
352 352
 					}
353 353
 				} else {
354
-					$this->errors[ $status['code'] ] = $status['description'];
354
+					$this->errors[$status['code']] = $status['description'];
355 355
 				}
356 356
 			}
357 357
 		}
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 	 * @return  array|bool Returns FALSE if failed.
385 385
 	 */
386 386
 	public function getProvinces() {
387
-		return $this->request( 'province' );
387
+		return $this->request('province');
388 388
 	}
389 389
 
390 390
 	// ------------------------------------------------------------------------
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
 	 * @access  public
400 400
 	 * @return  array|bool Returns FALSE if failed.
401 401
 	 */
402
-	public function getProvince( $idProvince ) {
403
-		return $this->request( 'province', [ 'id' => $idProvince ] );
402
+	public function getProvince($idProvince) {
403
+		return $this->request('province', ['id' => $idProvince]);
404 404
 	}
405 405
 
406 406
 	// ------------------------------------------------------------------------
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
 	 * @access  public
416 416
 	 * @return  array|bool Returns FALSE if failed.
417 417
 	 */
418
-	public function getCities( $idProvince = null ) {
418
+	public function getCities($idProvince = null) {
419 419
 		$params = [];
420 420
 
421
-		if ( ! is_null( $idProvince ) ) {
421
+		if (!is_null($idProvince)) {
422 422
 			$params['province'] = $idProvince;
423 423
 		}
424 424
 
425
-		return $this->request( 'city', $params );
425
+		return $this->request('city', $params);
426 426
 	}
427 427
 
428 428
 	// ------------------------------------------------------------------------
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
 	 * @access  public
438 438
 	 * @return  array|bool Returns FALSE if failed.
439 439
 	 */
440
-	public function getCity( $idCity ) {
441
-		return $this->request( 'city', [ 'id' => $idCity ] );
440
+	public function getCity($idCity) {
441
+		return $this->request('city', ['id' => $idCity]);
442 442
 	}
443 443
 
444 444
 	// ------------------------------------------------------------------------
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
 	 * @access  public
454 454
 	 * @return  array|bool Returns FALSE if failed.
455 455
 	 */
456
-	public function getSubdistricts( $idCity ) {
457
-		if ( $this->accountType === 'starter' ) {
456
+	public function getSubdistricts($idCity) {
457
+		if ($this->accountType === 'starter') {
458 458
 			$this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.';
459 459
 
460 460
 			return false;
461
-		} elseif ( $this->accountType === 'basic' ) {
461
+		} elseif ($this->accountType === 'basic') {
462 462
 			$this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.';
463 463
 
464 464
 			return false;
465 465
 		}
466 466
 
467
-		return $this->request( 'subdistrict', [ 'city' => $idCity ] );
467
+		return $this->request('subdistrict', ['city' => $idCity]);
468 468
 	}
469 469
 
470 470
 	// ------------------------------------------------------------------------
@@ -479,18 +479,18 @@  discard block
 block discarded – undo
479 479
 	 * @access  public
480 480
 	 * @return  array|bool Returns FALSE if failed.
481 481
 	 */
482
-	public function getSubdistrict( $idSubdistrict ) {
483
-		if ( $this->accountType === 'starter' ) {
482
+	public function getSubdistrict($idSubdistrict) {
483
+		if ($this->accountType === 'starter') {
484 484
 			$this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.';
485 485
 
486 486
 			return false;
487
-		} elseif ( $this->accountType === 'basic' ) {
487
+		} elseif ($this->accountType === 'basic') {
488 488
 			$this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.';
489 489
 
490 490
 			return false;
491 491
 		}
492 492
 
493
-		return $this->request( 'subdistrict', [ 'id' => $idSubdistrict ] );
493
+		return $this->request('subdistrict', ['id' => $idSubdistrict]);
494 494
 	}
495 495
 
496 496
 	// ------------------------------------------------------------------------
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
 	 * @access  public
506 506
 	 * @return  array|bool Returns FALSE if failed.
507 507
 	 */
508
-	public function getInternationalOrigins( $idProvince = null ) {
509
-		if ( $this->accountType === 'starter' ) {
508
+	public function getInternationalOrigins($idProvince = null) {
509
+		if ($this->accountType === 'starter') {
510 510
 			$this->errors[301] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.';
511 511
 
512 512
 			return false;
@@ -514,11 +514,11 @@  discard block
 block discarded – undo
514 514
 
515 515
 		$params = [];
516 516
 
517
-		if ( isset( $idProvince ) ) {
517
+		if (isset($idProvince)) {
518 518
 			$params['province'] = $idProvince;
519 519
 		}
520 520
 
521
-		return $this->request( 'v2/internationalOrigin', $params );
521
+		return $this->request('v2/internationalOrigin', $params);
522 522
 	}
523 523
 
524 524
 	// ------------------------------------------------------------------------
@@ -534,22 +534,22 @@  discard block
 block discarded – undo
534 534
 	 * @access  public
535 535
 	 * @return  array|bool Returns FALSE if failed.
536 536
 	 */
537
-	public function getInternationalOrigin( $idCity = null, $idProvince = null ) {
538
-		if ( $this->accountType === 'starter' ) {
537
+	public function getInternationalOrigin($idCity = null, $idProvince = null) {
538
+		if ($this->accountType === 'starter') {
539 539
 			$this->errors[301] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.';
540 540
 
541 541
 			return false;
542 542
 		}
543 543
 
544
-		if ( isset( $idCity ) ) {
544
+		if (isset($idCity)) {
545 545
 			$params['id'] = $idCity;
546 546
 		}
547 547
 
548
-		if ( isset( $idProvince ) ) {
548
+		if (isset($idProvince)) {
549 549
 			$params['province'] = $idProvince;
550 550
 		}
551 551
 
552
-		return $this->request( 'v2/internationalOrigin', $params );
552
+		return $this->request('v2/internationalOrigin', $params);
553 553
 	}
554 554
 
555 555
 	// ------------------------------------------------------------------------
@@ -565,13 +565,13 @@  discard block
 block discarded – undo
565 565
 	 * @return  array|bool Returns FALSE if failed.
566 566
 	 */
567 567
 	public function getInternationalDestinations() {
568
-		if ( $this->accountType === 'starter' ) {
568
+		if ($this->accountType === 'starter') {
569 569
 			$this->errors[301] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.';
570 570
 
571 571
 			return false;
572 572
 		}
573 573
 
574
-		return $this->request( 'v2/internationalDestination' );
574
+		return $this->request('v2/internationalDestination');
575 575
 	}
576 576
 
577 577
 	// ------------------------------------------------------------------------
@@ -586,8 +586,8 @@  discard block
 block discarded – undo
586 586
 	 * @access  public
587 587
 	 * @return  array|bool Returns FALSE if failed.
588 588
 	 */
589
-	public function getInternationalDestination( $idCountry = null ) {
590
-		if ( $this->accountType === 'starter' ) {
589
+	public function getInternationalDestination($idCountry = null) {
590
+		if ($this->accountType === 'starter') {
591 591
 			$this->errors[301] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.';
592 592
 
593 593
 			return false;
@@ -595,11 +595,11 @@  discard block
 block discarded – undo
595 595
 
596 596
 		$params = [];
597 597
 
598
-		if ( isset( $idCountry ) ) {
598
+		if (isset($idCountry)) {
599 599
 			$params['id'] = $idCountry;
600 600
 		}
601 601
 
602
-		return $this->request( 'v2/internationalDestination', $params );
602
+		return $this->request('v2/internationalDestination', $params);
603 603
 	}
604 604
 
605 605
 	// ------------------------------------------------------------------------
@@ -632,75 +632,75 @@  discard block
 block discarded – undo
632 632
 	 * );
633 633
 	 *
634 634
 	 */
635
-	public function getCost( array $origin, array $destination, $metrics, $courier ) {
636
-		$params['courier'] = strtolower( $courier );
635
+	public function getCost(array $origin, array $destination, $metrics, $courier) {
636
+		$params['courier'] = strtolower($courier);
637 637
 
638
-		$params['originType']      = strtolower( key( $origin ) );
639
-		$params['destinationType'] = strtolower( key( $destination ) );
638
+		$params['originType']      = strtolower(key($origin));
639
+		$params['destinationType'] = strtolower(key($destination));
640 640
 
641
-		if ( $params['originType'] !== 'city' ) {
641
+		if ($params['originType'] !== 'city') {
642 642
 			$params['originType'] = 'subdistrict';
643 643
 		}
644 644
 
645
-		if ( ! in_array( $params['destinationType'], [ 'city', 'country' ] ) ) {
645
+		if (!in_array($params['destinationType'], ['city', 'country'])) {
646 646
 			$params['destinationType'] = 'subdistrict';
647 647
 		}
648 648
 
649
-		if ( is_array( $metrics ) ) {
650
-			if ( ! isset( $metrics['weight'] ) and
651
-			     isset( $metrics['length'] ) and
652
-			     isset( $metrics['width'] ) and
653
-			     isset( $metrics['height'] )
649
+		if (is_array($metrics)) {
650
+			if (!isset($metrics['weight']) and
651
+			     isset($metrics['length']) and
652
+			     isset($metrics['width']) and
653
+			     isset($metrics['height'])
654 654
 			) {
655
-				$metrics['weight'] = ( ( $metrics['length'] * $metrics['width'] * $metrics['height'] ) / 6000 ) * 1000;
656
-			} elseif ( isset( $metrics['weight'] ) and
657
-			           isset( $metrics['length'] ) and
658
-			           isset( $metrics['width'] ) and
659
-			           isset( $metrics['height'] )
655
+				$metrics['weight'] = (($metrics['length'] * $metrics['width'] * $metrics['height']) / 6000) * 1000;
656
+			} elseif (isset($metrics['weight']) and
657
+			           isset($metrics['length']) and
658
+			           isset($metrics['width']) and
659
+			           isset($metrics['height'])
660 660
 			) {
661
-				$weight = ( ( $metrics['length'] * $metrics['width'] * $metrics['height'] ) / 6000 ) * 1000;
661
+				$weight = (($metrics['length'] * $metrics['width'] * $metrics['height']) / 6000) * 1000;
662 662
 
663
-				if ( $weight > $metrics['weight'] ) {
663
+				if ($weight > $metrics['weight']) {
664 664
 					$metrics['weight'] = $weight;
665 665
 				}
666 666
 			}
667 667
 
668
-			foreach ( $metrics as $key => $value ) {
669
-				$params[ $key ] = $value;
668
+			foreach ($metrics as $key => $value) {
669
+				$params[$key] = $value;
670 670
 			}
671
-		} elseif ( is_numeric( $metrics ) ) {
671
+		} elseif (is_numeric($metrics)) {
672 672
 			$params['weight'] = $metrics;
673 673
 		}
674 674
 
675
-		switch ( $this->accountType ) {
675
+		switch ($this->accountType) {
676 676
 			case 'starter':
677 677
 
678
-				if ( $params['destinationType'] === 'country' ) {
678
+				if ($params['destinationType'] === 'country') {
679 679
 					$this->errors[301] = 'Unsupported International Destination. Tipe akun starter tidak mendukung pengecekan destinasi international.';
680 680
 
681 681
 					return false;
682
-				} elseif ( $params['originType'] === 'subdistrict' or $params['destinationType'] === 'subdistrict' ) {
682
+				} elseif ($params['originType'] === 'subdistrict' or $params['destinationType'] === 'subdistrict') {
683 683
 					$this->errors[302] = 'Unsupported Subdistrict Origin-Destination. Tipe akun starter tidak mendukung pengecekan ongkos kirim sampai kecamatan.';
684 684
 
685 685
 					return false;
686 686
 				}
687 687
 
688
-				if ( ! isset( $params['weight'] ) and
689
-				     isset( $params['length'] ) and
690
-				     isset( $params['width'] ) and
691
-				     isset( $params['height'] )
688
+				if (!isset($params['weight']) and
689
+				     isset($params['length']) and
690
+				     isset($params['width']) and
691
+				     isset($params['height'])
692 692
 				) {
693 693
 					$this->errors[304] = 'Unsupported Dimension. Tipe akun starter tidak mendukung pengecekan biaya kirim berdasarkan dimensi.';
694 694
 
695 695
 					return false;
696
-				} elseif ( isset( $params['weight'] ) and $params['weight'] > 30000 ) {
696
+				} elseif (isset($params['weight']) and $params['weight'] > 30000) {
697 697
 					$this->errors[305] = 'Unsupported Weight. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).';
698 698
 
699 699
 					return false;
700 700
 				}
701 701
 
702
-				if ( ! in_array( $params['courier'], $this->supportedCouriers[ $this->accountType ] ) ) {
703
-					$this->errors[303] = 'Unsupported Courier. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[ $courier ] . '.';
702
+				if (!in_array($params['courier'], $this->supportedCouriers[$this->accountType])) {
703
+					$this->errors[303] = 'Unsupported Courier. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[$courier] . '.';
704 704
 
705 705
 					return false;
706 706
 				}
@@ -709,30 +709,30 @@  discard block
 block discarded – undo
709 709
 
710 710
 			case 'basic':
711 711
 
712
-				if ( $params['originType'] === 'subdistrict' or $params['destinationType'] === 'subdistrict' ) {
712
+				if ($params['originType'] === 'subdistrict' or $params['destinationType'] === 'subdistrict') {
713 713
 					$this->errors[302] = 'Unsupported Subdistrict Origin-Destination. Tipe akun basic tidak mendukung pengecekan ongkos kirim sampai kecamatan.';
714 714
 
715 715
 					return false;
716 716
 				}
717 717
 
718
-				if ( ! isset( $params['weight'] ) and
719
-				     isset( $params['length'] ) and
720
-				     isset( $params['width'] ) and
721
-				     isset( $params['height'] )
718
+				if (!isset($params['weight']) and
719
+				     isset($params['length']) and
720
+				     isset($params['width']) and
721
+				     isset($params['height'])
722 722
 				) {
723 723
 					$this->errors[304] = 'Unsupported Dimension. Tipe akun basic tidak mendukung pengecekan biaya kirim berdasarkan dimensi.';
724 724
 
725 725
 					return false;
726
-				} elseif ( isset( $params['weight'] ) and $params['weight'] > 30000 ) {
726
+				} elseif (isset($params['weight']) and $params['weight'] > 30000) {
727 727
 					$this->errors[305] = 'Unsupported Weight. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).';
728 728
 
729 729
 					return false;
730
-				} elseif ( isset( $params['weight'] ) and $params['weight'] < 30000 ) {
731
-					unset( $params['length'], $params['width'], $params['height'] );
730
+				} elseif (isset($params['weight']) and $params['weight'] < 30000) {
731
+					unset($params['length'], $params['width'], $params['height']);
732 732
 				}
733 733
 
734
-				if ( ! in_array( $params['courier'], $this->supportedCouriers[ $this->accountType ] ) ) {
735
-					$this->errors[303] = 'Unsupported Courier. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[ $courier ] . '.';
734
+				if (!in_array($params['courier'], $this->supportedCouriers[$this->accountType])) {
735
+					$this->errors[303] = 'Unsupported Courier. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[$courier] . '.';
736 736
 
737 737
 					return false;
738 738
 				}
@@ -740,12 +740,12 @@  discard block
 block discarded – undo
740 740
 				break;
741 741
 		}
742 742
 
743
-		$params['origin']      = $origin[ key( $origin ) ];
744
-		$params['destination'] = $destination[ key( $destination ) ];
743
+		$params['origin']      = $origin[key($origin)];
744
+		$params['destination'] = $destination[key($destination)];
745 745
 
746
-		$path = key( $destination ) === 'country' ? 'internationalCost' : 'cost';
746
+		$path = key($destination) === 'country' ? 'internationalCost' : 'cost';
747 747
 
748
-		return $this->request( $path, $params, 'POST' );
748
+		return $this->request($path, $params, 'POST');
749 749
 	}
750 750
 
751 751
 	// ------------------------------------------------------------------------
@@ -761,15 +761,15 @@  discard block
 block discarded – undo
761 761
 	 * @access  public
762 762
 	 * @return  array|bool Returns FALSE if failed.
763 763
 	 */
764
-	public function getWaybill( $idWaybill, $courier ) {
765
-		$courier = strtolower( $courier );
764
+	public function getWaybill($idWaybill, $courier) {
765
+		$courier = strtolower($courier);
766 766
 
767
-		if ( in_array( $courier, $this->supportedWayBills[ $this->accountType ] ) ) {
768
-			return $this->request( 'waybill', [
767
+		if (in_array($courier, $this->supportedWayBills[$this->accountType])) {
768
+			return $this->request('waybill', [
769 769
 				'key'     => $this->apiKey,
770 770
 				'waybill' => $idWaybill,
771 771
 				'courier' => $courier,
772
-			], 'POST' );
772
+			], 'POST');
773 773
 		}
774 774
 
775 775
 		return false;
@@ -786,8 +786,8 @@  discard block
 block discarded – undo
786 786
 	 * @return  array|bool Returns FALSE if failed.
787 787
 	 */
788 788
 	public function getCurrency() {
789
-		if ( $this->accountType !== 'starter' ) {
790
-			return $this->request( 'currency' );
789
+		if ($this->accountType !== 'starter') {
790
+			return $this->request('currency');
791 791
 		}
792 792
 
793 793
 		$this->errors[301] = 'Unsupported Get Currency. Tipe akun starter tidak mendukung pengecekan currency.';
@@ -805,8 +805,8 @@  discard block
 block discarded – undo
805 805
 	 * @return array|bool Returns FALSE if failed.
806 806
 	 */
807 807
 	public function getSupportedCouriers() {
808
-		if ( isset( $this->supportedCouriers[ $this->accountType ] ) ) {
809
-			return $this->supportedCouriers[ $this->accountType ];
808
+		if (isset($this->supportedCouriers[$this->accountType])) {
809
+			return $this->supportedCouriers[$this->accountType];
810 810
 		}
811 811
 
812 812
 		return false;
@@ -822,8 +822,8 @@  discard block
 block discarded – undo
822 822
 	 * @return array|bool Returns FALSE if failed.
823 823
 	 */
824 824
 	public function getSupportedWayBills() {
825
-		if ( isset( $this->supportedWayBills[ $this->accountType ] ) ) {
826
-			return $this->supportedWayBills[ $this->accountType ];
825
+		if (isset($this->supportedWayBills[$this->accountType])) {
826
+			return $this->supportedWayBills[$this->accountType];
827 827
 		}
828 828
 
829 829
 		return false;
Please login to merge, or discard this patch.