We are developing our own woocommerce payment gateway plugin (for Alipay). After user presses "Proceed to Alipay" on the checkout page, the Alipay API takes the order information (amount, name, address, order number, etc.), creates a form with them, and them automatically submit it to the Alipay gateway. This is how it looks like:
'<form id=\'alipaysubmit\' name=\'alipaysubmit\' action=\'https://openapi.alipaydev.com/gateway.do?charset=UTF-8\' method=\'POST\'><input type=\'hidden\' name=\'biz_content\' value=\'{"product_code":"FAST_INSTANT_TRADE_PAY","body":"","subject":"Wendy Wang","total_amount":"21.50","out_trade_no":"1724"}\'/><input type=\'hidden\' name=\'app_id\' value=\'2016090900467784\'/><input type=\'hidden\' name=\'version\' value=\'1.0\'/><input type=\'hidden\' name=\'format\' value=\'json\'/><input type=\'hidden\' name=\'sign_type\' value=\'RSA\'/><input type=\'hidden\' name=\'method\' value=\'alipay.trade.page.pay\'/><input type=\'hidden\' name=\'timestamp\' value=\'2017-11-13 04:50:57\'/><input type=\'hidden\' name=\'alipay_sdk\' value=\'alipay-sdk-php-20161101\'/><input type=\'hidden\' name=\'notify_url\' value=\'https://sv.icubeinfo.com/wp-content/plugins/onepigeon-alipay/notify_url.php\'/><input type=\'hidden\' name=\'return_url\' value=\'https://sv.icubeinfo.com/wp-content/plugins/onepigeon-alipay/return_url.php\'/><input type=\'hidden\' name=\'charset\' value=\'UTF-8\'/><input type=\'hidden\' name=\'sign\' value=\'ahegEWInBM8h9Gav6oNOirp881D7j8/x1gjpgSdXfgzHA81vOrDQQOdJqO2rMMj9bmm7/etVQI6MSFY1kPN9KDbPhvPeAIeygHTcDksz0k2PyNhm1P35zgctT20fWptskhZwz1vAjGVTcWOqsG7V4O9pkvnYsKm4cY83yEbFZN3G5hQHj4ZCKD/ixJFDLTtu65DonIwGV9o6qI26YCjMzUSOHVIfVFx/531R1SlGcaqhpzUzaFkMGFFLcI/F349bExDEVuXM1earg9EKZyCq/m8ZihiutPiMQkbGJnYks/casUAyA3l3m1iuWg2DqvA5tT/6psWOiIPiZSEViioMMA==\'/><input type=\'submit\' value=\'ok\' style=\'display:none;\'\'></form><script>document.forms[\'alipaysubmit\'].submit();</script>'
So this is what returns from Alipay API and it was stored as a string $result
.
To run it we simply do echo $result;
This was all good when we test-ran it on our own laptop (XAMPP hosted): the page redirected to Alipay's page and users could choose to either pay with QR code or login to pay (I assumed the redirection took place because of the echo
); and later when user got the payment done, it would redirect back to woocommerce's payment completion page.
However, when we tried to deploy the same codes to our server (IIS hosted), it just didn't work.
We tried using logs to trace code execution behaviors; all the codes before and after the echo
command got logged, that means the echo
should have been executed, but we don't understand why it didn't take effect. No redirection happened, so the woocommerce process_checkout()
function would continue running until it hit send_ajax_failure_response()
function, and then resulted in the error message "Error processing checkout. Please try again."
Anyone has an idea on what the problem is here?
BTW, echo
failed even in the simple case of echo '1234';
command.
Also, when we tried to echo
a simple string at the loading of checkout page, it worked good. The string will be printed on the page; but not after pressing the "Proceed to Alipay" button.
"Proceed to Alipay" seems to be implemented with AJAX; is this the reason that echo
failed? If it is, why it worked at my laptop but not on our server? How can I make it work?
Thanks.