/** * Applies surcharge of selected payment to cart total * * @param array $cart Array of the cart contents and user information necessary for purchase * @param array $auth Array of user authentication data (e.g. uid, usergroup_ids, etc.) * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.) * @return bool Always true */ function fn_update_payment_surcharge(&$cart, $auth, $lang_code = CART_LANGUAGE) { $cart['payment_surcharge'] = 0; if (!empty($cart['payment_id'])) { $_data = db_get_row("SELECT a_surcharge, p_surcharge FROM ?:payments WHERE payment_id = ?i", $cart['payment_id']); if (!empty($_data)) { if (floatval($_data['a_surcharge'])) { $cart['payment_surcharge'] += $_data['a_surcharge']; } if (floatval($_data['p_surcharge'])) { $cart['payment_surcharge'] += fn_format_price($cart['total'] * $_data['p_surcharge'] / 100); } } } if (!empty($cart['payment_surcharge'])) { $cart['payment_surcharge_title'] = db_get_field("SELECT surcharge_title FROM ?:payment_descriptions WHERE payment_id = ?i AND lang_code = ?s", $cart['payment_id'], $lang_code); // apply tax fn_calculate_payment_taxes($cart, $auth); } return true; }
/** * Applies surcharge of selected payment to cart total * * @param array $cart Array of the cart contents and user information necessary for purchase * @param array $auth Array of user authentication data (e.g. uid, usergroup_ids, etc.) * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.) * @return bool Always true */ function fn_update_payment_surcharge(&$cart, $auth, $lang_code = CART_LANGUAGE) { $cart['payment_surcharge'] = 0; // Calculate cart payment surcharge based on cart total if (!empty($cart['payment_id'])) { $surcharges = db_get_row("SELECT a_surcharge AS `absolute`, p_surcharge AS `percentage` FROM ?:payments WHERE payment_id = ?i", $cart['payment_id']); if (!empty($surcharges)) { if (floatval($surcharges['absolute'])) { $cart['payment_surcharge'] += $surcharges['absolute']; } if (floatval($surcharges['percentage'])) { $cart['payment_surcharge'] += fn_format_price($cart['total'] * $surcharges['percentage'] / 100); } } } if (!empty($cart['payment_surcharge'])) { // Apply surcharge title $cart['payment_surcharge_title'] = db_get_field("SELECT surcharge_title FROM ?:payment_descriptions WHERE payment_id = ?i AND lang_code = ?s", $cart['payment_id'], $lang_code); // Apply tax fn_calculate_payment_taxes($cart, $auth); } return true; }