PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/IT技术/Alipay支付宝接口/Alipaymate(第三方)/old/zencart1.5.x支付宝外卡/1.5.1/includes/modules/pages/checkout_confirmation/header_php.php

https://gitlab.com/shinvdu/doc
PHP | 211 lines | 133 code | 42 blank | 36 comment | 52 complexity | 8e6e115479bfa90662830f169b7a3bae MD5 | raw file
  1. <?php
  2. /**
  3. * checkout_confirmation header_php.php
  4. *
  5. * @package page
  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: header_php.php 16435 2010-05-28 09:34:32Z drbyte $
  10. */
  11. // This should be first line of the script:
  12. $zco_notifier->notify('NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION');
  13. // if there is nothing in the customers cart, redirect them to the shopping cart page
  14. if ($_SESSION['cart']->count_contents() <= 0) {
  15. zen_redirect(zen_href_link(FILENAME_TIME_OUT));
  16. }
  17. // if the customer is not logged on, redirect them to the login page
  18. if (!$_SESSION['customer_id']) {
  19. $_SESSION['navigation']->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_PAYMENT));
  20. zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
  21. } else {
  22. // validate customer
  23. if (zen_get_customer_validate_session($_SESSION['customer_id']) == false) {
  24. $_SESSION['navigation']->set_snapshot();
  25. zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
  26. }
  27. }
  28. // avoid hack attempts during the checkout procedure by checking the internal cartID
  29. if (isset($_SESSION['cart']->cartID) && $_SESSION['cartID']) {
  30. if ($_SESSION['cart']->cartID != $_SESSION['cartID']) {
  31. zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  32. }
  33. }
  34. // if no shipping method has been selected, redirect the customer to the shipping method selection page
  35. if (!$_SESSION['shipping']) {
  36. zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  37. }
  38. if (isset($_SESSION['shipping']['id']) && $_SESSION['shipping']['id'] == 'free_free' && defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER') && $_SESSION['cart']->show_total() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
  39. zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  40. }
  41. if (isset($_POST['payment'])) $_SESSION['payment'] = $_POST['payment'];
  42. $_SESSION['comments'] = zen_db_prepare_input($_POST['comments']);
  43. //'checkout_payment_discounts'
  44. //zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  45. if (DISPLAY_CONDITIONS_ON_CHECKOUT == 'true') {
  46. if (!isset($_POST['conditions']) || ($_POST['conditions'] != '1')) {
  47. $messageStack->add_session('checkout_payment', ERROR_CONDITIONS_NOT_ACCEPTED, 'error');
  48. }
  49. }
  50. //echo $messageStack->size('checkout_payment');
  51. require(DIR_WS_CLASSES . 'order.php');
  52. $order = new order;
  53. // load the selected shipping module
  54. require(DIR_WS_CLASSES . 'shipping.php');
  55. $shipping_modules = new shipping($_SESSION['shipping']);
  56. require(DIR_WS_CLASSES . 'order_total.php');
  57. $order_total_modules = new order_total;
  58. $order_total_modules->collect_posts();
  59. $order_total_modules->pre_confirmation_check();
  60. // load the selected payment module
  61. require(DIR_WS_CLASSES . 'payment.php');
  62. if (!isset($credit_covers)) $credit_covers = FALSE;
  63. //echo 'credit covers'.$credit_covers;
  64. if ($credit_covers) {
  65. unset($_SESSION['payment']);
  66. $_SESSION['payment'] = '';
  67. }
  68. //@debug echo ($credit_covers == true) ? 'TRUE' : 'FALSE';
  69. $payment_modules = new payment($_SESSION['payment']);
  70. $payment_modules->update_status();
  71. if ( ($_SESSION['payment'] == '' || !is_object($$_SESSION['payment']) ) && $credit_covers === FALSE) {
  72. $messageStack->add_session('checkout_payment', ERROR_NO_PAYMENT_MODULE_SELECTED, 'error');
  73. }
  74. if (is_array($payment_modules->modules)) {
  75. $payment_modules->pre_confirmation_check();
  76. }
  77. if ($messageStack->size('checkout_payment') > 0) {
  78. zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
  79. }
  80. //echo $messageStack->size('checkout_payment');
  81. //die('here');
  82. // Stock Check
  83. $flagAnyOutOfStock = false;
  84. $stock_check = array();
  85. if (STOCK_CHECK == 'true') {
  86. for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
  87. if ($stock_check[$i] = zen_check_stock($order->products[$i]['id'], $order->products[$i]['qty'])) {
  88. $flagAnyOutOfStock = true;
  89. }
  90. }
  91. // Out of Stock
  92. if ( (STOCK_ALLOW_CHECKOUT != 'true') && ($flagAnyOutOfStock == true) ) {
  93. zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
  94. }
  95. }
  96. // update customers_referral with $_SESSION['gv_id']
  97. if ($_SESSION['cc_id']) {
  98. $discount_coupon_query = "SELECT coupon_code
  99. FROM " . TABLE_COUPONS . "
  100. WHERE coupon_id = :couponID";
  101. $discount_coupon_query = $db->bindVars($discount_coupon_query, ':couponID', $_SESSION['cc_id'], 'integer');
  102. $discount_coupon = $db->Execute($discount_coupon_query);
  103. $customers_referral_query = "SELECT customers_referral
  104. FROM " . TABLE_CUSTOMERS . "
  105. WHERE customers_id = :customersID";
  106. $customers_referral_query = $db->bindVars($customers_referral_query, ':customersID', $_SESSION['customer_id'], 'integer');
  107. $customers_referral = $db->Execute($customers_referral_query);
  108. // only use discount coupon if set by coupon
  109. if ($customers_referral->fields['customers_referral'] == '' and CUSTOMERS_REFERRAL_STATUS == 1) {
  110. $sql = "UPDATE " . TABLE_CUSTOMERS . "
  111. SET customers_referral = :customersReferral
  112. WHERE customers_id = :customersID";
  113. $sql = $db->bindVars($sql, ':customersID', $_SESSION['customer_id'], 'integer');
  114. $sql = $db->bindVars($sql, ':customersReferral', $discount_coupon->fields['coupon_code'], 'string');
  115. $db->Execute($sql);
  116. } else {
  117. // do not update referral was added before
  118. }
  119. }
  120. if (isset($$_SESSION['payment']->form_action_url)) {
  121. $form_action_url = $$_SESSION['payment']->form_action_url;
  122. } else {
  123. $form_action_url = zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');
  124. }
  125. // if shipping-edit button should be overridden, do so
  126. $editShippingButtonLink = zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL');
  127. if (method_exists($$_SESSION['payment'], 'alterShippingEditButton')) {
  128. $theLink = $$_SESSION['payment']->alterShippingEditButton();
  129. if ($theLink) $editShippingButtonLink = $theLink;
  130. }
  131. // deal with billing address edit button
  132. $flagDisablePaymentAddressChange = false;
  133. if (isset($$_SESSION['payment']->flagDisablePaymentAddressChange)) {
  134. $flagDisablePaymentAddressChange = $$_SESSION['payment']->flagDisablePaymentAddressChange;
  135. }
  136. require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
  137. $breadcrumb->add(NAVBAR_TITLE_1, zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  138. $breadcrumb->add(NAVBAR_TITLE_2);
  139. // This should be last line of the script:
  140. $zco_notifier->notify('NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION');
  141. // added by alipaymate@qq.com
  142. if ($_SESSION['payment'] == 'alipay_forcard') {
  143. // delete if order existed
  144. if (isset($_SESSION['alipay_forcard_pending_order_id'])) {
  145. $_order_id = $_SESSION['alipay_forcard_pending_order_id'];
  146. $_order_query = 'select orders_id from ' . TABLE_ORDERS . " where orders_status = " . DEFAULT_ORDERS_STATUS_ID . " and payment_module_code = 'alipay_forcard' and orders_id = " . (int)$_order_id;
  147. $_orders = $db->Execute($_order_query);
  148. if ($_orders->RecordCount() > 0) {
  149. $db->Execute('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = ' . $_order_id);
  150. $db->Execute('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = ' . $_order_id);
  151. $db->Execute('delete from ' . TABLE_ORDERS . ' where orders_status = 1 and orders_id = ' . $_order_id);
  152. }
  153. unset($_SESSION['alipay_forcard_pending_order_id']);
  154. }
  155. $cart_type = '';
  156. if (isset($_SESSION['alipay_card_type'])) {
  157. $cart_type = $_SESSION['alipay_card_type'];
  158. }
  159. $order->info['payment_method'] = MODULE_PAYMENT_ALIPAYFOR_TEXT_TITLE . ': ' . $cart_type;
  160. $order->info['payment_module_code'] = 'alipay_forcard';
  161. // create the order record
  162. $order_totals = $order_total_modules->process();
  163. $insert_id = $order->create($order_totals, 2);
  164. $payment_modules->after_order_create($insert_id);
  165. // store the product info to the order
  166. $order->create_add_products($insert_id);
  167. $_SESSION['alipay_forcard_pending_order_id'] = $insert_id;
  168. }
  169. ?>