如何使用插件中的Ajax在woocommerce中处理付款?

时间:2019-01-30 09:39:31

标签: php wordpress woocommerce

我正在构建自定义付款网关,它将在iframe中加载信用卡表格,并且信用卡详细信息将由他们的服务器从我的网站处理,我提交了billinginfo详细信息后,我将获得“已批准”状态,并且交易编号。响应将在javascript事件中处理。一旦收到他们服务器的回复,请指导我处理付款。

一旦我从他们的服务器得到响应,我就会尝试使用ajaxurl通过插件中定义的函数传递那些响应。我收到400错误的要求。请检查我的代码

自定义网关插件

 <?
  class WC_Custom_Gateway extends WC_Payment_Gateway {
    public function __construct() {
//Defined all the required fields
  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') );
    } 
public function init_form_fields(){ 
  //Defined necessary fields
 }
public function payment_fields() {
 echo '<input id="token" name="token" type="hidden" value="sadfasdf'" />'; 
  //Iframe load cc form ?>
<script src="customgatway_script.js"></script>
<script>
var success = function(response){
//This is the where the response i am getting
 jQuery.ajax({
                 type : "POST",                                          

                url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',                  
                //data: response,
                data: {action:'get_process_payment'},
                dataType : "json",
                 cache: false,
                 success: function(response) { 
 }
};
 var decline = function(response){
 };
 var error = function(response){
 }
jQuery("form.woocommerce-checkout").on('submit', function () {
 submitbillinginfo(checkouttoken,billingfirst_name,etc)
}
</script>
<?php
   }
 function get_process_payment(){
   Process Payment
  }
   //or call the native function of woocommerce      process_payment($order_id)



 }

0 个答案:

没有答案