我正在为woocommerce建立一个自定义的支付网关。这是一个基于表单的网关,可以在银行的站点中完成付款。因此,用户将被重定向到银行站点以进行支付,例如Paypal。我已经创建了回调挂钩,但是我有一些问题。 首先,每当用户输入他的卡详细信息并付款时,他就会再次在银行站点而不是在“谢谢”页面中被重定向。银行返回成功的付款。 我相信问题隐藏在process_payment和receive_page功能中。因此,这引出了第二个问题。
第二个问题是:在我的构造函数中,我有这个钩子
add_action('woocommerce_thankyou_' . $this->id, array($this, 'receipt_page'));
然后我将其更改为:
add_action('woocommerce_receipt_bank_payment' , array($this, 'receipt_page'));
功能回执页面是这样的:
function receipt_page($order){
echo __('Thank you - your order is now pending payment. You should be automatically redirected to bank Paycenter to make payment.', 'woo-payment-gateway');
echo $this->generate_bank_form($order);
}
第一个钩子正常工作,但是第二个钩子没有正常工作。 谁能告诉我这两个钩子之间的区别是什么?
`add_action('woocommerce_thankyou_' . $this->id, array($this, 'receipt_page'));`
` add_action('woocommerce_receipt_bank_payment' , array($this, 'receipt_page'));`
最后有人知道如何解决重定向问题吗?
这是我的构造函数:
`public function __construct(){
$this->id = 'bank_payment';
$this->has_fields = false;
$this->method_title = "bank Payment Gateway";
$this->method_description = "Accept payments with Eurobank";
$this->init_form_fields();
global $wpdb;
if ($wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "bank_transactionst'") === $wpdb->prefix . 'bank_transactions') {
// The database table exist
} else {
// Table does not exist
$query = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'bank_transactions (id int(11) unsigned NOT NULL AUTO_INCREMENT, merch_ref varchar(50) not null, trans_ticket varchar(32) not null , timestamp datetime default null, PRIMARY KEY (id))';
$wpdb->query($query);
}
$this->init_settings();
$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
$this->eb_PayMerchantId = $this->get_option('eb_PayMerchantId');
$this->eb_PayMerchantKey = $this->get_option('eb_PayMerchantKey');
$this->pb_installments = $this->get_option('pb_installments');
$this->test_mode = $this->get_option('test_mode');
$this->redirect_page_id = $this->get_option('redirect_page_id');
$this->eb_installments_variation = $this->get_option('eb_installments_variation');
//$this->eb_render_logo = $this->get_option('eb_render_logo');
// ACTIONS
add_action('woocommerce_receipt_bank_payment' , array($this, 'receipt_page'),10,1);
//add_action( 'woocommerce_api_wc_bank_payment', array( $this, 'check_bank_response' ) );
add_action( 'woocommerce_api_wc_bank_payment', array( $this, 'check_bank_response' ) );
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
}`
我的process_payment函数是这样的:
function process_payment( $order_id ) {
global $woocommerce;
$order = new WC_Order( $order_id );
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
}
检查付款是否成功并将订单设置为“处理中”后,我现在有了以下代码,以便重定向到“谢谢”页面:
if ($this->redirect_page_id == "-1") {
$redirect_url = $this->get_return_url($order);
} else {
$redirect_url = ($this->redirect_page_id == "" || $this->redirect_page_id == 0) ? $this->get_return_url($order) : get_permalink($this->redirect_page_id);
}
wp_redirect($redirect_url);
exit;