PHP code example of dipantry / rupiah

1. Go to this page and download the library: Download dipantry/rupiah library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dipantry / rupiah example snippets


$app->withFacades();
$app->withEloquent();

$app->register(Dipantry\Rupiah\ServiceProvider::class);

// class_aliases
class_alias(Dipantry\Rupiah\Facade::class, 'Rupiah');

'providers' => [
    ...
    Dipantry\Rupiah\ServiceProvider::class,
],

'aliases' => [
    'Rajaongkir' => Dipantry\Rupiah\Facade::class,
],

return [
    'table_prefix' => 'Untuk migrasi dan seeding data',
    'timeout' => 'Waktu timeout untuk setiap pemanggilan API',
    'max_retry' => 'Jumlah perulangan yang dilakukan jika terjadi error',
]

use Dipantry\Rupiah\Models\Bank;

Bank::all();

\Rupiah::of(10000);

\Rupiah::of(10000)->getValue();
// 10000

use Dipantry\Rupiah\Enums\CurrencyCode;

\Rupiah::exchangeRate('USD');
// Mendapatkan nilai tukar rupiah terhadap USD pada hari ini
// ['buy' => 14000, 'sell' => 14200]

\Rupiah::exchangeRate('USD', '2021-01-01');
// Mendapatkan nilai tukar rupiah terhadap USD pada tanggal 1 Januari 2021
// ['buy' => 14000, 'sell' => 14200]

// atau

\Rupiah::exchangeRate(CurrencyCode::USD);

use Dipantry\Rupiah\Enums\CurrencyCode;

$rupiah = \Rupiah::of(10000);
$rupiah->buy(CurrencyCode::USD);
// 0.71

use Dipantry\Rupiah\Enums\CurrencyCode;

$rupiah = \Rupiah::of(10000);
$rupiah->sell(CurrencyCode::USD);
// 14200

\Rupiah::of(10000)->toWords();
// Sepuluh Ribu Rupiah
sh
php artisan vendor:publish --provider="Dipantry\Rupiah\ServiceProvider"
sh
php artisan migrate
sh
php artisan rupiah:bank