<?php


namespace App\Services;


class PayService
{
    /**
     * @param $amount
     * @param $from_currency
     * @return string
     */
     public static function convertCurrency($amount, $from_currency)
     {
         $apikey = '9854f4ddf0735985226d80bbc39f45d6';

         $json = file_get_contents("http://api.exchangeratesapi.io/v1/latest?access_key=$apikey&symbols=GBP," . urlencode($from_currency));

         $obj = json_decode($json, true);

         $val = floatval($obj['rates']['GBP']) / floatval($obj['rates'][$from_currency]);

         $total = $val * $amount;
         return number_format($total, 2, '.', '');
     }


    /**
     * @param $currencyCode
     * @return string
     */
    public static function showCurrency( $currencyCode )
    {
        switch ( $currencyCode) {
            case 'GBP':
                $currencyOutput = '&pound;';
                break;
            case 'EUR':
                $currencyOutput = '&euro;';
                break;
            case 'AUD':
                $currencyOutput = 'AUD$';
                break;
            case 'USD':
                $currencyOutput = 'USD$';
                break;
            default:
                $currencyOutput = $currencyCode;
        }
        return $currencyOutput;
    }
}
