Advertisement
businessdad

Aelia Currency Switcher - Convert Payeezy payments to USD

Jan 30th, 2017
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. /**
  2.  * Converts an amount from one currency to another, using the Aelia Currency
  3.  * Switcher.
  4.  *
  5.  * @param double amount The amount to convert.
  6.  * @param string to_currency The target currency.
  7.  * @param string from_currency The source currency.
  8.  * @return double
  9.  */
  10. function aelia_convert_amount_to_currency($amount, $to_currency, $from_currency) {
  11.   // Call the currency conversion filter.
  12.   return apply_filters('wc_aelia_cs_convert', $amount, $from_currency, $to_currency);
  13. }
  14.  
  15. /**
  16.  * Converts the payments passed to Payeezy to USD.
  17.  *
  18.  * @param array request_data The data used for a payment request.
  19.  * @param object A paument request instance.
  20.  * @return array The payment data, with the amount in USD.
  21.  * @author Aelia
  22.  * @link https://bit.ly/aelia_codeable
  23.  */
  24. add_filter( 'wc_first_data_payeezy_gateway_request_data', function($request_data, $payment_request) {
  25.   if(strtoupper($request_data['currency_code']) != 'USD') {
  26.     $request_data['amount'] = round(aelia_convert_amount_to_currency($request_data['amount'], 'USD', $request_data['currency_code']), 2);
  27.   }
  28.   return $request_data;
  29. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement