Example #1
0
/**
 * Format a price amount.
 *
 * The available options that you can specify in the $args argument include:
 *     'display_currency_symbol' - Whether to attach the currency symbol to the figure.
 *                                 Defaults to true.
 *     'display_decimal_point'   - Whether to display the decimal point.
 *                                 Defaults to true.
 *     'display_currency_code'   - Whether to attach the currency code to the figure.
 *                                 Defaults to fault.
 *     'isocode'                 - Specify the isocode of the base country that you want to use for
 *                                 this price.
 *                                 Defaults to the settings in Settings->Store->General.
 *
 * @since 4.0
 * @uses  apply_filters() Applies 'wpsc_format_currency'                     filter
 * @uses  apply_filters() Applies 'wpsc_format_currency_currency_code'       filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_currency_symbol'     filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_decimal_separator'   filter.
 * @uses  apply_filters() Applies 'wpsc_format_currency_thousands_separator' filter.
 * @uses  apply_filters() Applies 'wpsc_modify_decimals' filter.
 * @uses  get_option()    Gets the value of 'currency_sign_location' in Settings->Store->General.
 * @uses  get_option()    Gets the value of 'currency_type' in Settings->Store->General.
 * @uses  WPSC_Country::__construct()
 * @uses  WPSC_Country::get()
 * @uses  wp_parse_args()
 *
 * @param  float|int|string $amt  The price you want to format.
 * @param  string|array     $args A query string or array containing the options. Defaults to ''.
 * @return string                 The formatted price.
 */
function wpsc_format_currency($amt, $args = '')
{
    $defaults = array('display_currency_symbol' => true, 'display_decimal_point' => true, 'display_currency_code' => false, 'isocode' => false, 'currency_code' => false);
    $args = wp_parse_args($args);
    // Either display symbol or code, not both
    if (array_key_exists('display_currency_symbol', $args)) {
        $args['display_currency_code'] = !$args['display_currency_symbol'];
    } elseif (array_key_exists('display_currency_code', $args)) {
        $args['display_currency_symbol'] = !$args['display_currency_code'];
    }
    $r = wp_parse_args($args, $defaults);
    extract($r);
    $currencies_without_fractions = WPSC_Payment_Gateways::currencies_without_fractions();
    if ($isocode) {
        $currency = new WPSC_Country($isocode);
    } else {
        $currency = new WPSC_Country(get_option('currency_type'));
    }
    $currency_code = $currency->get_currency_code();
    // No decimal point, no decimals
    if (!$display_decimal_point || in_array($currency_code, $currencies_without_fractions)) {
        $decimals = 0;
    } else {
        $decimals = 2;
        // default is 2
    }
    $decimals = apply_filters('wpsc_modify_decimals', $decimals, $isocode);
    $decimal_separator = apply_filters('wpsc_format_currency_decimal_separator', wpsc_get_option('decimal_separator'), $isocode);
    $thousands_separator = apply_filters('wpsc_format_currency_thousands_separator', wpsc_get_option('thousands_separator'), $isocode);
    // Format the price for output
    $formatted = number_format($amt, $decimals, $decimal_separator, $thousands_separator);
    if (!$display_currency_code) {
        $currency_code = '';
    }
    $symbol = $display_currency_symbol ? $currency->get_currency_symbol() : '';
    $symbol = esc_html($symbol);
    $symbol = apply_filters('wpsc_format_currency_currency_symbol', $symbol, $isocode);
    $currency_sign_location = get_option('currency_sign_location');
    // Rejig the currency sign location
    switch ($currency_sign_location) {
        case 1:
            $format_string = '%3$s%1$s%2$s';
            break;
        case 2:
            $format_string = '%3$s %1$s%2$s';
            break;
        case 4:
            $format_string = '%1$s%2$s  %3$s';
            break;
        case 3:
        default:
            $format_string = '%1$s %2$s%3$s';
            break;
    }
    $currency_code = apply_filters('wpsc_format_currency_currency_code', $currency_code, $isocode);
    // Compile the output
    $output = trim(sprintf($format_string, $currency_code, $symbol, $formatted));
    return $output;
}
Example #2
0
function _wpsc_filter_merchant_v3_gateway_form($form, $gateway_id)
{
    if (!WPSC_Payment_Gateways::is_registered($gateway_id)) {
        return $form;
    }
    $payment_gateway_names = get_option('payment_gateway_names');
    $form = array();
    $output = array('name' => ' ', 'form_fields' => __('To configure a payment module select one on the left.', 'wpsc'), 'has_submit_button' => 0);
    $gateway = wpsc_get_payment_gateway($gateway_id);
    $display_name = empty($payment_gateway_names[$gateway_id]) ? $gateway->get_title() : $payment_gateway_names[$gateway_id];
    ob_start();
    ?>
	<tr>
		<td style='border-top: none;'>
			<?php 
    _e('Display Name', 'wpsc');
    ?>
		</td>
		<td style='border-top: none;'>
			<input type='text' name='user_defined_name[<?php 
    echo esc_attr($gateway_id);
    ?>
]' value='<?php 
    echo esc_attr($display_name);
    ?>
' /><br />
			<span class='small description'><?php 
    _e('The text that people see when making a purchase.', 'wpsc');
    ?>
</span>
		</td>
	</tr>
	<?php 
    $gateway->setup_form();
    $output = array('name' => $gateway->get_title(), 'form_fields' => ob_get_clean(), 'has_submit_button' => 0);
    return $output;
}
 /**
  *
  * Return an array containing active gateway names.
  *
  * @access public
  * @since 3.9
  *
  * @return array
  */
 public static function get_active_gateways()
 {
     if (empty(self::$active_gateways)) {
         $selected_gateways = get_option('custom_gateway_options', array());
         $registered_gateways = self::get_gateways();
         self::$active_gateways = array_intersect($selected_gateways, $registered_gateways);
     }
     return apply_filters('wpsc_get_active_gateways', array_values(self::$active_gateways));
 }
 private function get_shipping_method_js_vars()
 {
     global $wpsc_cart;
     $js_var = array('subtotal' => (double) $wpsc_cart->calculate_subtotal(), 'shipping' => array(), 'tax' => wpsc_is_tax_enabled() && !wpsc_is_tax_included() ? (double) wpsc_cart_tax(false) : 0, 'discount' => wpsc_coupon_amount(false) > 0 ? wpsc_coupon_amount(false) : 0);
     foreach ($this->shipping_calculator->sorted_quotes as $module_name => $quotes) {
         foreach ($quotes as $option => $cost) {
             $id = $this->shipping_calculator->ids[$module_name][$option];
             $js_var['shipping'][$id] = $cost;
         }
     }
     $currency = new WPSC_Country(get_option('currency_type'));
     $currency_code = $currency->get_currency_code();
     $isocode = $currency->get_isocode();
     $without_fractions = in_array($currency_code, WPSC_Payment_Gateways::currencies_without_fractions());
     $decimals = $without_fractions ? 0 : 2;
     $decimals = apply_filters('wpsc_modify_decimals', $decimals, $isocode);
     $decimal_separator = apply_filters('wpsc_format_currency_decimal_separator', wpsc_get_option('decimal_separator'), $isocode);
     $thousands_separator = apply_filters('wpsc_format_currency_thousands_separator', wpsc_get_option('thousands_separator'), $isocode);
     $symbol = apply_filters('wpsc_format_currency_currency_symbol', $currency->get_currency_symbol());
     $sign_location = get_option('currency_sign_location');
     $js_var['formatter'] = array('currency_code' => $currency_code, 'without_fractions' => $without_fractions, 'decimals' => $decimals, 'decimal_separator' => $decimal_separator, 'thousands_separator' => $thousands_separator, 'symbol' => $symbol, 'sign_location' => $sign_location);
     return $js_var;
 }
Example #5
0
function _wpsc_filter_merchant_v3_payment_method_form_fields($fields)
{
    $selected_value = isset($_POST['wpsc_payment_method']) ? $_POST['wpsc_payment_method'] : '';
    if (empty($selected_value)) {
        $current_purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id');
        $purchase_log = new WPSC_Purchase_Log($current_purchase_log_id);
        $selected_value = $purchase_log->get('gateway');
    }
    foreach (WPSC_Payment_Gateways::get_active_gateways() as $gateway_name) {
        $gateway = (object) WPSC_Payment_Gateways::get_meta($gateway_name);
        $title = $gateway->name;
        if (!empty($gateway->image)) {
            $title .= ' <img src="' . $gateway->image . '" alt="' . $gateway->name . '" />';
        }
        if (!empty($gateway->mark)) {
            $title = $gateway->mark;
        }
        $field = array('title' => $title, 'type' => 'radio', 'value' => $gateway->internalname, 'name' => 'wpsc_payment_method', 'checked' => $selected_value == $gateway->internalname);
        $fields[] = $field;
    }
    // check the first payment gateway by default
    if (empty($selected_value)) {
        $fields[0]['checked'] = true;
    }
    return $fields;
}
Example #6
0
/**
 * Return True if the gateway is registered and active, false otherwise.
 *
 * @param string $gateway_id
 * @return bool
 */
function wpsc_is_gateway_active($gateway_id)
{
    $active_gateways = WPSC_Payment_Gateways::get_active_gateways();
    return in_array($gateway_id, $active_gateways);
}
Example #7
0
 private function gateway_list()
 {
     $selected_gateways = get_option('custom_gateway_options', array());
     foreach (WPSC_Payment_Gateways::get_gateways() as $gateway) {
         $gateway_meta = WPSC_Payment_Gateways::get_meta($gateway);
         $this->gateway_item($gateway, $gateway_meta['name'], in_array($gateway, $selected_gateways));
     }
     // compat with older API
     global $nzshpcrt_gateways;
     foreach ($nzshpcrt_gateways as $gateway) {
         if (isset($gateway['admin_name'])) {
             $gateway['name'] = $gateway['admin_name'];
         }
         $this->gateway_item($gateway['internalname'], $gateway['name'], in_array($gateway['internalname'], $selected_gateways));
     }
 }
Example #8
0
 function wpsc_gateways()
 {
     global $nzshpcrt_gateways;
     foreach (WPSC_Payment_Gateways::get_active_gateways() as $gateway_name) {
         $this->wpsc_gateways[] = WPSC_Payment_Gateways::get_meta($gateway_name);
     }
     $gateway_options = get_option('custom_gateway_options');
     foreach ($nzshpcrt_gateways as $gateway) {
         if (array_search($gateway['internalname'], (array) $gateway_options) !== false) {
             $this->wpsc_gateways[] = $gateway;
         }
     }
     $this->gateway_count = count($this->wpsc_gateways);
 }
Example #9
0
function wpsc_get_payment_gateway($gateway)
{
    return WPSC_Payment_Gateways::get($gateway);
}
function pbci_auth_register_gateway_file($gateway_controller)
{
    $gateway_file = dirname(__FILE__) . '/Authorize_Net_Credit_Card.php';
    WPSC_Payment_Gateways::register_file($gateway_file);
}