@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | { |
222 | 222 | if (isset($apiKey)) { |
223 | 223 | if (is_array($apiKey)) { |
224 | - if (isset($apiKey[ 'api_key' ])) { |
|
225 | - $this->apiKey = $apiKey[ 'api_key' ]; |
|
224 | + if (isset($apiKey['api_key'])) { |
|
225 | + $this->apiKey = $apiKey['api_key']; |
|
226 | 226 | } |
227 | 227 | |
228 | - if (isset($apiKey[ 'account_type' ])) { |
|
229 | - $accountType = $apiKey[ 'account_type' ]; |
|
228 | + if (isset($apiKey['account_type'])) { |
|
229 | + $accountType = $apiKey['account_type']; |
|
230 | 230 | } |
231 | 231 | } elseif (is_string($apiKey)) { |
232 | 232 | $this->apiKey = $apiKey; |
@@ -342,23 +342,23 @@ discard block |
||
342 | 342 | $body = $this->response->getBody(); |
343 | 343 | |
344 | 344 | if ($body instanceof \DOMDocument) { |
345 | - $this->errors[ 404 ] = 'Page Not Found!'; |
|
345 | + $this->errors[404] = 'Page Not Found!'; |
|
346 | 346 | } else { |
347 | 347 | $body = $body->rajaongkir; |
348 | - $status = $body[ 'status' ]; |
|
349 | - |
|
350 | - if ($status[ 'code' ] == 200) { |
|
351 | - if (isset($body[ 'results' ])) { |
|
352 | - if (count($body[ 'results' ]) == 1 && isset($body[ 'results' ][ 0 ])) { |
|
353 | - return $body[ 'results' ][ 0 ]; |
|
354 | - } elseif (count($body[ 'results' ])) { |
|
355 | - return $body[ 'results' ]; |
|
348 | + $status = $body['status']; |
|
349 | + |
|
350 | + if ($status['code'] == 200) { |
|
351 | + if (isset($body['results'])) { |
|
352 | + if (count($body['results']) == 1 && isset($body['results'][0])) { |
|
353 | + return $body['results'][0]; |
|
354 | + } elseif (count($body['results'])) { |
|
355 | + return $body['results']; |
|
356 | 356 | } |
357 | - } elseif (isset($body[ 'result' ])) { |
|
358 | - return $body[ 'result' ]; |
|
357 | + } elseif (isset($body['result'])) { |
|
358 | + return $body['result']; |
|
359 | 359 | } |
360 | 360 | } else { |
361 | - $this->errors[ $status[ 'code' ] ] = $status[ 'description' ]; |
|
361 | + $this->errors[$status['code']] = $status['description']; |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | } |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | { |
430 | 430 | $params = []; |
431 | 431 | |
432 | - if ( ! is_null($idProvince)) { |
|
433 | - $params[ 'province' ] = $idProvince; |
|
432 | + if (!is_null($idProvince)) { |
|
433 | + $params['province'] = $idProvince; |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $this->request('city', $params); |
@@ -468,11 +468,11 @@ discard block |
||
468 | 468 | public function getSubdistricts($idCity) |
469 | 469 | { |
470 | 470 | if ($this->accountType === 'starter') { |
471 | - $this->errors[ 302 ] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.'; |
|
471 | + $this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.'; |
|
472 | 472 | |
473 | 473 | return false; |
474 | 474 | } elseif ($this->accountType === 'basic') { |
475 | - $this->errors[ 302 ] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.'; |
|
475 | + $this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.'; |
|
476 | 476 | |
477 | 477 | return false; |
478 | 478 | } |
@@ -495,11 +495,11 @@ discard block |
||
495 | 495 | public function getSubdistrict($idSubdistrict) |
496 | 496 | { |
497 | 497 | if ($this->accountType === 'starter') { |
498 | - $this->errors[ 302 ] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.'; |
|
498 | + $this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun starter tidak mendukung hingga tingkat kecamatan.'; |
|
499 | 499 | |
500 | 500 | return false; |
501 | 501 | } elseif ($this->accountType === 'basic') { |
502 | - $this->errors[ 302 ] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.'; |
|
502 | + $this->errors[302] = 'Unsupported Subdistricts Request. Tipe akun basic tidak mendukung hingga tingkat kecamatan.'; |
|
503 | 503 | |
504 | 504 | return false; |
505 | 505 | } |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | public function getInternationalOrigins($idProvince = null) |
523 | 523 | { |
524 | 524 | if ($this->accountType === 'starter') { |
525 | - $this->errors[ 301 ] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.'; |
|
525 | + $this->errors[301] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.'; |
|
526 | 526 | |
527 | 527 | return false; |
528 | 528 | } |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | $params = []; |
531 | 531 | |
532 | 532 | if (isset($idProvince)) { |
533 | - $params[ 'province' ] = $idProvince; |
|
533 | + $params['province'] = $idProvince; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | return $this->request('v2/internationalOrigin', $params); |
@@ -552,17 +552,17 @@ discard block |
||
552 | 552 | public function getInternationalOrigin($idCity = null, $idProvince = null) |
553 | 553 | { |
554 | 554 | if ($this->accountType === 'starter') { |
555 | - $this->errors[ 301 ] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.'; |
|
555 | + $this->errors[301] = 'Unsupported International Origin Request. Tipe akun starter tidak mendukung tingkat international.'; |
|
556 | 556 | |
557 | 557 | return false; |
558 | 558 | } |
559 | 559 | |
560 | 560 | if (isset($idCity)) { |
561 | - $params[ 'id' ] = $idCity; |
|
561 | + $params['id'] = $idCity; |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | if (isset($idProvince)) { |
565 | - $params[ 'province' ] = $idProvince; |
|
565 | + $params['province'] = $idProvince; |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | return $this->request('v2/internationalOrigin', $params); |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | public function getInternationalDestinations() |
584 | 584 | { |
585 | 585 | if ($this->accountType === 'starter') { |
586 | - $this->errors[ 301 ] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.'; |
|
586 | + $this->errors[301] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.'; |
|
587 | 587 | |
588 | 588 | return false; |
589 | 589 | } |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | public function getInternationalDestination($idCountry = null) |
607 | 607 | { |
608 | 608 | if ($this->accountType === 'starter') { |
609 | - $this->errors[ 301 ] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.'; |
|
609 | + $this->errors[301] = 'Unsupported International Destination Request. Tipe akun starter tidak mendukung tingkat international.'; |
|
610 | 610 | |
611 | 611 | return false; |
612 | 612 | } |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | $params = []; |
615 | 615 | |
616 | 616 | if (isset($idCountry)) { |
617 | - $params[ 'id' ] = $idCountry; |
|
617 | + $params['id'] = $idCountry; |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | return $this->request('v2/internationalDestination', $params); |
@@ -652,74 +652,74 @@ discard block |
||
652 | 652 | */ |
653 | 653 | public function getCost(array $origin, array $destination, $metrics, $courier) |
654 | 654 | { |
655 | - $params[ 'courier' ] = strtolower($courier); |
|
655 | + $params['courier'] = strtolower($courier); |
|
656 | 656 | |
657 | - $params[ 'originType' ] = strtolower(key($origin)); |
|
658 | - $params[ 'destinationType' ] = strtolower(key($destination)); |
|
657 | + $params['originType'] = strtolower(key($origin)); |
|
658 | + $params['destinationType'] = strtolower(key($destination)); |
|
659 | 659 | |
660 | - if ($params[ 'originType' ] !== 'city') { |
|
661 | - $params[ 'originType' ] = 'subdistrict'; |
|
660 | + if ($params['originType'] !== 'city') { |
|
661 | + $params['originType'] = 'subdistrict'; |
|
662 | 662 | } |
663 | 663 | |
664 | - if ( ! in_array($params[ 'destinationType' ], ['city', 'country'])) { |
|
665 | - $params[ 'destinationType' ] = 'subdistrict'; |
|
664 | + if (!in_array($params['destinationType'], ['city', 'country'])) { |
|
665 | + $params['destinationType'] = 'subdistrict'; |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | if (is_array($metrics)) { |
669 | - if ( ! isset($metrics[ 'weight' ]) AND |
|
670 | - isset($metrics[ 'length' ]) AND |
|
671 | - isset($metrics[ 'width' ]) AND |
|
672 | - isset($metrics[ 'height' ]) |
|
669 | + if (!isset($metrics['weight']) AND |
|
670 | + isset($metrics['length']) AND |
|
671 | + isset($metrics['width']) AND |
|
672 | + isset($metrics['height']) |
|
673 | 673 | ) { |
674 | - $metrics[ 'weight' ] = (($metrics[ 'length' ] * $metrics[ 'width' ] * $metrics[ 'height' ]) / 6000) * 1000; |
|
675 | - } elseif (isset($metrics[ 'weight' ]) AND |
|
676 | - isset($metrics[ 'length' ]) AND |
|
677 | - isset($metrics[ 'width' ]) AND |
|
678 | - isset($metrics[ 'height' ]) |
|
674 | + $metrics['weight'] = (($metrics['length'] * $metrics['width'] * $metrics['height']) / 6000) * 1000; |
|
675 | + } elseif (isset($metrics['weight']) AND |
|
676 | + isset($metrics['length']) AND |
|
677 | + isset($metrics['width']) AND |
|
678 | + isset($metrics['height']) |
|
679 | 679 | ) { |
680 | - $weight = (($metrics[ 'length' ] * $metrics[ 'width' ] * $metrics[ 'height' ]) / 6000) * 1000; |
|
680 | + $weight = (($metrics['length'] * $metrics['width'] * $metrics['height']) / 6000) * 1000; |
|
681 | 681 | |
682 | - if ($weight > $metrics[ 'weight' ]) { |
|
683 | - $metrics[ 'weight' ] = $weight; |
|
682 | + if ($weight > $metrics['weight']) { |
|
683 | + $metrics['weight'] = $weight; |
|
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | 687 | foreach ($metrics as $key => $value) { |
688 | - $params[ $key ] = $value; |
|
688 | + $params[$key] = $value; |
|
689 | 689 | } |
690 | 690 | } elseif (is_numeric($metrics)) { |
691 | - $params[ 'weight' ] = $metrics; |
|
691 | + $params['weight'] = $metrics; |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | switch ($this->accountType) { |
695 | 695 | case 'starter': |
696 | 696 | |
697 | - if ($params[ 'destinationType' ] === 'country') { |
|
698 | - $this->errors[ 301 ] = 'Unsupported International Destination. Tipe akun starter tidak mendukung pengecekan destinasi international.'; |
|
697 | + if ($params['destinationType'] === 'country') { |
|
698 | + $this->errors[301] = 'Unsupported International Destination. Tipe akun starter tidak mendukung pengecekan destinasi international.'; |
|
699 | 699 | |
700 | 700 | return false; |
701 | - } elseif ($params[ 'originType' ] === 'subdistrict' OR $params[ 'destinationType' ] === 'subdistrict') { |
|
702 | - $this->errors[ 302 ] = 'Unsupported Subdistrict Origin-Destination. Tipe akun starter tidak mendukung pengecekan ongkos kirim sampai kecamatan.'; |
|
701 | + } elseif ($params['originType'] === 'subdistrict' OR $params['destinationType'] === 'subdistrict') { |
|
702 | + $this->errors[302] = 'Unsupported Subdistrict Origin-Destination. Tipe akun starter tidak mendukung pengecekan ongkos kirim sampai kecamatan.'; |
|
703 | 703 | |
704 | 704 | return false; |
705 | 705 | } |
706 | 706 | |
707 | - if ( ! isset($params[ 'weight' ]) AND |
|
708 | - isset($params[ 'length' ]) AND |
|
709 | - isset($params[ 'width' ]) AND |
|
710 | - isset($params[ 'height' ]) |
|
707 | + if (!isset($params['weight']) AND |
|
708 | + isset($params['length']) AND |
|
709 | + isset($params['width']) AND |
|
710 | + isset($params['height']) |
|
711 | 711 | ) { |
712 | - $this->errors[ 304 ] = 'Unsupported Dimension. Tipe akun starter tidak mendukung pengecekan biaya kirim berdasarkan dimensi.'; |
|
712 | + $this->errors[304] = 'Unsupported Dimension. Tipe akun starter tidak mendukung pengecekan biaya kirim berdasarkan dimensi.'; |
|
713 | 713 | |
714 | 714 | return false; |
715 | - } elseif (isset($params[ 'weight' ]) AND $params[ 'weight' ] > 30000) { |
|
716 | - $this->errors[ 305 ] = 'Unsupported Weight. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).'; |
|
715 | + } elseif (isset($params['weight']) AND $params['weight'] > 30000) { |
|
716 | + $this->errors[305] = 'Unsupported Weight. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).'; |
|
717 | 717 | |
718 | 718 | return false; |
719 | 719 | } |
720 | 720 | |
721 | - if ( ! in_array($params[ 'courier' ], $this->supportedCouriers[ $this->accountType ])) { |
|
722 | - $this->errors[ 303 ] = 'Unsupported Courier. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[ $courier ] . '.'; |
|
721 | + if (!in_array($params['courier'], $this->supportedCouriers[$this->accountType])) { |
|
722 | + $this->errors[303] = 'Unsupported Courier. Tipe akun starter tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[$courier] . '.'; |
|
723 | 723 | |
724 | 724 | return false; |
725 | 725 | } |
@@ -728,30 +728,30 @@ discard block |
||
728 | 728 | |
729 | 729 | case 'basic': |
730 | 730 | |
731 | - if ($params[ 'originType' ] === 'subdistrict' OR $params[ 'destinationType' ] === 'subdistrict') { |
|
732 | - $this->errors[ 302 ] = 'Unsupported Subdistrict Origin-Destination. Tipe akun basic tidak mendukung pengecekan ongkos kirim sampai kecamatan.'; |
|
731 | + if ($params['originType'] === 'subdistrict' OR $params['destinationType'] === 'subdistrict') { |
|
732 | + $this->errors[302] = 'Unsupported Subdistrict Origin-Destination. Tipe akun basic tidak mendukung pengecekan ongkos kirim sampai kecamatan.'; |
|
733 | 733 | |
734 | 734 | return false; |
735 | 735 | } |
736 | 736 | |
737 | - if ( ! isset($params[ 'weight' ]) AND |
|
738 | - isset($params[ 'length' ]) AND |
|
739 | - isset($params[ 'width' ]) AND |
|
740 | - isset($params[ 'height' ]) |
|
737 | + if (!isset($params['weight']) AND |
|
738 | + isset($params['length']) AND |
|
739 | + isset($params['width']) AND |
|
740 | + isset($params['height']) |
|
741 | 741 | ) { |
742 | - $this->errors[ 304 ] = 'Unsupported Dimension. Tipe akun basic tidak mendukung pengecekan biaya kirim berdasarkan dimensi.'; |
|
742 | + $this->errors[304] = 'Unsupported Dimension. Tipe akun basic tidak mendukung pengecekan biaya kirim berdasarkan dimensi.'; |
|
743 | 743 | |
744 | 744 | return false; |
745 | - } elseif (isset($params[ 'weight' ]) AND $params[ 'weight' ] > 30000) { |
|
746 | - $this->errors[ 305 ] = 'Unsupported Weight. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).'; |
|
745 | + } elseif (isset($params['weight']) AND $params['weight'] > 30000) { |
|
746 | + $this->errors[305] = 'Unsupported Weight. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan berat lebih dari 30000 gram (30kg).'; |
|
747 | 747 | |
748 | 748 | return false; |
749 | - } elseif (isset($params[ 'weight' ]) AND $params[ 'weight' ] < 30000) { |
|
750 | - unset($params[ 'length' ], $params[ 'width' ], $params[ 'height' ]); |
|
749 | + } elseif (isset($params['weight']) AND $params['weight'] < 30000) { |
|
750 | + unset($params['length'], $params['width'], $params['height']); |
|
751 | 751 | } |
752 | 752 | |
753 | - if ( ! in_array($params[ 'courier' ], $this->supportedCouriers[ $this->accountType ])) { |
|
754 | - $this->errors[ 303 ] = 'Unsupported Courier. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[ $courier ] . '.'; |
|
753 | + if (!in_array($params['courier'], $this->supportedCouriers[$this->accountType])) { |
|
754 | + $this->errors[303] = 'Unsupported Courier. Tipe akun basic tidak mendukung pengecekan biaya kirim dengan kurir ' . $this->couriersList[$courier] . '.'; |
|
755 | 755 | |
756 | 756 | return false; |
757 | 757 | } |
@@ -759,8 +759,8 @@ discard block |
||
759 | 759 | break; |
760 | 760 | } |
761 | 761 | |
762 | - $params[ 'origin' ] = $origin[ key($origin) ]; |
|
763 | - $params[ 'destination' ] = $destination[ key($destination) ]; |
|
762 | + $params['origin'] = $origin[key($origin)]; |
|
763 | + $params['destination'] = $destination[key($destination)]; |
|
764 | 764 | |
765 | 765 | $path = key($destination) === 'country' ? 'internationalCost' : 'cost'; |
766 | 766 | |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | { |
785 | 785 | $courier = strtolower($courier); |
786 | 786 | |
787 | - if (in_array($courier, $this->supportedWayBills[ $this->accountType ])) { |
|
787 | + if (in_array($courier, $this->supportedWayBills[$this->accountType])) { |
|
788 | 788 | return $this->request('waybill', [ |
789 | 789 | 'key' => $this->apiKey, |
790 | 790 | 'waybill' => $idWaybill, |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | return $this->request('currency'); |
812 | 812 | } |
813 | 813 | |
814 | - $this->errors[ 301 ] = 'Unsupported Get Currency. Tipe akun starter tidak mendukung pengecekan currency.'; |
|
814 | + $this->errors[301] = 'Unsupported Get Currency. Tipe akun starter tidak mendukung pengecekan currency.'; |
|
815 | 815 | |
816 | 816 | return false; |
817 | 817 | } |
@@ -827,8 +827,8 @@ discard block |
||
827 | 827 | */ |
828 | 828 | public function getSupportedCouriers() |
829 | 829 | { |
830 | - if (isset($this->supportedCouriers[ $this->accountType ])) { |
|
831 | - return $this->supportedCouriers[ $this->accountType ]; |
|
830 | + if (isset($this->supportedCouriers[$this->accountType])) { |
|
831 | + return $this->supportedCouriers[$this->accountType]; |
|
832 | 832 | } |
833 | 833 | |
834 | 834 | return false; |
@@ -845,8 +845,8 @@ discard block |
||
845 | 845 | */ |
846 | 846 | public function getSupportedWayBills() |
847 | 847 | { |
848 | - if (isset($this->supportedWayBills[ $this->accountType ])) { |
|
849 | - return $this->supportedWayBills[ $this->accountType ]; |
|
848 | + if (isset($this->supportedWayBills[$this->accountType])) { |
|
849 | + return $this->supportedWayBills[$this->accountType]; |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | return false; |