You are here

function commerce_multicurrency_exchange_rate_sync_provider_google in Commerce Multicurrency 7

Fetch the currency exchange rates for the requested currency combination.

Return an array with the array(target_currency_code => rate) combination.

Parameters

string $currency_code: Source currency code.

array $target_currencies: Array with the target currency codes.

Return value

array Array with the array(target_currency_code => rate) combination.

1 string reference to 'commerce_multicurrency_exchange_rate_sync_provider_google'
commerce_multicurrency_commerce_multicurrency_exchange_rate_sync_provider_info in ./commerce_multicurrency.module
Implements hook_commerce_multicurrency_exchange_rate_sync_provider_info().

File

./commerce_multicurrency.google.inc, line 21
Default currency sync callback

Code

function commerce_multicurrency_exchange_rate_sync_provider_google($currency_code, $target_currencies) {
  $rates = array();
  foreach ($target_currencies as $target_currency_code) {
    $result = drupal_http_request('http://rate-exchange.appspot.com/currency?from=' . $currency_code . '&to=' . $target_currency_code);
    if ($result->code == 200) {
      $result_data = drupal_json_decode($result->data);
      $rates[$target_currency_code] = $result_data['rate'];
    }
    else {
      watchdog('commerce_multicurrency', 'Rate provider Google: Unable to fetch / process the currency data and returned !response', array(
        '!response' => print_r($result, TRUE),
      ), WATCHDOG_ERROR);
    }
  }
  return $rates;
}