最新的woocommerce版本支付网关集成存在问题。 我最近开始使用woocommerce为朋友,他有woocommerce版本1.6.5.2。但现在他将他的woocommerce更新到最新版本(2.0.12)。 他有一些定制的支付网关,适用于1.6版本,但现在它没有。 这是自定义支付网关代码:
/*
Plugin Name ......
.../*
$post_perma = trim( esc_url ( $_SERVER['REQUEST_URI'] ), '/' );
add_action('plugins_loaded', 'woocommerce_rba_etomitreba_init', 0);
if($post_perma == 'uspjeh'||$post_perma == 'greska') {
add_filter('the_content', 'after_processing');
}
function after_processing() {
global $post, $post_perma, $woocommerce;
if($post_perma == 'uspjeh') {
if(isset($_POST['OrderID'])&&isset($_POST['ApprovalCode'])) {
echo '<div class="notify notify-success">Not Important;)</div>';
$order = new WC_Order( $_POST['OrderID'] );
$order->payment_complete();
$order->status = 'completed';
$woocommerce->cart->empty_cart();
unset($_SESSION['order_awaiting_payment']);
}
else {
echo '<div class="notify notify-error">Not Important</div>';
}
}
if($post_perma == 'greska') {
echo '<div class="notify notify-error">DNot Important</div>';
}
}
function woocommerce_rba_etomitreba_init() {
if ( !class_exists( 'WC_Payment_Gateway' ) ) return;
class WC_Raiffeisen_Bank_eToMiTreba extends WC_Payment_Gateway {
public function __construct() {
$this->id = 'rba_etomitreba';
$this->method_title = __( 'Raiffeisen Bank', 'woocommerce' );
$this->icon = apply_filters('woocommerce_cheque_icon', '');
$this->has_fields = false;
// Load the form fields.
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'checkbox',
'label' => __( 'Not Important', 'woothemes' ),
'default' => 'yes'
),
'merchant-id' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'terminal-id' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'rsa-private-key' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'textarea',
'description' => __( 'Not Important', 'woothemes' ),
'default' => __( '', 'woothemes' )
),
'title' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'text',
'description' => __( '', 'woothemes' ),
'default' => __( 'Not Important', 'woothemes' )
),
'description' => array(
'title' => __( 'Not Important', 'woothemes' ),
'type' => 'textarea',
'description' => __( '', 'woothemes' ),
'default' => 'Not Important.'
)
);
// Load the settings.
$this->init_settings();
$this->title = $this->settings['title'];
$this->description = $this->settings['description'];
// Actions
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
}
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
$order->shipping_first_name;
$order->shipping_last_name;
$order->get_shipping_address();
$url_gateway = 'Not Important';
$merchant_id = 'xxxxx';
$terminal_id = 'xxxxx';
$total = $order->get_total()*100; // kn to lp conversion
$currency_id = 191;
$time = new DateTime('', new DateTimeZone('Europe/Zagreb'));
$purchase_time = $time->format('ymdHis');
$locale = 'hr';
$ordered_items = $order->get_items();
foreach($ordered_items as $item) {
$ordered_items_array[] = $item['name'];
}
$ordered_items = implode(', ',$ordered_items_array);
$purchase_desc = $time->format('d.m.Y. H:i:s').' - '.$order->shipping_first_name.' '.$order->shipping_last_name.' : '.$ordered_items;
$session_id = session_id();
$data = "$merchant_id;$terminal_id;$purchase_time;$order_id;$currency_id;$total;$session_id;";
$priv_key = $this->settings['rsa-private-key'];
$pkeyid = openssl_get_privatekey($priv_key);
openssl_sign($data, $signature, $pkeyid);
openssl_free_key($pkeyid);
$b64sign = base64_encode($signature);
$signature = $b64sign;
//$order->update_status('on-hold', __('Not Important', 'woothemes'));
echo '
<form name="ordersend" action="'.$url_gateway.'" method="post">
<input name="Version" type="hidden" value="1" >
<input name="MerchantID" type="hidden" value="'.$merchant_id.'" >
<input name="TerminalID" type="hidden" value="'.$terminal_id.'" >
<input name="TotalAmount" type="hidden" value="'.$total.'">
<input name="SD" type="hidden" value="'.$session_id.'">
<input name="Currency" type="hidden" value="'.$currency_id.'" >
<input name="Locale" type="hidden" value="'.$locale.'">
<input name="OrderID" type="hidden" value="'.$order_id.'" >
<input name="PurchaseTime" type="hidden" value="'.$purchase_time.'">
<input name="PurchaseDesc" type="hidden" value="'.$purchase_desc.'" >
<input name="Signature" type="hidden" value="'.$signature.'" >
</form>
<script language="javascript">
<!--
document.forms["ordersend"].submit();
--></script>
';
/*
return array (
'result' => 'success'
);*/
}
public function admin_options() {
?>
<img src="<?php echo 'Not Important ?>" width="664" height="114" />
<h3><?php _e('Not Important', 'woothemes'); ?></h3>
<p><?php _e('Not Important'); ?></p>
<table class="form-table">
<?php
// Generate the HTML For the settings form.
$this->generate_settings_html();
?>
</table>
<?php
} // End admin_options()
}
function woocommerce_raiffeisen_bank_etomitreba_gateway($methods) {
$methods[] = 'WC_Raiffeisen_Bank_eToMiTreba';
return $methods;
}
add_filter('woocommerce_payment_gateways', 'woocommerce_raiffeisen_bank_etomitreba_gateway' );
}
它只是一个兼容性问题,但正如我所说,我是woocommerce的新手,并没有经验丰富的PHP。任何帮助将不胜感激。
答案 0 :(得分:0)
更改
add_action('woocommerce_update_options_payment_gateways', array(&$this, process_admin_options'));
到
if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) );
} else {
add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) );
}