如何解决付款完成后,在 PayU WordPress 插件上,订单状态仍然显示待付款
我正在尝试将 payU 支付网关添加到我的 WooCommerce 网站,但官方插件不起作用,所以我尝试自己制作,但在付款完成订单后,其状态仍显示为“待付款”。
但是,我正在通过我的 PayU 帐户收到付款。
add_action('plugins_loaded','woocommerce_payupaisa_init',0);
define('payupaisa_imgdir',WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/images/');
function woocommerce_payupaisa_init(){
if(!class_exists('WC_Payment_Gateway')) return;
if( isset($_GET['msg']) && !empty($_GET['msg']) ){
add_action('the_content','payupaisa_showMessage');
}
function payupaisa_showMessage($content){
return '<div class="'.htmlentities($_GET['type']).'">'.htmlentities(urldecode($_GET['msg'])).'</div>'.$content;
}
/**
* Gateway class
*/
class WC_payupaisa extends WC_Payment_Gateway{
public function __construct(){
$this->id = 'payupaisa';
$this->method_title = 'PayU Paisa';
$this->method_description = "Redefining Payments,Simplifying Lives";
$this->has_fields = false;
$this->init_form_fields();
$this->init_settings();
if ( $this->settings['showlogo'] == "yes" ) {
$this->icon = payupaisa_imgdir . 'logo.png';
}
$this->title = $this->settings['title'];
$this->redirect_page_id = $this->settings['redirect_page_id'];
$this -> enable_currency_conversion = $this -> settings['enable_currency_conversion'];
if ( $this->settings['testmode'] == "yes" ) {
$this->liveurl = 'https://test.payu.in/_payment';
$this->merchant_id = "gtKFFx";
$this->salt = "eCwWELxi";
$this->description = $this->settings['description'].
"<br/><br/><u>Test Mode is <strong>ACTIVE</strong>,use following Credit Card details:-</u><br/>".
"Test Card Name: <strong><em style='#999999;'>any name</em></strong><br/>".
"Test Card Number: <strong>5123456789012346</strong><br/>".
"Test Card CVV: <strong>123</strong><br/>".
"Test Card Expiry: <strong>01/2020</strong><br/>";
} else {
$this->liveurl = 'https://secure.payu.in/_payment';
$this->merchant_id = $this->settings['merchant_id'];
$this->salt = $this->settings['salt'];
$this->description = $this->settings['description'];
}
$this->msg['message'] = "";
$this->msg['class'] = "";
add_action('init',array(&$this,'check_payupaisa_response'));
//update for woocommerce >2.0
add_action( 'woocommerce_api_' . strtolower( get_class( $this ) ),array( $this,'check_payupaisa_response' ) );
if ( version_compare( WOOCOMMERCE_VERSION,'2.0.0','>=' ) ) {
/* 2.0.0 */
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id,array( &$this,'process_admin_options' ) );
} else {
/* 1.6.6 */
add_action( 'woocommerce_update_options_payment_gateways','process_admin_options' ) );
}
add_action('woocommerce_receipt_payupaisa','receipt_page'));
}
function init_form_fields(){
$this->form_fields = array(
'enabled' => array(
'title' => __('Enable/disable','nilesh'),'type' => 'checkBox','label' => __('Enable PayU Paisa Payment Module.','default' => 'no','description' => 'Show in the Payment List as a payment option'
),'title' => array(
'title' => __('Title:','type' => 'text','default' => __('Online Payment','description' => __('This controls the title which the user sees during checkout.','desc_tip' => true
),'description' => array(
'title' => __('Description:','type' => 'textarea','default' => __('Pay securely by Credit or Debit Card or Internet Banking through PayU Secure Servers.','description' => __('This controls the description which the user sees during checkout.','merchant_id' => array(
'title' => __('Merchant KEY','description' => __('Given to Merchant by PayU Money'),'salt' => array(
'title' => __('Merchant SALT','description' => __('Given to Merchant by PayU Money','showlogo' => array(
'title' => __('Show logo','label' => __('Show the "PayU Paisa" logo in the Payment Method section for the user','default' => 'yes','description' => __('Tick to show "PayU Paisa" logo'),'enable_currency_conversion' => array(
'title' => __('Currency Conversion to INR?','type' => 'checkBox','label' => __('Enable Currency Conversion to INR.','default' => 'no','description'=> __('converted to equivalent amount in INR for faster payment processing'),'testmode' => array(
'title' => __('TEST Mode','label' => __('Enable PayU Paisa TEST Transactions.','description' => __('Tick to run TEST Transaction on the PayU Paisa platform'),'redirect_page_id' => array(
'title' => __('Return Page'),'type' => 'select','options' => $this->payupaisa_get_pages('Select Page'),'description' => __('URL of success page','desc_tip' => true
)
);
}
/**
* Admin Panel Options
* - Options for bits like 'title' and availability on a country-by-country basis
**/
public function admin_options(){
echo '<h3>'.__('PayU Paisa','nilesh').'</h3>';
echo '<p>'.__('Redefining Payments,Simplifying Lives! Empowering any business to collect money online within minutes').'</p>';
echo '<table class="form-table">';
// Generate the HTML For the settings form.
$this->generate_settings_html();
echo '</table>';
}
/**
* There are no payment fields for techpro,but we want to show the description if set.
**/
function payment_fields(){
if($this->description) echo wpautop(wptexturize($this->description));
}
/**
* Receipt Page
**/
function receipt_page($order){
echo '<p>'.__('Thank you for your order,please click the button below to pay with PayU.','nilesh').'</p>';
echo $this->generate_payupaisa_form($order);
}
/*currency convertor API*/
function currency_convert($currency_from,$currency_to,$currency_input)
{
if ($currency_from != $currency_to)
{
$yql_base_url = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select * from yahoo.finance.xchange where pair in ("'.$currency_from.$currency_to.'")';
$yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
$yql_query_url .= "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
$yql_session = curl_init($yql_query_url);
curl_setopt($yql_session,CURLOPT_RETURNTRANSFER,true);
$yqlexec = curl_exec($yql_session);
$yql_json = json_decode($yqlexec,true);
$currency_output = (float) $currency_input*$yql_json['query']['results']['rate']['Rate'];
return $currency_output;
}
else
{
return $currency_input;
}
}
/**
* Generate payu button link
**/
function generate_payupaisa_form($order_id){
global $woocommerce;
$order = new WC_Order( $order_id );
$myTxnId = substr(str_shuffle(md5('abcdefghijklmnop9876543210')),8);
if ( $this->redirect_page_id == "" || $this->redirect_page_id == 0 ) {
$redirect_url = $order->get_checkout_order_received_url();
} else {
$redirect_url = get_permalink($this->redirect_page_id);
}
//For wooCoomerce 2.0
if ( version_compare( WOOCOMMERCE_VERSION,'>=' ) ) {
$redirect_url = add_query_arg( 'wc-api',get_class( $this ),$redirect_url );
}
$productinfo = "Order $order_id";
/*check if currency converstion is enable*/
$the_order_total = $order->order_total;
if($this->enable_currency_conversion=='yes')
{
$the_order_total = $this->currency_convert($the_currency,'INR',$the_order_total);
$the_display_msg = "<small> $the_currency has been converted to equivalent amount in INR for faster payment processing.</small><br />";
}
/*-------------------------*/
$str = $this->merchant_id."|".$myTxnId."|".$the_order_total."|".$productinfo."|".$order->billing_first_name."|".$order->billing_email."|||||||||||".$this->salt;
$hash = hash('sha512',$str);
$payupaisa_args = array(
'key' => $this->merchant_id,'hash' => $hash,'txnid' => $myTxnId,'amount' => $the_order_total,'debug' => 1,'firstname' => $order->billing_first_name,'email' => $order->billing_email,'phone' => $order->billing_phone,'productinfo' => $productinfo,'surl' => $redirect_url,'furl' => $redirect_url,'lastname' => $order->billing_last_name,'address1' => $order->billing_address_1,'address2' => $order->billing_address_2,'city' => $order->billing_city,'state' => $order->billing_state,'country' => $order->billing_country,'zipcode' => $order->billing_postcode,'curl' => $redirect_url,'pg' => 'NB'
);
$payupaisa_args_array = array();
foreach($payupaisa_args as $key => $value){
$payupaisa_args_array[] = "<input type='hidden' name='$key' value='$value'/>";
}
return ' <form action="'.$this->liveurl.'" method="post" id="payupaisa_payment_form">
' . implode('',$payupaisa_args_array) . '
<input type="submit" class="button-alt" id="submit_payupaisa_payment_form" value="'.__('Pay via PayU Paisa','nilesh').'" /> <a class="button cancel" href="'.$order->get_cancel_order_url().'">'.__('Cancel order & restore cart','nilesh').'</a>
<script type="text/javascript">
jQuery(function(){
jQuery("body").block({
message: "'.__('Thank you for your order. We are Now redirecting you to Payment Gateway to make payment.','nilesh').'",overlayCSS: {
background : "#fff",opacity : 0.6
},css: {
padding : 20,textAlign : "center",color : "#555",border : "3px solid #aaa",backgroundColor : "#fff",cursor : "wait",lineHeight : "32px"
}
});
jQuery("#submit_payupaisa_payment_form").click();});
</script>
</form>';
}
/**
* Process the payment and return the result
**/
function process_payment($order_id){
global $woocommerce;
$order = new WC_Order( $order_id );
if ( version_compare( WOOCOMMERCE_VERSION,'2.1.0','>=' ) ) {
/* 2.1.0 */
$checkout_payment_url = $order->get_checkout_payment_url( true );
} else {
/* 2.0.0 */
$checkout_payment_url = get_permalink( get_option ( 'woocommerce_pay_page_id' ) );
}
return array(
'result' => 'success','redirect' => add_query_arg(
'order',$order->id,add_query_arg(
'key',$order->order_key,$checkout_payment_url
)
)
);
}
/**
* Check for valid payu server callback
**/
function check_payupaisa_response(){
global $woocommerce;
if( isset($_REQUEST['txnid']) && isset($_REQUEST['mihpayid']) ){
$order_id = $_REQUEST['udf1'];
if($order_id != ''){
try{
$order = new WC_Order( $order_id );
$hash = $_REQUEST['hash'];
$status = $_REQUEST['status'];
$checkhash = hash('sha512',"$this->salt|||||||||||$_REQUEST[email]|$_REQUEST[firstname]|$_REQUEST[productinfo]|$_REQUEST[amount]|$_REQUEST[txnid]|$this->merchant_id");
$transauthorised = false;
if( $order->status !=='completed' ){
if($hash == $checkhash){
$status = strtolower($status);
if($status=="success"){
$transauthorised = true;
$this->msg['message'] = "Thank you for shopping with us. Your account has been charged and your transaction is successful.";
$this->msg['class'] = 'woocommerce-message';
if($order->status == 'processing'){
$order->add_order_note('PayU Paisa ID: '.$_REQUEST['mihpayid'].' ('.$_REQUEST['txnid'].')<br/>PG: '.$_REQUEST['PG_TYPE'].'<br/>Bank Ref: '.$_REQUEST['bank_ref_num']);
}else{
$order->payment_complete();
$order->add_order_note('PayU Paisa payment successful.<br/>PayU Paisa ID: '.$_REQUEST['mihpayid'].' ('.$_REQUEST['txnid'].')<br/>PG: '.$_REQUEST['PG_TYPE'].'<br/>Bank Ref: '.$_REQUEST['bank_ref_num']);
$woocommerce -> cart -> empty_cart();
}
}else if($status=="pending"){
$this->msg['message'] = "Thank you for shopping with us. Right Now your payment status is pending. We will keep you posted regarding the status of your order through eMail";
$this->msg['class'] = 'woocommerce-info';
$order->add_order_note('PayU Paisa payment status is pending<br/>PayU Paisa ID: '.$_REQUEST['mihpayid'].' ('.$_REQUEST['txnid'].')<br/>PG: '.$_REQUEST['PG_TYPE'].'<br/>Bank Ref: '.$_REQUEST['bank_ref_num']);
$order->update_status('on-hold');
$woocommerce -> cart -> empty_cart();
}else{
$this->msg['class'] = 'woocommerce-error';
$this->msg['message'] = "Thank you for shopping with us. However,the transaction has been declined.";
$order->add_order_note('Transaction ERROR: '.$_REQUEST['error'].'<br/>PayU Paisa ID: '.$_REQUEST['mihpayid'].' ('.$_REQUEST['txnid'].')');
}
}else{
$this->msg['class'] = 'error';
$this->msg['message'] = "Security Error. Illegal access detected.";
}
if($transauthorised==false){
$order->update_status('Failed');
}
}
}catch(Exception $e){
$msg = "Error";
}
}
$redirect_url = ($this->redirect_page_id=="" || $this->redirect_page_id==0)?get_site_url() . "/":get_permalink($this->redirect_page_id);
//For wooCoomerce 2.0
$redirect_url = add_query_arg( array('msg'=> urlencode($this->msg['message']),'type'=>$this->msg['class']),$redirect_url );
wp_redirect( $redirect_url );
exit;
}
}
// get all pages
function payupaisa_get_pages($title = false,$indent = true) {
$wp_pages = get_pages('sort_column=menu_order');
$page_list = array();
if ($title) $page_list[] = $title;
foreach ($wp_pages as $page) {
$prefix = '';
// show indented child pages?
if ($indent) {
$has_parent = $page->post_parent;
while($has_parent) {
$prefix .= ' - ';
$next_page = get_post($has_parent);
$has_parent = $next_page->post_parent;
}
}
// add to page list array array
$page_list[$page->ID] = $prefix . $page->post_title;
}
return $page_list;
}
}
/**
* Add the Gateway to WooCommerce
**/
function woocommerce_add_payupaisa_gateway($methods) {
$methods[] = 'WC_payupaisa';
return $methods;
}
add_filter('woocommerce_payment_gateways','woocommerce_add_payupaisa_gateway' );
}
```
解决方法
我很清楚,收到付款后,订单状态没有变化?
您是否在插件和 PayU 面板中启用了自动接收?
您的服务器过滤 IP 地址还是使用 CloudFlare 之类的工具? 如果您过滤 IP 地址,请记住允许 PayU 使用的 IP 发送通知。它们是:
生产
185.68.12.10,185.68.12.11,185.68.12.12,185.68.12.26,185.68.12.27,185.68.12.28
沙盒
185.68.14.10,185.68.14.11,185.68.14.12,185.68.14.26,185.68.14.27,185.68.14.28
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。