Bronanza / laravel-ongkir by erickkur

This package provides the use of raja ongkir API
85
0
2
Package Data
Maintainer Username: erickkur
Maintainer Contact: erickkur11@gmail.com (Erick Kurniawan)
Package Create Date: 2017-01-09
Package Last Update: 2017-01-15
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:16:11
Package Statistics
Total Downloads: 85
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel-Ongkir

Laravel ongkir provide the use of raja ongkir API in Laravel 5.

Contents

Installation

  1. To install laravel-ongkir, add the following code to composer.json. Then run composer update:
"bronanza/laravel-ongkir": "dev-master"
  1. Open your config/app.php and add the following code to provider:
Bronanza\LaravelOngkir\OngkirServiceProvider::class,
  1. Run the command below to publish package config file config/ongkir.php
php artisan vendor:publish
  1. You can fill api key for laravel ongkir in config/ongkir.php
<?php

return [
    'api' => 'http://api.rajaongkir.com/starter',
    'apiKey' => '12kasjdaksdqpwepqwoepqwoe',
    'originCityId' => 151, // Jakarta Barat Based on RajaOngkir API
    'couriers' => [
        'jne'  => 'JNE',
        'tiki' => 'TIKI'
    ]
];

Usage

  1. Add the following code in your class file:
use Bronanza\LaravelOngkir\Ongkir;
  1. Now you can use Laravel-Ongkir:
<?php
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Bronanza\LaravelOngkir\Ongkir;

class TestController extends Controller
{
    private $laravelOngkir;

    public function __construct(Ongkir $ongkir)
    {
        $this->laravelOngkir = $ongkir;
    }

    public function getAllAvailableProvinces()
    {
        return $this->laravelOngkir->getAllAvailableProvinces();
    }

    public function getAllAvailableCities()
    {
        return $this->laravelOngkir->getAllAvailableCities();
    }

    public function getAvailableCities()
    {
        return $this->laravelOngkir->getAvailableCities("5");
    }

    public function getCosts()
    {
        return $this->laravelOngkir->getCosts("501", "114", 1700, "jne");
    }
}

Explanation

  1. getAllAvailableProvinces() — use this method to get all available provinces in Indonesia.
  2. getAllAvailableCities() — use this method to get all available cities in Indonesia.
  3. getAvailableCities() — use this method to get available cities for the given province code. This method need 1 paramater:
    • string provinceCode - Province ID in Indonesia
  4. getCosts() — use this method to get shipment cost based on weight and location. This method need 4 parameter:
    • string originId - city origin
    • string rajaongkirCityId - city destination
    • int weight - shipment weight in gram
    • string courier - the available courier code: jne, pos, tiki.