raw($messageText, function ($message) use ($recipients, $title) { $message->subject($title); $message->to($recipients); }); // return $this->successResponse("mail envoye"); } public function checkPassword($password, $encrypted_password, $salt) { $encrypted_password_to_check = base64_encode(sha1($password . $salt, true) . $salt); return $encrypted_password_to_check == $encrypted_password; } public function hashSSHA($string) { $salt = sha1(rand()); $salt = substr($salt, 0, 10); $encrypted = base64_encode(sha1($string . $salt, true) . $salt); $hash = array("salt" => $salt, "encrypted" => $encrypted); return $hash; } public function getCountryName($id_country){ return Country::findOrFail($id_country)->name; } public function toMoneyWithNetwork($amount , $id_network){ $currency = collect(DB::select('SELECT cu.code FROM networks n INNER JOIN countries c ON c.id = n.country_id INNER JOIN currencies cu ON cu.id = c.idCurrency WHERE n.id = :id',['id'=>$id_network]))->first(); $money = Money::of(round($amount, 2),$currency ? $currency->code : 'XAF',new AutoContext()); return $money->formatTo('fr_FR'); } public function toMoney($amount, $id_country) { $country = Country::findOrFail($id_country); $money = Money::of(round($amount, 2),$country->currency->code,new AutoContext()); return $money->formatTo('fr_FR'); } private function convertMoney($amount , $init_country , $final_country) { // set to whatever your rates are relative to $baseCurrency = 'USD'; // use your own credentials, or re-use your existing PDO connection $pdo = new PDO('mysql:host=' .env('DB_HOST') . ';dbname=' .env('DB_DATABASE'), env('DB_USERNAME'), env('DB_PASSWORD')); $configuration = new PDOProviderConfiguration(); $configuration->tableName = 'exchange_rate'; $configuration->exchangeRateColumnName = 'exchange_rate'; $configuration->targetCurrencyColumnName = 'target_currency'; $configuration->sourceCurrencyCode = $baseCurrency; // this provider loads exchange rates from your database $provider = new PDOProvider($pdo, $configuration); // this provider calculates exchange rates relative to the base currency $provider = new BaseCurrencyProvider($provider, $baseCurrency); // this currency converter can now handle any currency pair $converter = new CurrencyConverter($provider); $init_country = Country::findOrFail($init_country); $final_country = Country::findOrFail($final_country); $init_money = Money::of(round($amount, 2),$init_country->currency->code,new AutoContext()); return $converter->convert($init_money, $final_country->currency->code, RoundingMode::DOWN); } public function toMoneyWithCurrency($amount , $init_country , $final_country){ return $this->convertMoney($amount , $init_country , $final_country)->formatTo('fr_FR'); } public function toMoneyAmount($amount , $init_country , $final_country){ return $this->convertMoney($amount , $init_country , $final_country)->getAmount()->toFloat(); } public function toUSDAmount($amount , $init_country , $final_currency_code = 'USD'){ // set to whatever your rates are relative to $baseCurrency = 'USD'; // use your own credentials, or re-use your existing PDO connection $pdo = new PDO('mysql:host=' .env('DB_HOST') . ';dbname=' .env('DB_DATABASE'), env('DB_USERNAME'), env('DB_PASSWORD')); $configuration = new PDOProviderConfiguration(); $configuration->tableName = 'exchange_rate'; $configuration->exchangeRateColumnName = 'exchange_rate'; $configuration->targetCurrencyColumnName = 'target_currency'; $configuration->sourceCurrencyCode = $baseCurrency; // this provider loads exchange rates from your database $provider = new PDOProvider($pdo, $configuration); // this provider calculates exchange rates relative to the base currency $provider = new BaseCurrencyProvider($provider, $baseCurrency); // this currency converter can now handle any currency pair $converter = new CurrencyConverter($provider); $init_country = Country::findOrFail($init_country); $init_money = Money::of(round($amount, 2),$init_country->currency->code,new AutoContext()); return $converter->convert($init_money, $final_currency_code, RoundingMode::DOWN)->getAmount()->toFloat(); } // public function getTransactionID(){ // $d = new DateTime(); // $first = str_replace(['-',':'], '',$d->format("y-m-d H:i:s.u")); // return str_replace(' ' ,'.',$first); // } public function getCurrency($id_country){ $cc = CountriesCurrency::findOrFail($id_country); return $cc->currency_code; } }