function _set_express_checkout($params)
 {
     global $osC_ShoppingCart, $osC_Currencies, $osC_Language, $osC_Tax, $messageStack, $osC_Database;
     // if there is nothing in the customers cart, redirect them to the shopping cart page
     if (!$osC_ShoppingCart->hasContents()) {
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, '', 'NONSSL', true, true, true));
     }
     $params['METHOD'] = 'SetExpressCheckout';
     $params['PAYMENTACTION'] = MODULE_PAYMENT_PAYPAL_EXPRESS_TRANSACTION_METHOD == 'Sale' || !osc_not_null(MODULE_PAYMENT_PAYPAL_EXPRESS_API_USERNAME) ? 'Sale' : 'Authorization';
     $params['RETURNURL'] = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . FILENAME_CHECKOUT . '?callback&module=paypal_express&express_action=retrieve';
     $params['CANCELURL'] = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . FILENAME_CHECKOUT . '?callback&module=paypal_express&express_action=cancel';
     $params['CURRENCYCODE'] = $osC_Currencies->getCode();
     //process item total account(not to include tax)
     $line_item_no = 0;
     $items_total = 0;
     if ($osC_ShoppingCart->hasContents()) {
         foreach ($osC_ShoppingCart->getProducts() as $product) {
             $product_name = $product['name'];
             //gift certificate
             if ($product['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                 $product_name .= "\n" . ' - ' . $osC_Language->get('senders_name') . ': ' . $product['gc_data']['senders_name'];
                 if ($product['gc_data']['type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                     $product_name .= "\n" . ' - ' . $osC_Language->get('senders_email') . ': ' . $product['gc_data']['senders_email'];
                 }
                 $product_name .= "\n" . ' - ' . $osC_Language->get('recipients_name') . ': ' . $product['gc_data']['recipients_name'];
                 if ($product['gc_data']['type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                     $product_name .= "\n" . ' - ' . $osC_Language->get('recipients_email') . ': ' . $product['gc_data']['recipients_email'];
                 }
                 $product_name .= "\n" . ' - ' . $osC_Language->get('message') . ': ' . $product['gc_data']['message'];
             }
             if ($osC_ShoppingCart->hasVariants($product['id'])) {
                 foreach ($osC_ShoppingCart->getVariants($product['id']) as $variant) {
                     $product_name .= ' - ' . $variant['groups_name'] . ': ' . $variant['values_name'];
                 }
             }
             $params['L_NAME' . $line_item_no] = $product_name;
             $params['L_AMT' . $line_item_no] = $osC_Currencies->formatRaw($product['final_price']);
             $params['L_NUMBER' . $line_item_no] = $product['id'];
             $params['L_QTY' . $line_item_no] = $product['quantity'];
             $items_total += $product['final_price'] * $product['quantity'];
             $line_item_no++;
         }
     }
     //process shipping (not to include tax)
     if (!class_exists('osC_Shipping')) {
         include 'includes/classes/shipping.php';
     }
     $osC_Shipping = new osC_Shipping();
     $shipping = $osC_Shipping->getQuote($osC_ShoppingCart->getShippingMethod('id'));
     $params['SHIPPINGAMT'] = $osC_Currencies->formatRaw($shipping['cost']);
     /**
      * process order totals, minus the coupon and gift certificate discount
      * if coupon type is freefship, we have to pass shipping fee with zero to paypal
      * the discount should not to include tax. otherwise, it will be rejected by the paypal
      * First we process gift certificate because we have to calculte the coupon fee based on total, item total, shipping total
      */
     //process gift certificate
     foreach ($osC_ShoppingCart->getOrderTotals() as $total) {
         if ($total['code'] == 'gift_certificate') {
             $params['L_NAME' . $line_item_no] = 'Discount Gift Certificate';
             $params['L_AMT' . $line_item_no] = -$osC_Currencies->formatRaw(abs($total['value']));
             $params['L_QTY' . $line_item_no] = 1;
             //minus the gift certificate discount from sub total(not to include the tax)
             $items_total -= abs($total['value']);
             $line_item_no++;
             break;
         }
     }
     //process the coupon
     foreach ($osC_ShoppingCart->getOrderTotals() as $total) {
         if ($total['code'] == 'coupon') {
             $coupon_amount = $osC_ShoppingCart->getTotal() - $osC_ShoppingCart->getTax() - $shipping['cost'] - $items_total;
             $params['L_NAME' . $line_item_no] = 'Discount Coupon';
             $params['L_AMT' . $line_item_no] = -$osC_Currencies->formatRaw(abs($coupon_amount));
             $params['L_QTY' . $line_item_no] = 1;
             //minus the coupon discount from sub total(not to include the tax)
             $items_total -= abs($coupon_amount);
             $line_item_no++;
             break;
         }
     }
     $params['ITEMAMT'] = $osC_Currencies->formatRaw($items_total);
     //pass total tax and order total
     $params['TAXAMT'] = $osC_Currencies->formatRaw($osC_ShoppingCart->getTax());
     $params['AMT'] = $osC_Currencies->formatRaw($osC_ShoppingCart->getTotal());
     //call the setExpressCheckout api
     $post_string = '';
     foreach ($params as $key => $value) {
         $post_string .= $key . '=' . urlencode(utf8_encode(trim($value))) . '&';
     }
     $post_string = substr($post_string, 0, -1);
     $response = $this->sendTransactionToGateway($this->api_url, $post_string);
     $response_array = array();
     parse_str($response, $response_array);
     if ($response_array['ACK'] == 'Success' || $response_array['ACK'] == 'SuccessWithWarning') {
         osc_redirect($this->paypal_url . '&token=' . $response_array['TOKEN'] . '&useraction=commit');
     } else {
         $messageStack->add_session('checkout', $osC_Language->get('payment_paypal_express_error_title') . ' <strong>' . stripslashes($response_array['L_LONGMESSAGE0']) . '</strong>');
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'checkout', 'SSL'));
     }
 }
 function get_error()
 {
     global $osC_Language;
     $message = $osC_Language->get('payment_sage_pay_form_error_general');
     if (isset($_GET['error']) && is_numeric($_GET['error']) && $this->errorMessageNumberExists($_GET['error'])) {
         $message = $this->getErrorMessage($_GET['error']) . ' ' . $message;
     } else {
         if (isset($_GET['crypt']) && osc_not_null($_GET['crypt'])) {
             $transaction_response = $this->simpleXor($this->base64Decode($_GET['crypt']), MODULE_PAYMENT_SAGE_PAY_FORM_ENCRYPTION_PASSWORD);
             $string_array = explode('&', $transaction_response);
             $return = array('Status' => null);
             foreach ($string_array as $string) {
                 if (strpos($string, '=') != false) {
                     $parts = explode('=', $string, 2);
                     $return[trim($parts[0])] = trim($parts[1]);
                 }
             }
             $error_number = $this->getErrorMessageNumber($return['StatusDetail']);
             if (is_numeric($error_number) && $this->errorMessageNumberExists($error_number)) {
                 $message = $this->getErrorMessage($error_number) . ' ' . $message;
             }
         }
     }
     $error = array('title' => $osC_Language->get('payment_sage_pay_form_error_title'), 'error' => $message);
     return $error;
 }
 function process()
 {
     global $osC_ShoppingCart, $osC_Database;
     $prep = explode('-', $_SESSION['prepOrderID']);
     if ($prep[0] == $osC_ShoppingCart->getCartID()) {
         $Qcheck = $osC_Database->query('select orders_status_id from :table_orders_status_history where orders_id = :orders_id');
         $Qcheck->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
         $Qcheck->bindInt(':orders_id', $prep[1]);
         $Qcheck->execute();
         $paid = false;
         if ($Qcheck->numberOfRows() > 0) {
             while ($Qcheck->next()) {
                 if ($Qcheck->valueInt('orders_status_id') == $this->order_status) {
                     $paid = true;
                 }
             }
         }
         if ($paid === false) {
             if (osc_not_null(MODULE_PAYMENT_PAYPAL_STANDARD_PROCESSING_ORDER_STATUS_ID)) {
                 osC_Order::process($_POST['invoice'], MODULE_PAYMENT_PAYPAL_STANDARD_PROCESSING_ORDER_STATUS_ID, 'PayPal Processing Transaction');
             }
         }
     }
     unset($_SESSION['prepOrderID']);
 }