--- ecommerce\payment\payment.module Sat Jun 10 09:01:47 2006 +++ payment.module Tue Jul 04 05:20:00 2006 @@ -43,6 +43,24 @@ } /** + * Implementation of cron_hook() + */ +function payment_cron() { + if (variable_get('payment_multicur', 0) && module_exist('currency_api') && variable_get('payment_multicur_dynamic', 0)) { + $from = variable_get('payment_code', 'USD'); + $to = variable_get('payment_display_code', 'HKD'); + $amt = 1; + $ret = currency_api_convert($from, $to, $amt); + if ($ret['status'] == FALSE) { + watchdog('ecommerce', t('%message', array('%message' => $ret['message']))); + } + else { + variable_set('payment_multicur_rate', $ret['value']); + } + } +} + +/** * Implementation of hook_checkoutapi(). */ function payment_checkoutapi(&$txn, $op, $arg3 = NULL, $arg4 = NULL) { @@ -109,43 +127,142 @@ '#collapsible' => TRUE, '#collapsed' => TRUE, ); - $form['price_format']['payment_symbol'] = array( + $form['price_format']['payment_multicur'] = array( + '#type' => 'radios', + '#title' => t('Enable Multiple Currency'), + '#default_value' => variable_get('payment_multicur', 0), + '#options' => array(t('Disabled'), t('Enabled')), + '#desciption' => t('If enabled, your product price will display in multiple currency format.'), + ); + if (variable_get('payment_multicur', 0)) { + $form['price_format']['payment_multicur_dynamic'] = array( + '#type' => 'radios', + '#title' => t('Enable Dynamic Update Exchange Rates'), + '#default_value' => variable_get('payment_multicur_dynamic', 0), + '#options' => array(t('Disabled'), t('Enabled')), + '#desciption' => t('If enabled, exchange rates will change due to currency_api.'), + ); + $form['price_format']['payment_multicur_rate'] = array( + '#type' => 'textfield', + '#title' => t('Current Exchange Rates'), + '#default_value' => variable_get('payment_multicur_rate', '7.80'), + '#size' => 5, '#maxlength' => 10, + '#description' => t('Current exchange rates. This will be updated by cron if enable Dynamic Update Exhange Rates. Requires currency_api module for automatically update.'), + ); + } + + // Basic formatting + $form['price_format']['base_format'] = array( + '#type' => 'fieldset', + '#title' => t('System Currency Formatting'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['price_format']['base_format']['payment_code'] = array( + '#type' => 'textfield', + '#title' => t('Currency Code'), + '#default_value' => variable_get('payment_code', 'USD'), + '#size' => 3, + '#maxlength' => 3, + '#description' => t('Enter the three letter currency code for your price. This will be displayed in front of the price.'), + ); + $form['price_format']['base_format']['payment_symbol'] = array( '#type' => 'textfield', '#title' => t('Currency Symbol'), '#default_value' => variable_get('payment_symbol', '$'), '#size' => 3, '#maxlength' => 5, - '#desciption' => t('Enter the currency symbol you wish to associate with your price. This will be displayed in front of the price. Default is the dollar symbol.') + '#desciption' => t('Enter the currency symbol you wish to associate with your price. This will be displayed in front of the price. Default is the dollar symbol.'), ); - $form['price_format']['payment_symbol_position'] = array( + $form['price_format']['base_format']['payment_symbol_position'] = array( '#type' => 'radios', '#title' => t('Currency Symbol'), '#default_value' => variable_get('payment_symbol_position', 1), '#options' => array(t('Right'), t('Left')), - '#desciption' => t('This option places the currency symbol of the left or right side of the price.') + '#desciption' => t('This option places the currency symbol of the left or right side of the price.'), ); - $form['price_format']['payment_thousands'] = array( + $form['price_format']['base_format']['payment_thousands'] = array( '#type' => 'textfield', '#title' => t('Thousands separator'), '#default_value' => variable_get('payment_thousands', ','), - '#size' => 3, '#maxlength' => 5, - '#desciption' => t('Enter the sign for the thousands separator.') - ); - $form['price_format']['payment_decimal'] = array( + '#size' => 3, + '#maxlength' => 5, + '#desciption' => t('Enter the sign for the thousands separator.'), + ); + $form['price_format']['base_format']['payment_decimal'] = array( '#type' => 'textfield', '#title' => t('Decimal separator'), '#default_value' => variable_get('payment_decimal', '.'), - '#size' => 3, '#maxlength' => 5, - '#desciption' => t('Enter the sign to seperate real numbers from floating numbers.') - ); - $form['price_format']['payment_decimal_places'] = array( + '#size' => 3, + '#maxlength' => 5, + '#desciption' => t('Enter the sign to seperate real numbers from floating numbers.'), + ); + $form['price_format']['base_format']['payment_decimal_places'] = array( '#type' => 'textfield', '#title' => t('Number of places after the decimal separator'), '#default_value' => variable_get('payment_decimal_places', 2), - '#size' => 3, '#maxlength' => 5, - '#desciption' => t('How many slots are needed after the decimal?') - ); - + '#size' => 3, + '#maxlength' => 5, + '#desciption' => t('How many slots are needed after the decimal?'), + ); + + // Display formatting + if (variable_get('payment_multicur', 0)) { + $form['price_format']['display_format'] = array( + '#type' => 'fieldset', + '#title' => t('Display Currency Formatting'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['price_format']['display_format']['payment_display_code'] = array( + '#type' => 'textfield', + '#title' => t('Currency Code'), + '#default_value' => variable_get('payment_display_code', 'HKD'), + '#size' => 3, + '#maxlength' => 3, + '#description' => t('Enter the three letter currency code for your price. This will be displayed in front of the price.'), + ); + $form['price_format']['display_format']['payment_display_symbol'] = array( + '#type' => 'textfield', + '#title' => t('Currency Symbol'), + '#default_value' => variable_get('payment_display_symbol', '$'), + '#size' => 3, + '#maxlength' => 5, + '#desciption' => t('Enter the currency symbol you wish to associate with your price. This will be displayed in front of the price. Default is the dollar symbol.'), + ); + $form['price_format']['display_format']['payment_display_symbol_position'] = array( + '#type' => 'radios', + '#title' => t('Currency Symbol'), + '#default_value' => variable_get('payment_display_symbol_position', 1), + '#options' => array(t('Right'), t('Left')), + '#desciption' => t('This option places the currency symbol of the left or right side of the price.'), + ); + $form['price_format']['display_format']['payment_display_thousands'] = array( + '#type' => 'textfield', + '#title' => t('Thousands separator'), + '#default_value' => variable_get('payment_display_thousands', ','), + '#size' => 3, + '#maxlength' => 5, + '#desciption' => t('Enter the sign for the thousands separator.'), + ); + $form['price_format']['display_format']['payment_display_decimal'] = array( + '#type' => 'textfield', + '#title' => t('Decimal separator'), + '#default_value' => variable_get('payment_display_decimal', '.'), + '#size' => 3, + '#maxlength' => 5, + '#desciption' => t('Enter the sign to seperate real numbers from floating numbers.'), + ); + $form['price_format']['display_format']['payment_display_decimal_places'] = array( + '#type' => 'textfield', + '#title' => t('Number of places after the decimal separator'), + '#default_value' => variable_get('payment_display_decimal_places', 2), + '#size' => 3, + '#maxlength' => 5, + '#desciption' => t('How many slots are needed after the decimal?'), + ); + } + // Begin recurring payments $form['recurring_payments'] = array( '#type' => 'fieldset', @@ -453,11 +570,26 @@ * Format the price according to payment_settings() config options. */ function payment_format($price) { + $code = variable_get('payment_code', 'USD'); + $symbol = variable_get('payment_symbol', '$'); $price = number_format((float) $price, variable_get('payment_decimal_places', 2), variable_get('payment_decimal', '.'), variable_get('payment_thousands', ',')); - return (variable_get('payment_symbol_position', 1) == 1) ? variable_get('payment_symbol', '$') . $price : $price . variable_get('payment_symbol', '$'); + $return = (variable_get('payment_symbol_position', 1) == 1) ? t("$code") . ' ' . $symbol . $price : t("$code") . ' ' . $price . $symbol; + + if (variable_get('payment_multicur', 0)) { + $return .= ' | '; + $display_code = variable_get('payment_display_code', 'HKD'); + $display_symbol = variable_get('payment_display_symbol', '$'); + $display_price = number_format((float) $price * (float) variable_get('payment_multicur_rate', '7.80'), + variable_get('payment_display_decimal_places', 2), + variable_get('payment_display_decimal', '.'), + variable_get('payment_display_thousands', ',')); + $return .= (variable_get('payment_display_symbol_position', 1) == 1) ? t("$display_code") . ' ' . $display_symbol . $display_price : t("$display_code") . ' ' . $display_price . $display_symbol; + } + + return $return; } function payment_accepted($txnid) {