我在网上使用WooCommerce,目前添加了一个网关插件。我只想问一下这个插件中的成功URL,取消URL和IPN URL是什么。在我们的例子中,我们以www.domain.com
为例。
这是代码:
add_action('plugins_loaded', 'woocommerce_FdBank_init', 0);
function woocommerce_FdBank_init() {
class WC_FdBank extends WC_Payment_Gateway {
/*
* consrtuct
*/
public function __construct()
{
$url = includes_url();
$this->id = 'FdBank';
// some code
$this->notify_url = trailingslashit(home_url());
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action('woocommerce_thankyou_FdBank', array(&$this, 'thankyou_page'));
add_action('woocommerce_receipt_FdBank', array(&$this, 'receipt_page'));
add_action('init', array(&$this, 'check_FdBank_response'));
add_action( 'woocommerce_api_' . strtolower( get_class( $this ) ), array( $this, 'check_FdBank_response' ) );
}//function construct
/*
* Fields for admin
*/
public function init_form_fields()
{
// some code here
}//function init_form_fields
/*
* All resonses
* are opereted here
* +curl from pay server
*/
public function check_FdBank_response()
{
global $woocommerce;
##gettin notify Data from pay server
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$aData = $_POST;
if (!empty($aData)) {
$order_id = $aData['tran_id'];
$order_id = preg_replace("/$this->user_code/", '', $order_id, 1);
$order = new WC_Order( $order_id );
if($aData['Tran_Status'] == 'S' && $order->status == 'pending'){
$order->update_status('processing');
return;
}
}
}
## fail Action
$order_id = $aData['tran_id'];
$order_id = preg_replace("/$this->user_code/", '', $order_id, 1);
$order = new WC_Order( $order_id );
if($_POST['Tran_Status'] == 'F' || $_POST['Tran_Status'] == 'P'){
if($order->status !=='completed'){
if($order->status == 'processing'){
} else {
$order -> update_status('failed');
$order -> add_order_note('Failed');
$order -> add_order_note("Payment failed in bank");
$redirect = $order->get_cancel_order_url();
return;
}
} else {
wp_redirect($this->notify_url);
}
}//function check_FdBank_response
##Success Action
if($_POST['Tran_Status'] == 'S'){
if($order->status !=='completed'){
if($order->status == 'processing'){
$order->payment_complete();
$order->update_status('completed');
$order->add_order_note('FdBank payment successful<br/>Bank Ref Number: '.$transid);
$order->add_order_note("Thank you for shopping with us. Your account has been charged and your transaction is successful. We will be shipping your order to you soon.");
$woocommerce->cart->empty_cart();
$abc = $this->get_return_url( $order );
wp_redirect($this->get_return_url( $order ));
return;
}
} else {
$order -> update_status('failed');
$order -> add_order_note('Failed');
$order -> add_order_note("Payment failed in bank");
$redirect = $order->get_cancel_order_url();
wp_redirect($redirect);
return;
}
}
}
/*
* Gererating from fields
*/
public function payment_fields()
{
if ($this->description){
echo wpautop(wptexturize($this->description));
}
}//function payment_fields
/*
* thank you page
*/
public function thankyou_page()
{
if ($this->description){
echo wpautop(wptexturize($this->description));
}
?><h2><?php _e('Our Details', 'woocommerce') ?></h2>
<ul class="order_details ppay_details"><?php
$fields = array(
'ppay_number'=> __('FdBank ', 'woocommerce')
);
foreach ($fields as $key=>$value) :
if(!empty($this->$key)) :
echo '<li class="'.$key.'">'.$value.': <strong>'.wptexturize($this->$key).'</strong></li>';
endif;
endforeach;
?></ul><?php
}//function thankyou_page
/*
* simple reciept
*/
public function receipt_page($order)
{
echo '<p>'.__('Thank you for your order, please click the button below to pay with FdBank .', 'woocommerce').'</p>';
echo $this->generate_FdBank_form( $order );
}//function receipt_page
/*
* generate_FdBank_form
* form
*/
public function generate_FdBank_form( $order_id )
{
global $woocommerce;
$order = new WC_Order( $order_id );
$redirect_url = $order->get_checkout_order_received_url();
$redirect_url = add_query_arg( 'wc-api', get_class( $this ), $redirect_url );
$redirect_url = $redirect_url . '&res=1';
$params = array(
// some code
);
$lr_args_array = array();
foreach($params as $key => $value){
$lr_args_array[] = "<input type='hidden' name='$key' value='$value'/>";
}
return '<form id="FdBank" action="https://sandbox.domain.com/trans.aspx" method="POST" name="process" >' . implode('', $lr_args_array) . '
<input type="submit" class="button-alt button" id="submit_FdBank_payment_form" value="'.__('Pay FdBank ', 'woocommerce').'" /> <a class="button cancel" href="'.esc_url( $order->get_cancel_order_url() ).'">'.__('Cancel order & restore cart', 'woocommerce').'</a>
</form>';
}//function generate_FdBank_form
/*
* proccess
*/
public function process_payment( $order_id ) {
global $woocommerce;
$order = new WC_Order( $order_id );
return array(
'result' => 'success',
'redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(woocommerce_get_page_id('pay'))))
);
}//function process_payment
}
function woocommerce_add_FdBank_gateway($methods) {
$methods[] = 'WC_FdBank';
return $methods;
}
add_filter('woocommerce_payment_gateways', 'woocommerce_add_FdBank_gateway' );
}
如果check_FdBank_response
是响应处理程序,那么URL是什么?在交易之后,网关将用户重定向到哪个页面,因为我们没有发送带有参数的任何返回URL或取消URL?
答案 0 :(得分:3)
在您的银行帐户中设置此网址
domain.com/wc-api/WC_FederalBank
将domain.com
替换为您的域名
现在,在确认/取消交易后,您的支付网关将重定向回此网址,它会自动调用您的check_FdBank_response()
功能。
check_FdBank_response()
现在通过使用带有网关响应的参数来验证事务。
如果交易将确认它将重定向到感谢页面。其他明智的重定向取消网址
这是此代码的全部工作