欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

Zencart先生成订单后付款,类似淘宝后台修改订单价格,zencart生成订单

程序员文章站 2024-02-07 22:31:40
...

Zencart先生成订单后付款,类似淘宝后台修改订单价格,zencart生成订单

Zencart 使用 Paypal 付款,会出现漏单的情况,即 paypal 已经收到客户的付款,但是网站后台没有客户的订单。导致 paypal 漏单的原因大致会是当客户跳转到Paypal 网站付款完毕之后,直接关闭了窗口,或者网络不稳定,没有正常跳转到网站。

解决 Paypal 漏单问题的方案有好几种:

一. 开启 Detailed Line Items in Cart 选项。

原理:在 zencart 后台 Module --> Payment --> PayPal Website Payments Standard - IPN 开启 Detailed Line Items in Cart 选项。这个选项会把你所有的订单物品信息传给 paypal,当客户付款成功而后台未能成功生成订单时,也可以通过 paypal 帐号交易信息看到客户购买了哪些物品。

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.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按钮做准备的。paypal.php修改后的文件如下:

1 php 2 /** 3 * paypal.php payment module class for PayPal Website Payments Standard (IPN) method 4 * 5 * @package paymentMethod 6 * @copyright Copyright 2003-2010 Zen Cart Development Team 7 * @copyright Portions Copyright 2003 osCommerce 8 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 9 * @version $Id: paypal.php 15735 2010-03-29 07:13:53Z drbyte $ 10 */ 11 12 define('MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE', 'true'); 13 14 /** 15 * ensure dependencies are loaded 16 */ 17 include_once((IS_ADMIN_FLAG === true ? DIR_FS_CATALOG_MODULES : DIR_WS_MODULES) . 'payment/paypal/paypal_functions.php'); 18 19 /** 20 * paypal.php payment module class for PayPal Website Payments Standard (IPN) method 21 * 22 */ 23 class paypal extends base { 24 /** 25 * string representing the payment method 26 * 27 * @var string 28 */ 29 var $code; 30 /** 31 * $title is the displayed name for this payment method 32 * 33 * @var string 34 */ 35 var $title; 36 /** 37 * $description is a soft name for this payment method 38 * 39 * @var string 40 */ 41 var $description; 42 /** 43 * $enabled determines whether this module shows or not... in catalog. 44 * 45 * @var boolean 46 */ 47 var $enabled; 48 /** 49 * constructor 50 * 51 * @param int $paypal_ipn_id 52 * @return paypal 53 */ 54 function paypal($paypal_ipn_id = '') { 55 global $order, $messageStack; 56 $this->code = 'paypal'; 57 $this->codeVersion = '1.3.9'; 58 if (IS_ADMIN_FLAG === true) { 59 $this->title = MODULE_PAYMENT_PAYPAL_TEXT_ADMIN_TITLE; // Payment Module title in Admin 60 if (IS_ADMIN_FLAG === true && defined('MODULE_PAYMENT_PAYPAL_IPN_DEBUG') && MODULE_PAYMENT_PAYPAL_IPN_DEBUG != 'Off') $this->title .= ' (debug mode active)'; 61 if (IS_ADMIN_FLAG === true && MODULE_PAYMENT_PAYPAL_TESTING == 'Test') $this->title .= ' (dev/test mode active)'; 62 } else { 63 $this->title = MODULE_PAYMENT_PAYPAL_TEXT_CATALOG_TITLE; // Payment Module title in Catalog 64 } 65 $this->description = MODULE_PAYMENT_PAYPAL_TEXT_DESCRIPTION; 66 $this->sort_order = MODULE_PAYMENT_PAYPAL_SORT_ORDER; 67 $this->enabled = ((MODULE_PAYMENT_PAYPAL_STATUS == 'True') ? true : false); 68 if ((int)MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID > 0) { 69 $this->order_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID; 70 } 71 if (is_object($order)) $this->update_status(); 72 $this->paynow_action_url = 'https://' . MODULE_PAYMENT_PAYPAL_HANDLER; 73 74 if (PROJECT_VERSION_MAJOR != '1' && substr(PROJECT_VERSION_MINOR, 0, 3) != '3.9') $this->enabled = false; 75 76 // verify table structure 77 if (IS_ADMIN_FLAG === true) $this->tableCheckup(); 78 } 79 /** 80 * calculate zone matches and flag settings to determine whether this module should display to customers or not 81 * 82 */ 83 function update_status() { 84 global $order, $db; 85 86 if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_ZONE > 0) ) { 87 $check_flag = false; 88 $check_query = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYPAL_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id"); 89 while (!$check_query->EOF) { 90 if ($check_query->fields['zone_id'] ) {
相关标签: 淘宝卖家