Index: include/func/func.paypal.php @@ -896,7 +896,7 @@ } $access['test_mode'] = $payment_method['testmode'] == 'Y'; - $access['currency'] = $payment_method['param03']; + $access['currency'] = func_paypal_get_currency($payment_method); $access['prefix'] = $payment_method['param06']; $access['protocol'] = $payment_method['protocol']; } @@ -1616,4 +1616,112 @@ return true; } + +/* + * Check if ItemTotal = sum(Amount*Quantity) and + * OrderTotal = ItemTotal + ShippingTotal + TaxTotal + HandlingTotal + */ +function func_paypal_is_line_items_allowed($cart, $pp_total = 0) +{ + if (empty($cart)) + return array(); + + $pp_currency = func_paypal_get_currency(); + + if (empty($pp_total)) + $pp_total = func_paypal_convert_to_BasicAmountType($cart["total_cost"], $pp_currency); + + $result = array( + 'OrderTotal' => $pp_total, + 'ItemTotal' => $pp_total, + 'ShippingTotal' => 0, + 'TaxTotal' => 0, + 'HandlingTotal' => 0 + ); + + if (isset($cart['display_subtotal'])) + $result['ItemTotal'] = $cart['display_subtotal']; + + if (isset($cart['display_shipping_cost'])) + $result['ShippingTotal'] = $cart['display_shipping_cost']; + + $delta = 0.0000000001; + $result['TaxTotal'] = $result['OrderTotal'] - $result['ItemTotal'] - $result['ShippingTotal']; + + if (abs($result['TaxTotal']) < $delta) + $result['TaxTotal'] = 0; + + settype($cart['products'], 'array'); + $products_total = 0; + foreach ($cart['products'] as $p) { + $price = func_paypal_convert_to_BasicAmountType($p["display_price"], $pp_currency); + $products_total += $price * $p['amount']; + } + + if ( + $result['TaxTotal'] < 0 + || abs($products_total - $result['ItemTotal']) > $delta + ) { + return array(); + } else { + return $result; + } +} + +function func_paypal_get_payment_details_items_soap($products) +{ + + if (empty($products)) + return ''; + + x_load('clean_urls'); + + $pp_currency = func_paypal_get_currency(); + + $out = ''; + foreach ($products as $p) { + $name = substr($p['product'], 0, 127); + $url = func_get_resource_url("P", $p['productid']); + + $amount = func_paypal_convert_to_BasicAmountType($p["display_price"], $pp_currency); + $out .= << + $name + $amount + $p[amount] + $url + +EOT; + } + + return $out . "\n"; +} + +function func_paypal_convert_to_BasicAmountType($val, $pp_curr='') +{ + settype($val, 'float'); + + if (empty($pp_curr)) + $pp_curr = func_paypal_get_currency(); + + if (in_array($pp_curr, array('JPY','TWD','HUF'))) { + #bt:0089724 + $new_val = sprintf("%0.2f", floor($val)); + } else { + $new_val = sprintf("%0.2f", $val); + } + + return $new_val; +} + +function func_paypal_get_currency($params = array()) +{ + if (empty($params)) { + global $module_params; + return isset($module_params['param03']) ? $module_params['param03'] : 'USD'; + } else { + return isset($params['param03']) ? $params['param03'] : 'USD'; + } +} ?>