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

原创
2016-08-08 09:21:19 1209浏览

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 帐号交易信息看到客户购买了哪些物品。

二. 使用 Paypal Sessions Viewer 插件找回 Paypal 漏掉的订单。

原理:zencart 购物车的物品,通过 paypal 方式付款,会在 paypal_session 表中保存此次付款的所有记录,如果付款成功后,从 paypal 网站跳转到购物网站并生成了订单时,zencart系统会自动删除这条 paypal_session 记录,如果没有成功跳转到购物网站,没有成功生成订单,那这条付款记录数据就会一直保存在数据库,当使用 Paypal Session Viewer 插件,就能查看这条记录的所有数据,包括客户信息,购物时间,商品信息,如果你确定已收到款,就可以把这条 paypal_session 信息转移到订单中,生成一个订单。

插件下载地址:http://www.zen-cart.cn/english-version-modules/admin-tools/paypal-sessions-viewer

三. 修改付款流程,先生成订单后付款。

原理:用过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页面,这样造成的后果是很严重的,因为订单不能被正常的创建。基于上述的分析, 我们希望稍微地改变一下流程,即在支付之前订单已经创建好了,这样就算在支付时不能从第三方支付网站跳转回来,我们也不会存在用户付款成功却在后台没有订单的情况了。

本人是参照东国先生的这篇 修改zen-cart下单和付款流程以防止漏单 教程去修改的,因为这个教程比较老,而且也没有很全面,所以我根据自己的实际需求,把他做的更完善,更细节化。

经过修改后的蓝图基本是下面这样的:

1. 在checkour_confirmation页面确认订单后,都会直接proccess,并且进入 account_history_info 页面,可以在这里进入付款页面。如下图所示:

2. 如果当时客户没能付款,也可进入自己的后台对历史订单进行付款。如下图所示:

3. 未付款的订单,可以在后台修改价格,像淘宝一样拍下宝贝后,店主给你修改价格后再付款一样。如下图所示:

下面我们来正式修改代码,首先我列举出所有要修改的文件:

1. includes/classes/payment.php

2. includes/modules/payment/paypal.php

3. includes/classes/order.php

4. includes/modules/pages/checkout_process/header_php.php

5. includes/modules/pages/account_history_info/header_php.php

6. includes/templates/你的模板目录/templates/tpl_account_history_info_default.php

7. includes/templates/你的模板目录/templates/tpl_account_history_default.php

8. ipn_main_handler.php

9. admin(后台目录)/orders.php

因为先生成订单再付款,付款步骤就会比原来又多了一步,为了简化付款流程,我安装了 Fast And Easy Checkout For Zencart(快速支付) 插件,安装此插件之前,需要安装另外一个插件 Css Js Loader For Zencart,这是快速支付插件的依赖插件。快速支付与先生成订单后支付没什么因果关系,所以如果你不想安装的话完全可以不理。

按步骤修改上面列举的文件:

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.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 12define('MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE', 'true');
 13 14/**
 15 *  ensure dependencies are loaded
 16*/ 17include_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*/ 23class paypal extends base {
 24/**
 25   * string representing the payment method
 26   *
 27   * @var string
 28*/ 29var$code;
 30/**
 31   * $title is the displayed name for this payment method
 32   *
 33   * @var string
 34*/ 35var$title;
 36/**
 37   * $description is a soft name for this payment method
 38   *
 39   * @var string
 40*/ 41var$description;
 42/**
 43   * $enabled determines whether this module shows or not... in catalog.
 44   *
 45   * @var boolean
 46*/ 47var$enabled;
 48/**
 49    * constructor
 50    *
 51    * @param int $paypal_ipn_id
 52    * @return paypal
 53*/ 54function paypal($paypal_ipn_id = '') {
 55global$order, $messageStack;
 56$this->code = 'paypal';
 57$this->codeVersion = '1.3.9';
 58if (IS_ADMIN_FLAG === true) {
 59$this->title = MODULE_PAYMENT_PAYPAL_TEXT_ADMIN_TITLE; // Payment Module title in Admin 60if (IS_ADMIN_FLAG === true && defined('MODULE_PAYMENT_PAYPAL_IPN_DEBUG') && MODULE_PAYMENT_PAYPAL_IPN_DEBUG != 'Off') $this->title .= ' (debug mode active)';
 61if (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);
 68if ((int)MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID > 0) {
 69$this->order_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID;
 70    }
 71if (is_object($order)) $this->update_status();
 72$this->paynow_action_url = 'https://' . MODULE_PAYMENT_PAYPAL_HANDLER;
 73 74if (PROJECT_VERSION_MAJOR != '1' && substr(PROJECT_VERSION_MINOR, 0, 3) != '3.9') $this->enabled = false;
 75 76// verify table structure 77if (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*/ 83function update_status() {
 84global$order, $db;
 85 86if ( ($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");
 89while (!$check_query->EOF) {
 90if ($check_query->fields['zone_id'] < 1) {
 91$check_flag = true;
 92break;
 93         } elseif ($check_query->fields['zone_id'] == $order->billing['zone_id']) {
 94$check_flag = true;
 95break;
 96        }
 97$check_query->MoveNext();
 98      }
 99100if ($check_flag == false) {
101$this->enabled = false;
102      }
103    }
104  }
105/**
106   * JS validation which does error-checking of data-entry if this module is selected for use
107   * (Number, Owner, and CVV Lengths)
108   *
109   * @return string
110*/111function javascript_validation() {
112returnfalse;
113  }
114/**
115   * Displays payment method name along with Credit Card Information Submission Fields (if any) on the Checkout Payment Page
116   *
117   * @return array
118*/119function selection() {
120returnarray('id' => $this->code,
121                  'module' => MODULE_PAYMENT_PAYPAL_TEXT_CATALOG_LOGO,
122                  'icon' => MODULE_PAYMENT_PAYPAL_TEXT_CATALOG_LOGO
123                 );
124  }
125/**
126   * Normally evaluates the Credit Card Type for acceptance and the validity of the Credit Card Number & Expiration Date
127   * Since paypal module is not collecting info, it simply skips this step.
128   *
129   * @return boolean
130*/131function pre_confirmation_check() {
132returnfalse;
133  }
134/**
135   * Display Credit Card Information on the Checkout Confirmation Page
136   * Since none is collected for paypal before forwarding to paypal site, this is skipped
137   *
138   * @return boolean
139*/140function confirmation() {
141returnfalse;
142  }
143/**
144   * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
145   * This sends the data to the payment gateway for processing.
146   * (These are hidden fields on the checkout confirmation page)
147   *
148   * @return string
149*/150function process_button() {
151returnfalse;
152  }
153/**
154   * Determine the language to use when visiting the PayPal site
155*/156function getLanguageCode() {
157global$order;
158$lang_code = '';
159$orderISO = zen_get_countries($order->customer['country']['id'], true);
160$storeISO = zen_get_countries(STORE_COUNTRY, true);
161if (in_array(strtoupper($orderISO['countries_iso_code_2']), array('US', 'AU', 'DE', 'FR', 'IT', 'GB', 'ES', 'AT', 'BE', 'CA', 'CH', 'CN', 'NL', 'PL'))) {
162$lang_code = strtoupper($orderISO['countries_iso_code_2']);
163     } elseif (in_array(strtoupper($storeISO['countries_iso_code_2']), array('US', 'AU', 'DE', 'FR', 'IT', 'GB', 'ES', 'AT', 'BE', 'CA', 'CH', 'CN', 'NL', 'PL'))) {
164$lang_code = strtoupper($storeISO['countries_iso_code_2']);
165     } elseif (in_array(strtoupper($_SESSION['languages_code']), array('EN', 'US', 'AU', 'DE', 'FR', 'IT', 'GB', 'ES', 'AT', 'BE', 'CA', 'CH', 'CN', 'NL', 'PL'))) {
166$lang_code = $_SESSION['languages_code'];
167if (strtoupper($lang_code) == 'EN') $lang_code = 'US';
168    }
169//return $orderISO['countries_iso_code_2'];170returnstrtoupper($lang_code);
171  }
172/**
173   * Store transaction info to the order and process any results that come back from the payment gateway
174*/175function before_process() {
176returnfalse;
177  }
178/**
179    * Checks referrer
180    *
181    * @param string $zf_domain
182    * @return boolean
183*/184function check_referrer($zf_domain) {
185returntrue;
186  }
187/**
188    * Build admin-page components
189    *
190    * @param int $zf_order_id
191    * @return string
192*/193function admin_notification($zf_order_id) {
194global$db;
195$output = '';
196$sql = "select * from " . TABLE_PAYPAL . " where order_id = '" . (int)$zf_order_id . "' order by paypal_ipn_id DESC LIMIT 1";
197$ipn = $db->Execute($sql);
198if ($ipn->RecordCount() > 0 && file_exists(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypal_admin_notification.php')) require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypal_admin_notification.php');
199return$output;
200  }
201/**
202   * Post-processing activities
203   * When the order returns from the processor, if PDT was successful, this stores the results in order-status-history and logs data for subsequent reference
204   *
205   * @return boolean
206*/207function after_process() {
208returnfalse;
209  }
210/**
211   * Used to display error message details
212   *
213   * @return boolean
214*/215function output_error() {
216returnfalse;
217  }
218/**
219   * Check to see whether module is installed
220   *
221   * @return boolean
222*/223function check() {
224global$db;
225if (IS_ADMIN_FLAG === true) {
226global$sniffer;
227if ($sniffer->field_exists(TABLE_PAYPAL, 'zen_order_id'))  $db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE COLUMN zen_order_id order_id int(11) NOT NULL default '0'");
228    }
229if (!isset($this->_check)) {
230$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_STATUS'");
231$this->_check = $check_query->RecordCount();
232    }
233return$this->_check;
234  }
235/**
236   * Install the payment module and its configuration settings
237    *
238*/239function install() {
240global$db, $messageStack;
241if (defined('MODULE_PAYMENT_PAYPAL_STATUS')) {
242$messageStack->add_session('PayPal Website Payments Standard module already installed.', 'error');
243       zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypal', 'NONSSL'));
244return 'failed';
245    }
246if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) {
247$messageStack->add_session('NOTE: PayPal Express Checkout module already installed. You don\'t need Standard if you have Express installed.', 'error');
248       zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypalwpp', 'NONSSL'));
249return 'failed';
250    }
251$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 Module', 'MODULE_PAYMENT_PAYPAL_STATUS', 'True', 'Do you want to accept PayPal payments?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
252$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Business ID', 'MODULE_PAYMENT_PAYPAL_BUSINESS_ID','".STORE_OWNER_EMAIL_ADDRESS."', 'Primary email address for your PayPal account.
NOTE: This must match EXACTLY the primary email address on your PayPal account settings. It IS case-sensitive, so please check your PayPal profile preferences at paypal.com and be sure to enter the EXACT same primary email address here.', '6', '2', now())"); 253$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Currency', 'MODULE_PAYMENT_PAYPAL_CURRENCY', 'Selected Currency', 'Which currency should the order be sent to PayPal as?
NOTE: if an unsupported currency is sent to PayPal, it will be auto-converted to USD.', '6', '3', 'zen_cfg_select_option(array(\'Selected Currency\', \'Only USD\', \'Only AUD\', \'Only CAD\', \'Only EUR\', \'Only GBP\', \'Only CHF\', \'Only CZK\', \'Only DKK\', \'Only HKD\', \'Only HUF\', \'Only JPY\', \'Only NOK\', \'Only NZD\', \'Only PLN\', \'Only SEK\', \'Only SGD\', \'Only THB\', \'Only MXN\', \'Only ILS\', \'Only PHP\', \'Only TWD\', \'Only BRL\', \'Only MYR\'), ', now())"); 254$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_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '4', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())"); 255$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 Pending Notification Status', 'MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID', '" . DEFAULT_ORDERS_STATUS_ID . "', 'Set the status of orders made with this payment module that are not yet completed to this value
(\'Pending\' recommended)', '6', '5', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())"); 256$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_ORDER_STATUS_ID', '2', 'Set the status of orders made with this payment module that have completed payment to this value
(\'Processing\' recommended)', '6', '6', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())"); 257$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 Refund Order Status', 'MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID', '1', 'Set the status of orders that have been refunded made with this payment module to this value
(\'Pending\' recommended)', '6', '7', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())"); 258$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_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '8', now())"); 259$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Address Override', 'MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE', '1', 'If set to 1, the customer shipping address selected in Zen Cart will override the customer PayPal-stored address book. The customer will see their address from Zen Cart, but will NOT be able to edit it at PayPal.
(An invalid address will be treated by PayPal as not-supplied, or override=0)
0=No Override
1=ZC address overrides PayPal address choices', '6', '18', 'zen_cfg_select_option(array(\'0\',\'1\'), ', now())"); 260$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipping Address Requirements?', 'MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED', '2', 'The buyers shipping address. If set to 0 your customer will be prompted to include a shipping address. If set to 1 your customer will not be asked for a shipping address. If set to 2 your customer will be required to provide a shipping address.
0=Prompt
1=Not Asked
2=Required

NOTE: If you allow your customers to enter their own shipping address, then MAKE SURE you PERSONALLY manually verify the PayPal confirmation details to verify the proper address when filling orders. When using Website Payments Standard (IPN), Zen Cart does not know if they choose an alternate shipping address at PayPal vs the one entered when placing an order.', '6', '20', 'zen_cfg_select_option(array(\'0\',\'1\',\'2\'), ', now())"); 261$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Detailed Line Items in Cart', 'MODULE_PAYMENT_PAYPAL_DETAILED_CART', 'No', 'Do you want to give line-item details to PayPal? If set to True, line-item details will be shared with PayPal if no discounts apply and if tax and shipping are simple. Otherwise an Aggregate cart summary will be sent.', '6', '22', 'zen_cfg_select_option(array(\'No\',\'Yes\'), ', now())"); 262$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Page Style', 'MODULE_PAYMENT_PAYPAL_PAGE_STYLE', 'Primary', 'Sets the Custom Payment Page Style for payment pages. The value of page_style is the same as the Page Style Name you chose when adding or editing the page style. You can add and edit Custom Payment Page Styles from the Profile subtab of the My Account tab on the PayPal site. If you would like to always reference your Primary style, set this to \"primary.\" If you would like to reference the default PayPal page style, set this to \"paypal\".', '6', '25', now())"); 263$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 services

Default:
www.paypal.com/cgi-bin/webscr
or
www.paypal.com/us/cgi-bin/webscr
or for the UK,
www.paypal.com/uk/cgi-bin/webscr', 'MODULE_PAYMENT_PAYPAL_HANDLER', 'www.paypal.com/cgi-bin/webscr', 'Choose the URL for PayPal live processing', '6', '73', '', now())"); 264// sandbox: www.sandbox.paypal.com/cgi-bin/webscr265$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function) values ('PDT Token (Payment Data Transfer)', 'MODULE_PAYMENT_PAYPAL_PDTTOKEN', '', 'Enter your PDT Token value here in order to activate transactions immediately after processing (if they pass validation).', '6', '25', now(), 'zen_cfg_password_display')"); 266// Paypal testing options here267$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Debug Mode', 'MODULE_PAYMENT_PAYPAL_IPN_DEBUG', 'Off', 'Enable debug logging?
NOTE: This can REALLY clutter your email inbox!
Logging goes to the /includes/modules/payment/paypal/logs folder
Email goes to the store-owner address.
Email option NOT recommended.
Leave OFF for normal operation.', '6', '71', 'zen_cfg_select_option(array(\'Off\',\'Log File\',\'Log and Email\'), ', now())"); 268$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Debug Email Address', 'MODULE_PAYMENT_PAYPAL_DEBUG_EMAIL_ADDRESS','".STORE_OWNER_EMAIL_ADDRESS."', 'The email address to use for PayPal debugging', '6', '72', now())"); 269270$this->notify('NOTIFY_PAYMENT_PAYPAL_INSTALLED'); 271 } 272/** 273 * Remove the module and all its settings 274 * 275*/276function remove() { 277global$db; 278$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE 'MODULE\_PAYMENT\_PAYPAL\_%'"); 279$this->notify('NOTIFY_PAYMENT_PAYPAL_UNINSTALLED'); 280 } 281/** 282 * Internal list of configuration keys used for configuration of the module 283 * 284 * @return array 285*/286function keys() { 287$keys_list = array( 288 'MODULE_PAYMENT_PAYPAL_STATUS', 289 'MODULE_PAYMENT_PAYPAL_BUSINESS_ID', 290 'MODULE_PAYMENT_PAYPAL_PDTTOKEN', 291 'MODULE_PAYMENT_PAYPAL_CURRENCY', 292 'MODULE_PAYMENT_PAYPAL_ZONE', 293 'MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID', 294 'MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID', 295 'MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID', 296 'MODULE_PAYMENT_PAYPAL_SORT_ORDER', 297 'MODULE_PAYMENT_PAYPAL_DETAILED_CART', 298 'MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE' , 299 'MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED' , 300 'MODULE_PAYMENT_PAYPAL_PAGE_STYLE' , 301 'MODULE_PAYMENT_PAYPAL_HANDLER', 302 'MODULE_PAYMENT_PAYPAL_IPN_DEBUG', 303 ); 304305// Paypal testing/debug options go here:306if (IS_ADMIN_FLAG === true) { 307if (isset($_GET['debug']) && $_GET['debug']=='on') { 308$keys_list[]='MODULE_PAYMENT_PAYPAL_DEBUG_EMAIL_ADDRESS'; /* this defaults to store-owner-email-address */309 } 310 } 311return$keys_list; 312 } 313314function _getPDTresults($orderAmount, $my_currency, $pdtTX) { 315global$db; 316$ipnData = ipn_postback('PDT', $pdtTX); 317$respdata = $ipnData['info']; 318319// parse the data320$lines = explode("\n", $respdata); 321$this->pdtData = array(); 322for ($i=1; $i<count($lines);$i++){ 323if (!strstr($lines[$i], "=")) continue; 324list($key,$val) = explode("=", $lines[$i]); 325$this->pdtData[urldecode($key)] = urldecode($val); 326 } 327328if ($this->pdtData['txn_id'] == '' || $this->pdtData['payment_status'] == '') { 329 ipn_debug_email('PDT Returned INVALID Data. Must wait for IPN to process instead. ' . "\n" . print_r($this->pdtData, true)); 330returnFALSE; 331 } else { 332 ipn_debug_email('PDT Returned Data ' . print_r($this->pdtData, true)); 333 } 334335$_POST['mc_gross'] = $this->pdtData['mc_gross']; 336$_POST['mc_currency'] = $this->pdtData['mc_currency']; 337$_POST['business'] = $this->pdtData['business']; 338$_POST['receiver_email'] = $this->pdtData['receiver_email']; 339340$PDTstatus = (ipn_validate_transaction($respdata, $this->pdtData, 'PDT') && valid_payment($orderAmount, $my_currency, 'PDT') && $this->pdtData['payment_status'] == 'Completed'); 341if ($this->pdtData['payment_status'] != '' && $this->pdtData['payment_status'] != 'Completed') { 342 ipn_debug_email('PDT WARNING :: Order not marked as "Completed". Check for Pending reasons or wait for IPN to complete.' . "\n" . '[payment_status] => ' . $this->pdtData['payment_status'] . "\n" . '[pending_reason] => ' . $this->pdtData['pending_reason']); 343 } 344345$sql = "SELECT order_id, paypal_ipn_id, payment_status, txn_type, pending_reason 346 FROM " . TABLE_PAYPAL . " 347 WHERE txn_id = :transactionID OR parent_txn_id = :transactionID 348 ORDER BY order_id DESC "; 349$sql = $db->bindVars($sql, ':transactionID', $this->pdtData['txn_id'], 'string'); 350$ipn_id = $db->Execute($sql); 351if ($ipn_id->RecordCount() != 0) { 352 ipn_debug_email('PDT WARNING :: Transaction already exists. Perhaps IPN already added it. PDT processing ended.'); 353$pdtTXN_is_unique = false; 354 } else { 355$pdtTXN_is_unique = true; 356 } 357358$PDTstatus = ($pdtTXN_is_unique && $PDTstatus); 359360return$PDTstatus; 361 } 362363364function tableCheckup() { 365global$db, $sniffer; 366$fieldOkay1 = (method_exists($sniffer, 'field_type')) ? $sniffer->field_type(TABLE_PAYPAL, 'txn_id', 'varchar(20)', true) : -1; 367$fieldOkay2 = ($sniffer->field_exists(TABLE_PAYPAL, 'module_name')) ? true : -1; 368$fieldOkay3 = ($sniffer->field_exists(TABLE_PAYPAL, 'order_id')) ? true : -1; 369370if ($fieldOkay1 == -1) { 371$sql = "show fields from " . TABLE_PAYPAL; 372$result = $db->Execute($sql); 373while (!$result->EOF) { 374if ($result->fields['Field'] == 'txn_id') { 375if ($result->fields['Type'] == 'varchar(20)') { 376$fieldOkay1 = true; // exists and matches required type, so skip to other checkup377 } else { 378$fieldOkay1 = $result->fields['Type']; // doesn't match, so return what it "is"379break; 380 } 381 } 382$result->MoveNext(); 383 } 384 } 385386if ($fieldOkay1 !== true) { 387// temporary fix to table structure for v1.3.7.x -- may remove in later release388$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE payment_type payment_type varchar(40) NOT NULL default ''"); 389$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE txn_type txn_type varchar(40) NOT NULL default ''"); 390$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE payment_status payment_status varchar(32) NOT NULL default ''"); 391$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE reason_code reason_code varchar(40) default NULL"); 392$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE pending_reason pending_reason varchar(32) default NULL"); 393$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE invoice invoice varchar(128) default NULL"); 394$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE payer_business_name payer_business_name varchar(128) default NULL"); 395$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE address_name address_name varchar(64) default NULL"); 396$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE address_street address_street varchar(254) default NULL"); 397$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE address_city address_city varchar(120) default NULL"); 398$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE address_state address_state varchar(120) default NULL"); 399$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE payer_email payer_email varchar(128) NOT NULL default ''"); 400$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE business business varchar(128) NOT NULL default ''"); 401$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE receiver_email receiver_email varchar(128) NOT NULL default ''"); 402$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE txn_id txn_id varchar(20) NOT NULL default ''"); 403$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE parent_txn_id parent_txn_id varchar(20) default NULL"); 404 } 405if ($fieldOkay2 !== true) { 406$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " ADD COLUMN module_name varchar(40) NOT NULL default '' after txn_type"); 407$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " ADD COLUMN module_mode varchar(40) NOT NULL default '' after module_name"); 408 } 409if ($fieldOkay3 !== true) { 410$db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE zen_order_id order_id int(11) NOT NULL default '0'"); 411 } 412 } 413414function paynow_button($order_id) { 415global$db, $order, $currencies, $currency; 416require_once(DIR_WS_CLASSES . 'order.php'); 417$order = new order($order_id); 418$options = array(); 419$optionsCore = array(); 420$optionsPhone = array(); 421$optionsShip = array(); 422$optionsLineItems = array(); 423$optionsAggregate = array(); 424$optionsTrans = array(); 425$buttonArray = array(); 426427$this->totalsum = $order->info['total']; 428429// save the session stuff permanently in case paypal loses the session430$_SESSION['ppipn_key_to_remove'] = session_id(); 431$db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'"); 432433$sql = "insert into " . TABLE_PAYPAL_SESSION . " (session_id, saved_session, expiry) values ( 434 '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "', 435 '" . base64_encode(serialize($_SESSION)) . "', 436 '" . (time() + (1*60*60*24*2)) . "')"; 437438$db->Execute($sql); 439440$my_currency = select_pp_currency(); 441if(!empty($order->info['currency'])){ 442$my_currency=$order->info['currency']; 443 } 444$this->transaction_currency = $my_currency; 445446$this->transaction_amount = ($this->totalsum * $currencies->get_value($my_currency)); 447448$telephone = preg_replace('/\D/', '', $order->customer['telephone']); 449if ($telephone != '') { 450$optionsPhone['H_PhoneNumber'] = $telephone; 451if (in_array($order->customer['country']['iso_code_2'], array('US','CA'))) { 452$optionsPhone['night_phone_a'] = substr($telephone,0,3); 453$optionsPhone['night_phone_b'] = substr($telephone,3,3); 454$optionsPhone['night_phone_c'] = substr($telephone,6,4); 455$optionsPhone['day_phone_a'] = substr($telephone,0,3); 456$optionsPhone['day_phone_b'] = substr($telephone,3,3); 457$optionsPhone['day_phone_c'] = substr($telephone,6,4); 458 } else { 459$optionsPhone['night_phone_b'] = $telephone; 460$optionsPhone['day_phone_b'] = $telephone; 461 } 462 } 463464$optionsCore = array( 465 'lc' => US, 466//'lc' => $order->customer['country']['iso_code_2'],467 'charset' => CHARSET, 468 'page_style' => MODULE_PAYMENT_PAYPAL_PAGE_STYLE, 469 'custom' => zen_session_name() . '=' . zen_session_id(), 470 'invoice' => $order->info['num'], 471 'business' => MODULE_PAYMENT_PAYPAL_BUSINESS_ID, 472 'return' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=paypal', 'SSL'), 473 'cancel_return' => zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'), 474 'shopping_url' => zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'), 475 'notify_url' => zen_href_link('ipn_main_handler.php', '', 'SSL',false,false,true), 476 'redirect_cmd' => '_xclick','rm' => 2,'bn' => 'zencart','mrb' => 'R-6C7952342H795591R','pal' => '9E82WJBKKGPLQ', 477 ); 478$optionsCust = array( 479 'first_name' => replace_accents($order->customer['firstname']), 480 'last_name' => replace_accents($order->customer['lastname']), 481 'address1' => replace_accents($order->customer['street_address']), 482 'city' => replace_accents($order->customer['city']), 483 'state' => zen_get_zone_code($order->customer['country']['id'], $order->customer['zone_id'], $order->customer['state']), 484 'zip' => $order->customer['postcode'], 485 'country' => $order->customer['country']['iso_code_2'], 486 'email' => $order->customer['email_address'], 487 ); 488// address line 2 is optional489if ($order->customer['suburb'] != '') $optionsCust['address2'] = $order->customer['suburb']; 490// different format for Japanese address layout:491if ($order->customer['country']['iso_code_2'] == 'JP') $optionsCust['zip'] = substr($order->customer['postcode'], 0, 3) . '-' . substr($order->customer['postcode'], 3); 492if (MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED == 2) { 493$optionsCust = array( 494 'first_name' => replace_accents($order->delivery['firstname'] != '' ? $order->delivery['firstname'] : $order->billing['firstname']), 495 'last_name' => replace_accents($order->delivery['lastname'] != '' ? $order->delivery['lastname'] : $order->billing['lastname']), 496 'address1' => replace_accents($order->delivery['street_address'] != '' ? $order->delivery['street_address'] : $order->billing['street_address']), 497 'city' => replace_accents($order->delivery['city'] != '' ? $order->delivery['city'] : $order->billing['city']), 498 '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'])), 499 'zip' => ($order->delivery['postcode'] != '' ? $order->delivery['postcode'] : $order->billing['postcode']), 500 'country' => ($order->delivery['country']['title'] != '' ? $order->delivery['country']['title'] : $order->billing['country']['title']), 501 'country_code' => ($order->delivery['country']['iso_code_2'] != '' ? $order->delivery['country']['iso_code_2'] : $order->billing['country']['iso_code_2']), 502 'email' => $order->customer['email_address'], 503 ); 504if ($order->delivery['suburb'] != '') $optionsCust['address2'] = $order->delivery['suburb']; 505if ($order->delivery['country']['iso_code_2'] == 'JP') $optionsCust['zip'] = substr($order->delivery['postcode'], 0, 3) . '-' . substr($order->delivery['postcode'], 3); 506 } 507$optionsShip['no_shipping'] = MODULE_PAYMENT_PAYPAL_ADDRESS_REQUIRED; 508if (MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE == '1') $optionsShip['address_override'] = MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE; 509// prepare cart contents details where possible510if (MODULE_PAYMENT_PAYPAL_DETAILED_CART == 'Yes') $optionsLineItems = ipn_getLineItemDetails(); 511if (sizeof($optionsLineItems) > 0) { 512$optionsLineItems['cmd'] = '_cart'; 513// $optionsLineItems['num_cart_items'] = sizeof($order->products);514if (isset($optionsLineItems['shipping'])) { 515$optionsLineItems['shipping_1'] = $optionsLineItems['shipping']; 516unset($optionsLineItems['shipping']); 517 } 518unset($optionsLineItems['subtotal']); 519// if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode520if (!isset($optionsLineItems['item_name_1']) || $optionsLineItems['creditsExist'] == TRUE) $optionsLineItems = array(); 521//if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array(); 522 // debug: 523 //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));524unset($optionsLineItems['creditsExist']); 525 } 526$optionsAggregate = array( 527 'cmd' => '_ext-enter', 528 'item_name' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_TITLE, 529 'item_number' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_ITEMNUM, 530//'num_cart_items' => sizeof($order->products),531 'amount' => number_format($this->transaction_amount, $currencies->get_decimal_places($my_currency)), 532 'shipping' => '0.00', 533 ); 534if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') $optionsAggregate['tax'] = '0.00'; 535if (MODULE_PAYMENT_PAYPAL_TAX_OVERRIDE == 'true') $optionsAggregate['tax_cart'] = '0.00'; 536$optionsTrans = array( 537 'upload' => (int)(sizeof($order->products) > 0), 538 'currency_code' => $my_currency, 539//'paypal_order_id' => $paypal_order_id, 540 //'no_note' => '1', 541 //'invoice' => '',542 ); 543544// if line-item info is invalid, use aggregate:545if (sizeof($optionsLineItems) > 0) $optionsAggregate = $optionsLineItems; 546547// prepare submission548$options = array_merge($optionsCore, $optionsCust, $optionsPhone, $optionsShip, $optionsTrans, $optionsAggregate); 549//ipn_debug_email('Keys for submission: ' . print_r($options, true)); 550551 // build the button fields552foreach ($optionsas$name => $value) { 553// remove quotation marks554$value = str_replace('"', '', $value); 555// check for invalid chars556if (preg_match('/[^a-zA-Z_0-9]/', $name)) { 557 ipn_debug_email('datacheck - ABORTING - preg_match found invalid submission key: ' . $name . ' (' . $value . ')'); 558break; 559 } 560// do we need special handling for & and = symbols? 561 //if (strpos($value, '&') !== false || strpos($value, '=') !== false) $value = urlencode($value);562563$bu
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。