Home  >  Article  >  Backend Development  >  Modify the zen-cart order and payment process to prevent missed orders_PHP tutorial

Modify the zen-cart order and payment process to prevent missed orders_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:54:541088browse

After zen-cart enters the third-party payment website, if it cannot return normally, it will cause an embarrassing situation where the customer has paid but there is no order data in the background. This article provides a solution to this problem, hoping to be helpful to colleagues who are troubled by the same problem.

Everyone who has used zen-cart knows that the ordering steps in zen-cart are as follows (the expressions in [] are not necessary):

1. Shopping cart

2. [delivery method]

3. Payment method

4. Order confirmation (confirmation)

5. [Third Party Website Payment]

6. Order processing (checkout process) - This step is more important because the information in the shopping cart will be written into the order here

7. Order successful (checkout success)

There is no problem with this process under normal circumstances. However, in the process from step 5 to step 6, the user may think that the payment is successful and close the web page directly, or the user may not be able to jump to the checkout_process page normally due to network reasons. The consequences of this are very serious, because the order Cannot be created normally.

Based on the above analysis, we hope to change the process slightly, that is, the order has been created before payment, so that even if the payment cannot be redirected from the third-party payment website, we will not have the user fail to pay successfully. There are no orders in the background. The modified blueprint basically looks like this:

1. After confirming the order on the checkour_confirmation page, you will proccess directly and enter the checkour_success page, where you can enter the payment page. As shown below:

2. If the customer fails to pay at that time, they can also enter their own backend to pay for historical orders. As shown below:

Let’s take a look at how to implement the above functions step by step.

1. First we need to transform the existing payment module. It is necessary to add a field paynow_action_url to the payment method class to represent the page URL for payment. In addition, a function, paynow_button($order_id), needs to be added to obtain the parameter hidden field code of the payment form.

To add the paynow_action_url field, please add the following code at the end of the constructor of class 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;
}
To add the paynow_button($order_id) function, please add the following after the last function of the payment class Code:

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. Take the paypal payment method as an example to explain how to implement it. In order not to destroy the original code of paypal, we will make a copy of the paypal.php file, name it paypalsimple.php, and make appropriate modifications to the code inside. The code is as shown below. You can see that the specification of form_action_url is removed here and paynow_action_url is given. Because we hope that the user will directly enter the checkout_process after clicking "Confirm Order", so if form_action_url is not specified, then the form to confirm the order will be It is submitted directly to the checkout_process page, and paynow_action_url is the value of the previous form_action_url. The implementation of the paynow_button function is also very simple. Here we just cut the content of the original process_button() function, but we do not use the global $order variable, but use $order = new order($order_id) to re- An object constructed in preparation for displaying the pay now button in historical orders.

  • Total 3 pages:
  • Previous page
  • 1
  • 2
  • 3
  • Next page

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364529.htmlTechArticleAfter zen-cart enters the third-party payment website, if it cannot return normally, it will cause the customer to have paid but the backend The embarrassing situation of no order data. This article gives a solution to this problem...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn