Coder Social home page Coder Social logo

raja-ongkir's Introduction

🚀Raja Ongkir Laravel Package

Scrutinizer Code Quality Build Status Latest Stable Version PHP

Buy Me A Coffee ko-fi

Package ini berguna untuk mengecek biaya ongkos kirim dari kurir, package ini dapat digunakan di Laravel 5/6/7 atau PHP Native. (untuk saat ini hanya mendukung tipe akun starter)

🛠️ Installation with Composer

composer require irfa/raja-ongkir

You can get Composer here

🛠️ PHP Native Setup

  <?php 
     require "vendor/autoload.php";
        
     use Irfa\RajaOngkir\Ongkir\Ongkir as RajaOngkir;
     ....

Configuration File

Config location : vendor/irfa/raja-ongkir/config/config.php

<?php
	$config = [
		'account_type' => 'your-account-type',

		'api_key' => 'your-api-key',
	];

You can get API key in Raja Ongkir.
Account type supported : starter.


🛠️ Laravel Setup

Add to config/app.php

'providers' => [
      ....
         Irfa\RajaOngkir\RajaOngkirServiceProvider::class, 
     ];

Add to config/app.php

'aliases' => [
         ....
    'RajaOngkir' => Irfa\RajaOngkir\Facades\Ongkir::class,

    ],

Publish Vendor

php artisan vendor:publish --tag=raja-ongkir

Open .env file and add this line

....
RAJAONGKIR_ACCOUNT_TYPE=starter
RAJAONGKIR_API_KEY=your-api-key
RAJAONGKIR_PROV_TABLE=ro_province
RAJAONGKIR_CITY_TABLE=ro_city
RAJAONGKIR_CACHE=database

🚀 Caching

Caching is useful for loading city and province faster🚀.
You can change cache type in config/irfa/rajaongkir.php or project_name/.env.
This function currently only supports the Laravel Framework

Cache support : database and file
( if you don't want to use cache you can set it to null )

Migrating table city and provinsi

If you want to use database cache, you must run migrate first.

php artisan migrate

Caching Province,Sub-District and City


Open console/cmd and run

php artisan raja-ongkir:cache all

Caching City


Open console/cmd and run

php artisan raja-ongkir:cache city

Caching Province


Open console/cmd and run

php artisan raja-ongkir:cache province

Clear Cache


Open console/cmd and run

php artisan raja-ongkir:cache clear

Refresh Cache


Clear old cache and create latest cache.
Open console/cmd and run

php artisan raja-ongkir:cache refresh

💻 Usage

  use RajaOngkir;

Retrieve all province

 $get = RajaOngkir::province()->get();
 foreach($get as $prov)
 {
	echo $prov->province_id."<br>"; // value = 1
	echo $prov->province."<br>";// value = Bali
 }

Search province

   $get = RajaOngkir::find(['province_id' => 1])->province()->get();
	echo $get->province_id."<br>"; // value = 1
	echo $get->province."<br>";// value = Bali

Retrieve all City

$get = RajaOngkir::city()->get();
foreach($get as $city)
{
	echo $city->city_id."<br>"; // value = 17
	echo $city->province_id."<br>";// value = 1
	echo $city->province."<br>";// value = Bali
	echo $city->type."<br>"; // value = Kabupaten
	echo $city->city_name."<br>"; // value = Badung
	echo $city->postal_code."<br>"; // value = 80351
}

Retrieve all city in province

    $get = RajaOngkir::find(['province_id' => 1])->city()->get();
    foreach($get as $city){
		echo $city->city_id."<br>"; // value = 17
		echo $city->province_id."<br>";// value = 1
		echo $city->province."<br>";// value = Bali
		echo $city->type."<br>"; // value = Kabupaten
		echo $city->city_name."<br>"; // value = Badung
		echo $city->postal_code."<br>"; // value = 80351
     }

Retrieve courier

  $get = RajaOngkir::find(['origin'=>1,'destination'=>2,'weight'=>1000,'courier' => 'jne'])
	 ->courier()->get();
  foreach($get as $city)
  {
	echo $city->code."<br>"; // value = jne
	echo $city->name."<br>";// value = Jalur Nugraha Ekakurir (JNE)
  }

Retrieve cost courier

 $params = ['origin'=>1,'destination'=>2,'weight'=>1000,'courier' => 'jne'
			   ];
     $get = RajaOngkir::find($params)->costDetails()->get();
     foreach($get as $cost)
     {
	echo "Courier Name: ".$cost->service."<br>";
	echo "Description: ".$cost->description."<br>";
	 foreach($cost->cost as $detail)
	 {
		echo "Harga: ".$detail->value."<br>";
		echo "Estimasi: ".$detail->etd."<br>";
		echo "Note: ".$detail->note."<br>";
		echo "<hr>";
	 }
      }

How to Contributing?

  1. Fork it (https://github.com/irfaardy/raja-ongkir/fork)
  2. Commit your changes (git commit -m 'New Feature')
  3. Push to the branch (git push origin master)
  4. Create a new Pull Request

if you found bug or error, please post here https://github.com/irfaardy/raja-ongkir/issues so that they can be maintained together.


Bagaimana cara berkontribusi?

  1. Lakukan fork di (https://github.com/irfaardy/raja-ongkir/fork)
  2. Commit perubahan yang anda lakukan (git commit -m 'Fitur Baru')
  3. Push ke branch master (git push origin master)
  4. Buat Pull Request baru

Issue

If you found issues or bug please create new issues here https://github.com/irfaardy/php-gacha/issues/new

Jika anda menemukan bug atau error silahkan posting disini https://github.com/irfaardy/raja-ongkir/issues agar dapat diperbaiki bersama-sama.


raja-ongkir's People

Contributors

irfaardy avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

raja-ongkir's Issues

kurang jelas bang

bang. bagaimana cara menggunakannya. saya mentik di penggunaan pada bagian "use rajaongkir;"
itu dimasukin di page mana dan selanjurnya dimana? maap bang newbee

Class "RajaOngkir" not found

Saya mencoba menggunakan layanan rajaongkir, namun json saya tidak mau terlihat dengan kode error "Class "RajaOngkir" not found". Mohon bantuannya

^ Error {#267 #message: "Class "RajaOngkir" not found" #code: 0 #file: "C:\Users\William\Documents\Pacar\New with rajaongkir\prognetmodul2\app\Http\Controllers\CheckOngkirController.php" #line: 40

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.