imagina/icurrency-module

This module manages currencies and conversions

1.0.6 2020-02-19 14:36 UTC

This package is auto-updated.

Last update: 2024-10-28 18:39:13 UTC


README

Installation

composer require imagina/icurrency

php artisan module:migrate Icurrency

php artisan db:seed --class=\\Modules\\Icurrency\\Database\\Seeders\\CurrencyTableSeederTableSeeder

Add middleware in acms/app/Http/Kernel.php

  protected $middleware = [
    // ...
      \Modules\Icurrency\Http\Middleware\CurrencyMiddleware::class,
    // ...
  ];

Note: This middleware expects the currency configuration within the object or from the request filter object. Example: api/iquote/v1/products?setting={"currency":"COP"} o api/iquote/v1/products?filter={"currency":"COP"}, 'settings' have higher priority.

Add command for updates TRM in acms/app/Console/Kernel.php

  protected $commands = [
    // ...
      Modules\Icurrency\Console\UpdateCurrencies::class
    // ...
  ];

Add .env your Api Key

Get your api key in currencyconverterapi

Free Forex API Rate Limits
Currency Pairs per Request: 2
Number of Requests per Hour: 100

CURRCONV_APIKEY=apikye

Run the following command the first time after making the migration to synchronize the currencies at the current exchange rate, after this they will be updated automatically with cron job.

php artisan currencies:update

Add command in schedule Laravel in acms/app/Console/Kernel.php

  protected function schedule(Schedule $schedule)
  {
    // ...
    $schedule->command(Modules\Icurrency\Console\UpdateCurrencies::class)->dailyAt('01:00');
    // ...
  }

Default Currencies Available

Use Facade Currency

Add follow line on the class that you need use this Facade:

use Modules\Icurrency\Support\Facades\Currency;

Methods Available

  • Convert a value:

      /* Example */
      Currency::convert(1000): 
  • Convert a value from one currency to another currency:

      /* Example */
      Currency::convertFromTo(1000, 'COP', 'AUD');
  • Get the current currency:

      /* Example */
      Currency::getLocaleCurrency();
  • Set current currency:

      /* Example */
      Currency::setLocaleCurrency('COP');
  • Get array with all current supported:

      /* Example */
      Currency::getSupportedCurrencies();

End Points

Route Base: https://yourhost/api/icurrency/v1/

  • Currencies

  • Attributes

    • Create.

      • Method: POST

      • Requires Authentication: ☑

      • Routes:

        • /currencies
      • Post params (Example):

        {
           attributes:{
             name: 'name',
             code: 'code',
             symbol_left: 'symbol_left',
             symbol_right: 'symbol_right',
             decimal_place: 'decimal_place',
             value: 'value',
             status: 'status',
             default_currency: 'default_currency',
           }
        }
        
    • Read

      • Method: GET

      • Requires Authentication: ☐

      • Routes:

        • /currencies
        • /currencies/id
      • Filters

    • Update

      • Method: PUT
      • Requires Authentication: ☑
      • Routes:
        • /currencies/id
    • Delete

      • Method: DELETE
      • Requires Authentication: ☑
      • Routes:
        • /currencies/id