我正在构建自定义付款网关插件,我需要覆盖下订单按钮以执行javascript事件并调用ajax并处理付款。我试图在提交时使用jquery提交结帐,但多次请求ajax。如果我尝试拆分js表单未加载。从付款服务器获取交易ID后,请指导我处理付款。
/*Plugin file*/
class WC_Custom_Gateway extends WC_Payment_Gateway {
public function __construct() {
add_action('wp_ajax_get_process_payment', array( $this,'get_process_payment'));
add_action('wp_ajax_nopriv_get_process_payment',array( $this,'get_process_payment') );
// further check of SSL if you want
//add_action( 'admin_notices', array( $this, 'do_ssl_check' ) );
// This action hook saves the settings
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ));
// We need custom JavaScript to obtain a token
add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
add_action( 'wp_ajax_my_action', 'my_action' );
}
public function payment_fields() {
echo '<input id="token" name="token" type="hidden" value="adsfasdfasdfasdfasdfasdfasfasfasfasdf" />';
echo '<div id="iframe_checkout_form"></div>
<script>
var success = function(response){
response.transaciotn_id,success,etc
jQuery.ajax({
type : "POST",
url: '<?php echo plugins_url().'/custompaymentgateway/includes/custom_request.php'; ?>',
data: response,
dataType : "json",
cache: false,
success: function(response) {
alert("Your vote could not be added");
alert(response);
}
});
}
sending checkouttoken and get the iframeloaded
//once loaded clikcing the place order button
jQuery("form.woocommerce-checkout") .on("submit", function(event) { //submitevent given by payment gateway server(sending all the information billingaddress,everything) once completed will get the transaction id in success
}
</script>
}
}