Download the PHP package risan/jne without Composer
On this page you can find all versions of the php package risan/jne. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package jne
Short Description PHP HTTP client library for checking JNE shipment prices.
License MIT
Homepage https://github.com/risan/jne
Informations about the package jne
JNE HTTP Client
PHP HTTP client library for communicating with JNE website. This library can be used to retrieve JNE's delivery tariff and all available delivery locations.
Table of Contents
- Dependencies
- Installation
- Basic Usage
- Search for Origin
- Search for Destination
- Get Delivery Options
- Find or Create Origin Location
- Find or Create Destination Location
- Create Weight Instance
- Create Package Instance
- List All Available Options
Dependencies
This package relies on the following libraries to work:
All above dependencies will be automatically downloaded if you are using Composer to install this package.
Installation
To install this library using Composer, simply run the following command inside your project directory:
Or you may also add risan\jne package into your composer.json file like so:
Then don't forget to run the following command to install this library:
Basic Usage
Here is some basic example about how to use this library:
Search for Origin
To search for available origin cities or locations, we can use searchOrigin() method that owned by the Jne\Jne class. We only need to pass the $query parameter which is a string.
This method will perform a HTTP request to jne.co.id website in order to search for all available origin locations that match the given $query.
On success this method will return an instance of Jne\Collections\LocationCollection class which contains a collection of Jne\Location instances. The LocationCollection itself is a subclass of Illuminate\Support\Collection, so we may leverage the rich features of Laravel's collection.
For example, we can find all available origin locations that matched the word bandar like so:
We can transform $origin into an array using toArray() method and see that it contains several Jne\Location instances:
Search for Destination
To search for all available destination cities or locations, we can use searchDestination() method. The usage is very identical with searchOrigin() method:
This method will also perform a HTTP request to jne.co.id website to search for all available destination locations that match the given $query.
This method will also return an instance of Jne\Collections\LocationCollection class.
For example, we'd like to search for destination locations that match purwodadi, we can do it like so:
If we printed out the $destinations results, we will get the following output:
Get Delivery Options
With this library we can also get all available delivery options offered by JNE, listing all the tariffs and estimatted delivery days.
Find or Create Origin Location
First we need to find or create an origin location of the package, it must be an instance of Jne\Location class. To find the origin location, we can use searchOrigin() method:
The $bandung variable will hold the following value:
If you already know the location's code, you may also create the Jne\Location instance manually. With this way we don't have to create an additional HTTP request to JNE website:
For example if we already know that BANDUNG has a location's code of QkRPMTAwMDA=, then we can create Jne\Location instance like so:
Find or Create Destination Location
The second step is to find or create a destination location of the package. To find the destination location:
Now the above $depok variable will hold the following value:
In case you already know the destination location's code, you can create an instance of Jne\Location manually:
For example if we already know that DEPOK as the destination has a location's code of RFBLMTAwMDA=, then we can create it like so:
Create Weight Instance
The third step is to create a Jne\Weight instance that reflects our package's weight. We have several ways to create a Jne\Weight instance:
For example if our package is 10 kilograms in weight, we need to create an instance on weight class like so:
Create Package Instance
The forth step is to create an instance of Jne\Package class. This instance represents our package that needs to be delivered.
Both the $origin and the $destination are instances of Jne\Location instance. While the $weight is an instance of Jne\Weight class.
Here is the complete example of how to create a package instance:
List All Available Options
And the last step to retrieve all available delivery options is to call the deliveryOptions() method and pass the Jne\Package instance:
This method will return an instance of Jne\Collections\DeliveryOptionCollection class which consist of a collection of Jne\DeliveryOption instances. Just like the LocationCollection class, this DeliveryOptionCollection class is also a subclass of Illuminate\Support\Collection.
For example we can fetch all available delivery options for 10 kilograms package from BANDUNG to DEPOK like so:
The $deliveryOptions will contain the collection of Jne\DeliveryOption instances. If we printed out the $deliveryOptions to the console, we'll get a list of various delivery options:
All versions of jne with dependencies
illuminate/support Version ^5.1
symfony/dom-crawler Version ^3.0
symfony/css-selector Version ^3.0

