diff --git a/README-ID.md b/README-ID.md index deab841..a3593b1 100644 --- a/README-ID.md +++ b/README-ID.md @@ -32,14 +32,19 @@ Ini adalah konten dari file config yang telah dipublish: ```php return [ + 'API_KEY' => env('RAJAONGKIR_KEY', 'somerandomstring'), + 'ACCOUNT_TYPE' => env('RAJAONGKIR_TYPE', 'starter') ]; ``` ## Penggunaan ```php -$laravel-rajaongkir = new Kodepintar\LaravelRajaongkir(); -echo $laravel-rajaongkir->echoPhrase('Hello, Kodepintar!'); +use Kodepintar\LaravelRajaongkir\LaravelRajaongkir as Ongkir; + +$data = new Ongkir(); +$data = $data->getProvince(); +return $data; ``` ## Kredit diff --git a/README.md b/README.md index f868836..943e7c4 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,19 @@ This is the contents of the published config file: ```php return [ + 'API_KEY' => env('RAJAONGKIR_KEY', 'somerandomstring'), + 'ACCOUNT_TYPE' => env('RAJAONGKIR_TYPE', 'starter') ]; ``` ## Usage ```php -$laravel-rajaongkir = new Kodepintar\LaravelRajaongkir(); -echo $laravel-rajaongkir->echoPhrase('Hello, Kodepintar!'); +use Kodepintar\LaravelRajaongkir\LaravelRajaongkir as Ongkir; + +$data = new Ongkir(); +$data = $data->getProvince(); +return $data; ``` ## Credits diff --git a/composer.json b/composer.json index 7d1bf66..081161b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "kodepintar/laravel-rajaongkir", "description": "This is my package laravel-rajaongkir", + "version": "1.0", "keywords": [ "kodepintar", "laravel", diff --git a/resources/views/.gitkeep b/resources/views/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/Commands/LaravelRajaongkirCommand.php b/src/Commands/LaravelRajaongkirCommand.php deleted file mode 100644 index 7cfde31..0000000 --- a/src/Commands/LaravelRajaongkirCommand.php +++ /dev/null @@ -1,17 +0,0 @@ -comment('All done'); - } -} diff --git a/src/LaravelRajaongkir.php b/src/LaravelRajaongkir.php index 917c6d3..f7b4f6b 100755 --- a/src/LaravelRajaongkir.php +++ b/src/LaravelRajaongkir.php @@ -2,12 +2,11 @@ namespace Kodepintar\LaravelRajaongkir; -use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Http; class LaravelRajaongkir { - public const BASE_URL = [ + protected $BASE_URL = [ 'starter' => 'https://api.rajaongkir.com/starter', 'basic' => 'https://api.rajaongkir.com/basic', 'pro' => 'https://pro.rajaongkir.com/api', @@ -17,19 +16,19 @@ class LaravelRajaongkir public function __construct() { - $accountType = config('rajaongkir.ACCOUNT_TYPE'); + $accountType = config('rajaongkir.ACCOUNT_TYPE', env('RAJAONGKIR_TYPE')); - $this->url = self::BASE_URL[$accountType]; + $this->url = $this->BASE_URL[$accountType]; return $this; } - protected function apiCall(string $urlPath, array $payload = [], string $method = 'GET'): Response + protected function apiCall(string $urlPath, array $payload = [], string $method = 'GET') { $url = $this->url . '/' . ltrim($urlPath, '/'); return Http::withHeaders([ - 'key' => config('rajangkir.API_KEY'), + 'key' => config('rajaongkir.API_KEY', env('RAJAONGKIR_KEY')), 'content-type' => 'application/x-www-form-urlencoded', ])->{strtolower($method)}($url, $payload); }