修改zen-cart下单和付款流程以防止漏单文档.doc_第1页
修改zen-cart下单和付款流程以防止漏单文档.doc_第2页
修改zen-cart下单和付款流程以防止漏单文档.doc_第3页
修改zen-cart下单和付款流程以防止漏单文档.doc_第4页
修改zen-cart下单和付款流程以防止漏单文档.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

zen-cart进入第三方支付网站后,如果不能正常返回,则会造成客户已付款但后台却无订单数据的尴尬局面。本文就针对该问题给出一种解决方案,希望对 被同样问题困扰的同行有所帮助。 用过zen-cart的人都知道,zen-cart中下单步骤是下面这样的(其中中的表示不是必须的): 1. 购物车(shopping cart) 2. 货运方式(delivery method) 3. 支付方式(payment method) 4. 订单确认(confirmation) 5. 第三方网站支付 6. 订单处理(checkout process)这一步比较重要,因为会在这里将购物车中的信息写入订单 7. 下单成功(checkout success) 这样的流程在正常情况下是没有任何问题的。但是,从第5步到第6部的过程中,用户可能以为付款成功就直接关闭掉网页了,或者由于网络原因造成不能正 常跳转到checkout_process页面,这样造成的后果是很严重的,因为订单不能被正常的创建。 基于上述的分析, 我们希望稍微地改变一下流程,即在支付之前订单已经创建好了,这样就算在支付时不能从第三方支付网站跳转回来,我们也不会存在用户付款成功却在后台没有订 单的情况了。经过修改后的蓝图基本是下面这样的: 1. 在checkour_confirmation页面确认订单后,都会直接proccess,并且进入checkour_success页面,可以在这里进 入付款页面。如下图所示:2. 如果当时客户没能付款,也可进入自己的后台对历史订单进行付款。如下图所示:下面我们就来看看如何一步一步来实现上述的功能。 1. 首先我们需要对现有的支付模块进行一个改造。需要对支付方式的class增加一个字段paynow_action_url,用来表示进行支付的页面 url,另外还需要增加一个函数,paynow_button($order_id),来获取支付表单的参数隐藏域代码。 要增加paynow_action_url字段,请在类payment的构造函数中最后加上下面的代码: if ( (zen_not_null($module) & (in_array($module.php, $this-modules) & (isset($GLOBALS$module-paynow_action_url) ) $this-paynow_action_url = $GLOBALS$module-paynow_action_url; 要增加 paynow_button($order_id)函数,请在payment类的最后一个函数之后加上如下的代码: function paynow_button($order_id) if (is_array($this-modules) if (is_object($GLOBALS$this-selected_module) return $GLOBALS$this-selected_module-paynow_button($order_id); 2. 以paypal支付方式为例子,说明如何具体实现。为了不破坏paypal原有的代码,我们将paypal.php文件拷贝一个副本出来,并命名为 paypalsimple.php,并对里面的代码做适当的修改。代码如下所示,可以看到,这里去掉了对form_action_url的指定,并给定了 paynow_action_url,因为我们希望用户点击“确认订单”后直接进入checkout_process,所以如果不指定 form_action_url,那么确认订单的表单就会直接提交到checkout_process页面了,而paynow_action_url就是 以前的form_action_url的值。paynow_button函数的实现也很简单,这里只是将原先的process_button()函数的内 容剪切过来而已,只不过我们没有使用全局的$order变量,而是使用$order = new order($order_id),来重新构造的一个对象,这样做是为在历史订单中显示pay now按钮做准备的。 paypalsimple.php code = paypalsimple; $this-title = MODULE_PAYMENT_PAYPAL_SIMPLE_TEXT_TITLE; if(IS_ADMIN_FLAG = true) $this-title = MODULE_PAYMENT_PAYPAL_SIMPLE_TEXT_ADMIN_TITLE; $this-description = MODULE_PAYMENT_PAYPAL_SIMPLE_TEXT_DESCRIPTION; $this-sort_order = MODULE_PAYMENT_PAYPAL_SIMPLE_SORT_ORDER; $this-enabled = (MODULE_PAYMENT_PAYPAL_SIMPLE_STATUS = True) ? true : false); if (int)MODULE_PAYMENT_PAYPAL_SIMPLE_ORDER_STATUS_ID 0) $this-order_status = MODULE_PAYMENT_PAYPAL_SIMPLE_ORDER_STATUS_ID; $this-paynow_action_url = https:/ . MODULE_PAYMENT_PAYPAL_SIMPLE_HANDLER; if (is_object($order) $this-update_status(); / class methods function update_status() global $order, $db; if ( ($this-enabled = true) & (int)MODULE_PAYMENT_PAYPAL_SIMPLE_ZONE 0) ) $check_flag = false; $check = $db-Execute(select zone_id from . TABLE_ZONES_TO_GEO_ZONES . where geo_zone_id = . MODULE_PAYMENT_PAYPAL_SIMPLE_ZONE . and zone_country_id = . $order-billingcountryid . order by zone_id); while (!$check-EOF) if ($check-fieldszone_id fieldszone_id = $order-billingzone_id) $check_flag = true; break; $check-MoveNext(); if ($check_flag = false) $this-enabled = false; function javascript_validation() return false; function selection() $text = MODULE_PAYMENT_SIMPLE_PAYPAL_TEXT_CATALOG_LOGO.  .MODULE_PAYMENT_PAYPAL_SIMPLE_TEXT_TITLE .      . MODULE_PAYMENT_PAYPAL_SIMPLE_ACCEPTANCE_MARK_TEXT . ; return array(id = $this-code, module = $text ); function pre_confirmation_check() return false; function confirmation() return false; function process_button() return false; function before_process() return false; function after_process() return false; function get_error() return false; function check() global $db; if (!isset($this-_check) $check_query = $db-Execute(select configuration_value from . TABLE_CONFIGURATION . where configuration_key = MODULE_PAYMENT_PAYPAL_SIMPLE_STATUS); $this-_check = $check_query-RecordCount(); return $this-_check; function install() global $db; $db-Execute(insert into . TABLE_CONFIGURATION . (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values (Enable PayPal-Simple Module, MODULE_PAYMENT_PAYPAL_SIMPLE_STATUS, True, Do you want to accept PayPal-Simple payments?, 6, 0, zen_cfg_select_option(array(True, False), , now(); $db-Execute(insert into . TABLE_CONFIGURATION . (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values (Sort order of display., MODULE_PAYMENT_PAYPAL_SIMPLE_SORT_ORDER, 0, Sort order of display. Lowest is displayed first., 6, 8, now(); $db-Execute(insert into . TABLE_CONFIGURATION . (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values (Payment Zone, MODULE_PAYMENT_PAYPAL_SIMPLE_ZONE, 0, If a zone is selected, only enable this payment method for that zone., 6, 2, zen_get_zone_class_title, zen_cfg_pull_down_zone_classes(, now(); $db-Execute(insert into . TABLE_CONFIGURATION . (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values (Set Order Status, MODULE_PAYMENT_PAYPAL_SIMPLE_ORDER_STATUS_ID, 0, Set the status of orders made with this payment module to this value, 6, 0, zen_cfg_pull_down_order_statuses(, zen_get_order_status_name, now(); $db-Execute(insert into . TABLE_CONFIGURATION . (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values (Mode for PayPal web servicesDefault:/cgi-bin//us/cgi-bin/webscror for the UK,/uk/cgi-bin/webscr, MODULE_PAYMENT_PAYPAL_SIMPLE_HANDLER, /cgi-bin/webscr, Choose the URL for PayPal live processing, 6, 73, , now(); function remove() global $db; $db-Execute(delete from . TABLE_CONFIGURATION . where configuration_key in ( . implode(, , $this-keys() . ); function keys() return array(MODULE_PAYMENT_PAYPAL_SIMPLE_STATUS,MODULE_PAYMENT_PAYPAL_SIMPLE_SORT_ORDER,MODULE_PAYMENT_PAYPAL_SIMPLE_ZONE,MODULE_PAYMENT_PAYPAL_SIMPLE_ORDER_STATUS_ID, MODULE_PAYMENT_PAYPAL_SIMPLE_HANDLER); function paynow_button($order_id) global $db, $order, $currencies, $currency; require_once(DIR_WS_CLASSES . order.php); $order = new order($order_id); $options = array(); $optionsCore = array(); $optionsPhone = array(); $optionsShip = array(); $optionsLineItems = array(); $optionsAggregate = array(); $optionsTrans = array(); $buttonArray = array(); $this-totalsum = $order-infototal; / save the session stuff permanently in case paypal loses the session $_SESSIONppipn_key_to_remove = session_id(); $db-Execute(delete from . TABLE_PAYPAL_SESSION . where session_id = . zen_db_input($_SESSIONppipn_key_to_remove) . ); $sql = insert into . TABLE_PAYPAL_SESSION . (session_id, saved_session, expiry) values ( . zen_db_input($_SESSIONppipn_key_to_remove) . , . base64_encode(serialize($_SESSION) . , . (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); $telephone = preg_replace(/D/, , $order-customertelephone); if ($telephone != ) $optionsPhoneH_PhoneNumber = $telephone; if (in_array($order-customercountryiso_code_2, array(US,CA) $optionsPhonenight_phone_a = substr($telephone,0,3); $optionsPhonenight_phone_b = substr($telephone,3,3); $optionsPhonenight_phone_c = substr($telephone,6,4); $optionsPhoneday_phone_a = substr($telephone,0,3); $optionsPhoneday_phone_b = substr($telephone,3,3); $optionsPhoneday_phone_c = substr($telephone,6,4); else $optionsPhonenight_phone_b = $telephone; $optionsPhoneday_phone_b = $telephone; $optionsCore = array( charset = CHARSET, lc = $order-customercountryiso_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_PAY_SUCCESS, referer=paypal, SSL), cancel_return = zen_href_link(FILENAME_PAY_FAILED, , 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 = zencart, mrb = R-6C7952342H795591R, pal = 9E82WJBKKGPLQ, ); $optionsCust = array( first_name = replace_accents($order-customerfirstname), last_name = replace_accents($order-customerlastname), address1 = replace_accents($order-customerstreet_address), city = replace_accents($order-customercity), state = zen_get_zone_code($order-customercountryid, $order-customerzone_id, $order-customerzone_id), zip = $order-customerpostcode, country = $order-customercountryiso_code_2, email = $order-customeremail_address, ); if ($order-customersuburb != ) $optionsCustaddress2 = $order-customersuburb; if (MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED = 2) $optionsCust = array( address_name = replace_accents($order-customerfirstname . . $order-customerlastname), address_street = replace_accents($order-customerstreet_address), address_city = replace_accents($order-customercity), address_state = zen_get_zone_code($order-customercountryid, $order-customerzone_id, $order-customerzone_id), address_zip = $order-customerpostcode, address_country = $order-customercountrytitle, address_country_code = $order-customercountryiso_code_2, payer_email = $order-customeremail_address, ); $optionsShip = array( /address_override = MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE, no_shipping = MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED, ); if (MODULE_PAYMENT_PAYPAL_DETAILED_CART = Yes) $optionsLineItems = ipn_getLineItemDetails(); if (sizeof($optionsLineItems) 0) $optionsLineItemscmd = _cart; / $optionsLineItemsnum_cart_items = sizeof($order-products); if (isset($optionsLineItemsshipping) $optionsLineItemsshipping_1 = $optionsLineItemsshipping; unset($optionsLineItemsshipping); if (isset($optionsLineItemshandling) $optionsLineItemshandling_1 = $optionsLineItemshandling; unset($optionsLineItemshandling); unset($optionsLineItemssubtotal); / if line-item details couldnt be kept due to calculation mismatches or discounts etc, default to aggregate mode if (!isset($optionsLineItemsitem_name_1) $optionsLineItems = array(); /if ($optionsLineItemsamount != $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); $products_name_display = ; /* for ($i=0, $n=sizeof($order-products); $i 0) $products_name_display.= , ; $products_name_display.= $order-products$iname. (. $order-products$iqty .,.$order-products$idhisys_web_order_number.); */ $optionsAggregate = array( cmd = _ext-enter, item_name = $products_name_display, item_number = $order_id, num_cart_items = sizeof($order-products), amount = number_format($this-transaction_amount, $currencies-get_decimal_places($my_currency), shipping = 0.00, ); if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE = true) $optionsAggregatetax = 0.00; if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE = true) $optionsAggregatetax_cart = 0.00; $optionsTrans = array( upload = (int)(sizeof($order-products) 0), currency_code = $my_currency, / paypal_order_id = $paypal_order_id, /no_note = 1, /invoice = , ); / 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); if(sizeof($order-products) 0) $optionscmd = _cart; for ($i=0, $n=sizeof($order-products); $iproducts$iname; $optionsitem_number_. (string)($i+1) = $order-products$idhisys_web_order_number; $optionsamount_. (string)($i+1) = number_format(float)$order-products$ifinal_price,2); $optionsquantity_. (string)($i+1) = $order-products$iqty; / 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); $_SESSIONpaypal_transaction_info = array($this-transaction_amount, $this-transaction_currency); $process_button_string = implode(n, $buttonArray) . n; return $process_button_string; ? 3. 在checkout_success页面中显示pay now按钮。打开文件includes/modules/pages/checkout_success/header.php,在文件的末尾添加下 面

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论