Exemple #1
0
 /**
  * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
  * This sends the data to the payment gateway for processing.
  * (These are hidden fields on the checkout confirmation page)
  *
  * @return string
  */
 function process_button()
 {
     global $db, $order, $currencies, $currency;
     $options = array();
     $optionsCore = array();
     $optionsPhone = array();
     $optionsShip = array();
     $optionsLineItems = array();
     $optionsAggregate = array();
     $optionsTrans = array();
     $buttonArray = array();
     // save the session stuff permanently in case paypal loses the session
     $_SESSION['ppipn_key_to_remove'] = session_id();
     $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'");
     $sql = "insert into " . TABLE_PAYPAL_SESSION . " (session_id, saved_session, expiry) values (\n            '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "',\n            '" . base64_encode(serialize($_SESSION)) . "',\n            '" . (time() + 1 * 60 * 60 * 24 * 2) . "')";
     $db->Execute($sql);
     $my_currency = select_pp_currency();
     $this->transaction_currency = $my_currency;
     $this->totalsum = $order->info['total'] = zen_round($order->info['total'], 2);
     $this->transaction_amount = zen_round($this->totalsum * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
     $telephone = preg_replace('/\\D/', '', $order->customer['telephone']);
     if ($telephone != '') {
         $optionsPhone['H_PhoneNumber'] = $telephone;
         if (in_array($order->customer['country']['iso_code_2'], array('US', 'CA'))) {
             $optionsPhone['night_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['night_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['night_phone_c'] = substr($telephone, 6, 4);
             $optionsPhone['day_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['day_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['day_phone_c'] = substr($telephone, 6, 4);
         } else {
             $optionsPhone['night_phone_b'] = $telephone;
             $optionsPhone['day_phone_b'] = $telephone;
         }
     }
     $optionsCore = array('lc' => $this->getLanguageCode(), 'charset' => CHARSET, 'page_style' => MODULE_PAYMENT_PAYPAL_PAGE_STYLE, 'custom' => zen_session_name() . '=' . zen_session_id(), 'business' => MODULE_PAYMENT_PAYPAL_BUSINESS_ID, 'return' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=paypal', 'SSL'), 'cancel_return' => zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'), 'shopping_url' => zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'), 'notify_url' => zen_href_link('ipn_main_handler.php', '', 'SSL', false, false, true), 'redirect_cmd' => '_xclick', 'rm' => 2, 'bn' => 'CNZcart_Cart_EC', 'mrb' => 'R-4DM17246PS436904F', 'pal' => 'GR5QUVVL9AFGN');
     $optionsCust = array('first_name' => replace_accents($order->customer['firstname']), 'last_name' => replace_accents($order->customer['lastname']), 'address1' => replace_accents($order->customer['street_address']), 'city' => replace_accents($order->customer['city']), 'state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['state']), 'zip' => $order->customer['postcode'], 'country' => $order->customer['country']['iso_code_2'], 'email' => $order->customer['email_address']);
     // address line 2 is optional
     if ($order->customer['suburb'] != '') {
         $optionsCust['address2'] = $order->customer['suburb'];
     }
     // different format for Japanese address layout:
     if ($order->customer['country']['iso_code_2'] == 'JP') {
         $optionsCust['zip'] = substr($order->customer['postcode'], 0, 3) . '-' . substr($order->customer['postcode'], 3);
     }
     if (MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED == 2) {
         $optionsCust = array('first_name' => replace_accents($order->delivery['firstname'] != '' ? $order->delivery['firstname'] : $order->billing['firstname']), 'last_name' => replace_accents($order->delivery['lastname'] != '' ? $order->delivery['lastname'] : $order->billing['lastname']), 'address1' => replace_accents($order->delivery['street_address'] != '' ? $order->delivery['street_address'] : $order->billing['street_address']), 'city' => replace_accents($order->delivery['city'] != '' ? $order->delivery['city'] : $order->billing['city']), 'state' => $order->delivery['country']['id'] != '' ? zen_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']) : zen_get_zone_code($order->billing['country']['id'], $order->billing['zone_id'], $order->billing['state']), 'zip' => $order->delivery['postcode'] != '' ? $order->delivery['postcode'] : $order->billing['postcode'], 'country' => $order->delivery['country']['title'] != '' ? $order->delivery['country']['title'] : $order->billing['country']['title'], 'country_code' => $order->delivery['country']['iso_code_2'] != '' ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2'], 'email' => $order->customer['email_address']);
         if ($order->delivery['suburb'] != '') {
             $optionsCust['address2'] = $order->delivery['suburb'];
         }
         if ($order->delivery['country']['iso_code_2'] == 'JP') {
             $optionsCust['zip'] = substr($order->delivery['postcode'], 0, 3) . '-' . substr($order->delivery['postcode'], 3);
         }
     }
     $optionsShip['no_shipping'] = MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED;
     if (MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE == '1') {
         $optionsShip['address_override'] = MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE;
     }
     // prepare cart contents details where possible
     if (MODULE_PAYMENT_PAYPAL_DETAILED_CART == 'Yes') {
         $optionsLineItems = ipn_getLineItemDetails($my_currency);
     }
     if (sizeof($optionsLineItems) > 0) {
         $optionsLineItems['cmd'] = '_cart';
         // $optionsLineItems['num_cart_items'] = sizeof($order->products);
         if (isset($optionsLineItems['shipping'])) {
             $optionsLineItems['shipping_1'] = $optionsLineItems['shipping'];
             unset($optionsLineItems['shipping']);
         }
         unset($optionsLineItems['subtotal']);
         // if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode
         if (!isset($optionsLineItems['item_name_1']) || $optionsLineItems['creditsExist'] == TRUE) {
             $optionsLineItems = array();
         }
         // if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array();
         // debug:
         // ipn_debug_email('Line Item Details (if blank, this means there was a data mismatch or credits applied, and thus bypassed): ' . "\n" . print_r($optionsLineItems, true));
         unset($optionsLineItems['creditsExist']);
     }
     $optionsAggregate = array('cmd' => '_ext-enter', 'item_name' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_TITLE, 'item_number' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_ITEMNUM, 'amount' => number_format($this->transaction_amount, $currencies->get_decimal_places($my_currency)), 'shipping' => '0.00');
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax'] = '0.00';
     }
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax_cart'] = '0.00';
     }
     $optionsTrans = array('upload' => (int) (sizeof($order->products) > 0), 'currency_code' => $my_currency);
     // if line-item info is invalid, use aggregate:
     if (sizeof($optionsLineItems) > 0) {
         $optionsAggregate = $optionsLineItems;
     }
     if (defined('MODULE_PAYMENT_PAYPAL_LOGO_IMAGE')) {
         $optionsCore['cpp_logo_image'] = urlencode(MODULE_PAYMENT_LOGO_IMAGE);
     }
     if (defined('MODULE_PAYMENT_PAYPAL_CART_BORDER_COLOR')) {
         $optionsCore['cpp_cart_border_color'] = MODULE_PAYMENT_PAYPAL_CART_BORDER_COLOR;
     }
     // prepare submission
     $options = array_merge($optionsCore, $optionsCust, $optionsPhone, $optionsShip, $optionsTrans, $optionsAggregate);
     // ipn_debug_email('Keys for submission: ' . print_r($options, true));
     // build the button fields
     foreach ($options as $name => $value) {
         // remove quotation marks
         $value = str_replace('"', '', $value);
         // check for invalid chars
         if (preg_match('/[^a-zA-Z_0-9]/', $name)) {
             ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . $name . ' (' . $value . ')');
             break;
         }
         // do we need special handling for & and = symbols?
         // if (strpos($value, '&') !== false || strpos($value, '=') !== false) $value = urlencode($value);
         $buttonArray[] = zen_draw_hidden_field($name, $value);
     }
     $process_button_string = "\n" . implode("\n", $buttonArray) . "\n";
     $_SESSION['paypal_transaction_info'] = array($this->transaction_amount, $this->transaction_currency);
     return $process_button_string;
 }
Exemple #2
0
 /**
  * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
  * This sends the data to the payment gateway for processing.
  * (These are hidden fields on the checkout confirmation page)
  *
  * @return string
  */
 function process_button()
 {
     global $db, $order, $currencies, $currency;
     $options = array();
     $optionsCore = array();
     $optionsPhone = array();
     $optionsShip = array();
     $optionsLineItems = array();
     $optionsAggregate = array();
     $optionsTrans = array();
     $buttonArray = array();
     //$_SESSION['coupons']['price']   $ot_coupon->deduction
     $this->totalsum = $order->info['total'] - $_SESSION['coupons']['price'];
     // save the session stuff permanently in case paypal loses the session
     $_SESSION['ppipn_key_to_remove'] = session_id();
     $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'");
     $sql = "insert into " . TABLE_PAYPAL_SESSION . " (session_id, saved_session, expiry) values (\n            '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "',\n            '" . base64_encode(serialize($_SESSION)) . "',\n            '" . (time() + 1 * 60 * 60 * 24 * 2) . "')";
     $db->Execute($sql);
     $my_currency = select_pp_currency();
     $this->transaction_currency = $my_currency;
     $this->transaction_amount = $this->totalsum * $currencies->get_value($my_currency);
     $this->subtotal = $order->info['subtotal'] * $currencies->get_value($my_currency) - $_SESSION['coupons']['price'];
     $this->shipping_cost = $order->info['shipping_cost'];
     // * $currencies->get_value($my_currency)
     //$this->shipping_cost = ($this->transaction_amount - $this->subtotal);
     $telephone = preg_replace('/\\D/', '', $order->customer['telephone']);
     if ($telephone != '') {
         $optionsPhone['H_PhoneNumber'] = $telephone;
         if (in_array($order->customer['country']['iso_code_2'], array('US', 'CA'))) {
             $optionsPhone['night_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['night_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['night_phone_c'] = substr($telephone, 6, 4);
             $optionsPhone['day_phone_a'] = substr($telephone, 0, 3);
             $optionsPhone['day_phone_b'] = substr($telephone, 3, 3);
             $optionsPhone['day_phone_c'] = substr($telephone, 6, 4);
         } else {
             $optionsPhone['night_phone_b'] = $telephone;
             $optionsPhone['day_phone_b'] = $telephone;
         }
     }
     $optionsCore = array('charset' => CHARSET, 'lc' => $order->customer['country']['iso_code_2'], 'page_style' => MODULE_PAYMENT_PAYPAL_PAGE_STYLE, 'custom' => zen_session_name() . '=' . zen_session_id(), 'business' => MODULE_PAYMENT_PAYPAL_BUSINESS_ID, 'return' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=paypal', 'SSL'), 'cancel_return' => zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'shopping_url' => zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'), 'notify_url' => zen_href_link('ipn_main_handler.php', '', 'SSL', false, false, true), 'redirect_cmd' => '_xclick', 'rm' => 2, 'bn' => 'Zhongtuo_Cart_EC_C2', 'mrb' => 'R-4DM17246PS436904F', 'pal' => 'GR5QUVVL9AFGN', 'os1' => $_SESSION['paypal_product_id']);
     $optionsCust = array('first_name' => replace_accents($order->customer['firstname']), 'last_name' => replace_accents($order->customer['lastname']), 'address1' => replace_accents($order->customer['street_address']), 'city' => replace_accents($order->customer['city']), 'state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['zone_id']), 'zip' => $order->customer['postcode'], 'country' => $order->customer['country']['iso_code_2'], 'email' => $order->customer['email_address']);
     if ($order->customer['suburb'] != '') {
         $optionsCust['address2'] = $order->customer['suburb'];
     }
     if (MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED == 2) {
         $optionsCust = array('address_name' => replace_accents($order->customer['firstname'] . ' ' . $order->customer['lastname']), 'address_street' => replace_accents($order->customer['street_address']), 'address_city' => replace_accents($order->customer['city']), 'address_state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['zone_id']), 'address_zip' => $order->customer['postcode'], 'address_country' => $order->customer['country']['title'], 'address_country_code' => $order->customer['country']['iso_code_2'], 'payer_email' => $order->customer['email_address']);
     }
     $optionsShip = array('no_shipping' => 0);
     if (MODULE_PAYMENT_PAYPAL_DETAILED_CART == 'Yes') {
         $optionsLineItems = ipn_getLineItemDetails();
     }
     if (sizeof($optionsLineItems) > 0) {
         $optionsLineItems['cmd'] = '_cart';
         //      $optionsLineItems['num_cart_items'] = sizeof($order->products);
         if (isset($optionsLineItems['shipping'])) {
             $optionsLineItems['shipping_1'] = $optionsLineItems['shipping'];
             unset($optionsLineItems['shipping']);
         }
         if (isset($optionsLineItems['handling'])) {
             $optionsLineItems['handling_1'] = $optionsLineItems['handling'];
             unset($optionsLineItems['handling']);
         }
         unset($optionsLineItems['subtotal']);
         // if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode
         if (!isset($optionsLineItems['item_name_1'])) {
             $optionsLineItems = array();
         }
         //if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array();
         ipn_debug_email('Line Item Details (if blank, this means there was a data mismatch, and thus bypassed): ' . "\n" . print_r($optionsLineItems, true));
     }
     /** 提交购买的商品名称到 PAYPAL **/
     /*for ($i=0, $n=sizeof($order->products), $k=1; $i<$n; $i++, $k++) {
     		$product_names = $product_names . $order->products[$i]['name'] . " ; ";
     	}*/
     //global $orders_id;
     //$paypal_order_id = $_SESSION['paypal_order_no']; //zen_get_order_no($orders_id);
     $count_amount_total = number_format($this->subtotal, $currencies->get_decimal_places($my_currency));
     $count_shipping_total = number_format($this->wl_check_price($this->shipping_cost, $_SESSION['currency']), $currencies->get_decimal_places($my_currency));
     $count_amount_shipping = $count_amount_total + $count_shipping_total;
     if (!empty($_POST['cot_gv']) && $_POST['cot_gv'] > 0 && $_POST['cot_gv'] < $count_amount_shipping) {
         if ($_POST['cot_gv'] < $count_amount_total) {
             $paypal_amount_number = $count_amount_total - $_POST['cot_gv'];
             $paypal_shipping_number = $count_shipping_total;
         } elseif ($_POST['cot_gv'] < $count_shipping_total) {
             $paypal_amount_number = $count_amount_total;
             $paypal_shipping_number = $count_shipping_total - $_POST['cot_gv'];
         } else {
             $paypal_amount_number = 0.01;
             $paypal_shipping_number = $count_shipping_total - ($_POST['cot_gv'] - $count_amount_total) - 0.01;
         }
     } else {
         $paypal_amount_number = $count_amount_total;
         $paypal_shipping_number = $count_shipping_total;
     }
     $optionsAggregate = array('cmd' => '_ext-enter', 'item_name' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_TITLE . "#" . $_SESSION['paypal_no'], 'amount' => $paypal_amount_number, 'shipping' => $paypal_shipping_number, 'paypal_order_id' => $paypal_order_id);
     //var_dump($optionsAggregate);
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax'] = '0.00';
     }
     if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') {
         $optionsAggregate['tax_cart'] = '0.00';
     }
     $optionsTrans = array('upload' => (int) (sizeof($order->products) > 0), 'currency_code' => $my_currency);
     // if line-item info is invalid, use aggregate:
     if (sizeof($optionsLineItems) > 0) {
         $optionsAggregate = $optionsLineItems;
     }
     // prepare submission
     $options = array_merge($optionsCore, $optionsCust, $optionsPhone, $optionsShip, $optionsTrans, $optionsAggregate);
     ipn_debug_email('Keys for submission: ' . print_r($options, true));
     // build the button fields
     foreach ($options as $name => $value) {
         // remove quotation marks
         $value = str_replace('"', '', $value);
         // check for invalid chars
         if (preg_match('/[^a-zA-Z_0-9]/', $name)) {
             ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . $name . ' (' . $value . ')');
             break;
         }
         // do we need special handling for & and = symbols?
         //if (strpos($value, '&') !== false || strpos($value, '=') !== false) $value = urlencode($value);
         $buttonArray[] = zen_draw_hidden_field($name, $value);
     }
     $process_button_string = implode("\n", $buttonArray) . "\n";
     $_SESSION['paypal_transaction_info'] = array($this->transaction_amount, $this->transaction_currency);
     return $process_button_string;
 }