ruạṛ
<?php /** * Plugin Name: POLi Payments * Plugin URI: http://www.polipayments.com * Description: A payment gateway plugin for POLi Payments * Version: 2.0 * Author: POLi Payments * Author URI: http://www.polipayments.com * License: GPL-3.0 */ add_action('plugins_loaded', 'woocommerce_gateway_poli_init', 0); function woocommerce_gateway_poli_init() { if ( !class_exists( 'WC_Payment_Gateway' ) ) return; load_plugin_textdomain('wc-gateway-poli', false, dirname( plugin_basename( __FILE__ ) ) . '/languages'); class WC_Gateway_POLi extends WC_Payment_Gateway { public function __construct() { $this->method_title = 'POLi Payments'; $this->id = 'poli'; $this->title = 'Internet banking (Pay with POLi)'; // Create admin configuration form $this->initForm(); // Initialise gateway settings $this->init_settings(); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_api_poli_nudge', array($this, 'result')); $this->description = 'Pay with POLi! You will be transferred to your internet banking.<br>' .'<a target="_blank" href="http://www.polipayments.com/consumer"><img src="'.plugins_url('', __FILE__) . '/images/poli.gif"></a>' .'<br><a target="_blank" href = https://transaction.apac.paywithpoli.com/POLiFISupported.aspx?merchantcode='.$this->get_option('merchantcode').'>Available Banks</a>'; } public function result() { global $woocommerce; if(!empty($_POST["Token"])||!empty($_GET["token"])) { $token = $_POST["Token"]; if(!$token){$token = $_GET["token"];} /* $xml_builder = '<?xml version="1.0" encoding="utf-8"?> <GetTransactionRequest xmlns="http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <AuthenticationCode>'.$this->get_option('authenticationcode').'</AuthenticationCode> <MerchantCode>'.$this->get_option('merchantcode').'</MerchantCode> <TransactionToken>' . $token . '</TransactionToken> </GetTransactionRequest>'; $ch = curl_init('https://merchantapi.apac.paywithpoli.com/MerchantAPIService.svc/Xml/transaction/query'); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml_builder); curl_setopt( $ch, CURLOPT_POST, 1); */ $auth = base64_encode( $this->get_option('merchantcode').":".$this->get_option('authenticationcode')); $header = array(); $header[] = 'Authorization: Basic '.$auth; $ch = curl_init("https://poliapi.apac.paywithpoli.com/api/Transaction/GetTransaction?token=".urlencode($token)); curl_setopt( $ch, CURLOPT_HTTPHEADER, $header); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt( $ch, CURLOPT_POST, 0); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0); $referrer = ""; curl_setopt($ch, CURLOPT_REFERER, $referrer); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec( $ch ); curl_close ($ch); $response_json = json_decode( $response, true ); // get response $poli_id=$response_json['TransactionRefNo']; $orderid = $response_json['MerchantReference']; $order_status = $response_json['MerchantDefinedData']; $completed = $response_json['TransactionStatusCode']; if( $response_json['MerchantDefinedData'] == "Completed" ){ $status=$order_status; } else if( $response_json['MerchantDefinedData'] == "TimedOut" ){ $status="10"; } else if( $response_json['MerchantDefinedData'] == "Failed" ){ $status="10"; } else if( $response_json['MerchantDefinedData'] == "Cancelled" ){ $status="10"; } if($completed == "Completed"){ if($orderid!=""||$orderid!=null){ $order = new WC_Order(''.$orderid); $order->add_order_note( __('POLi Nudge Recieved. POLi ID: '.$poli_id, 'woothemes') ); $order->payment_complete(); } } } if($_GET["token"]) { //$woocommerce->cart->empty_cart(); //$redirect_url = get_permalink(woocommerce_get_page_id('thanks')); // $redirect_url = $this->get_return_url( $order ); $redirect_url = $order->get_checkout_order_received_url(); wp_safe_redirect($redirect_url); } exit(); } private function initForm() { $this->form_fields = array( 'configuration' => array( 'title' => __('Set-up configuration', 'POLi'), 'type' => 'title' ), 'enabled' => array( 'title' => __( 'Enable POLi', 'POLi' ), 'label' => __( 'Enable POLi Payments in the checkout', 'POLi' ), 'type' => 'checkbox', 'description' => '', 'default' => 'no' ), 'merchantcode' => array( 'title' => __('Merchant Code', 'POLi'), 'type' => 'text', 'class' => 'ic-input', 'description' => __('Please input your Merchant Code', 'POLi'), 'desc_tip' => true ), 'authenticationcode' => array( 'title' => __('authenticationcode', 'POLi'), 'type' => 'text', 'class' => 'ic-input', 'description' => __('Please input your Authentication Code', 'POLi'), 'desc_tip' => true ) ); } function admin_options() { ?> <h3><?php _e('POLi Payments','POLi'); ?></h3> <table class="form-table"> <?php $this->generate_settings_html(); ?> </table> <?php } function process_payment ($order_id) { global $woocommerce; $order = new WC_Order( $order_id ); // Mark as on-hold (we're awaiting the cheque) $order->update_status('pending', __( 'Payment yet to be recieved', 'POLi Payments' )); $authenticationcode = $this->get_option('authenticationcode'); $merchantcode = $this->get_option('merchantcode'); $amount = $order->get_total(); $currency = get_woocommerce_currency(); $datetime = date('Y-m-d').'T'.date('H:i:s'); $ipaddress = $_SERVER["REMOTE_ADDR"]; $baselink = ''.site_url(); $merchantdata = $order_id; $nudge = ''.str_replace('https:', 'http:', add_query_arg('wc-api', 'poli_nudge', home_url('/'))); // $success = ''.str_replace('https:', 'http:', add_query_arg('wc-api', 'poli_nudge', home_url('/'))); $success = $this->get_return_url( $order ); $cancel = ''.get_permalink(woocommerce_get_page_id('cart')); // $url = "https://merchantapi.apac.paywithpoli.com/MerchantAPIService.svc/Xml/transaction/initiate"; $auth = base64_encode( $merchantcode.":".$authenticationcode); $header = array(); $header[] = 'Content-Type: application/json'; $header[] = 'Authorization: Basic '.$auth; $transaction_json = '{ "Amount":"'.$amount.'", "CurrencyCode":"'.$currency.'", "MerchantReference":"'.$merchantdata.'", "MerchantHomepageURL":"'.$baselink.'", "SuccessURL":"'.$success.'", "FailureURL":"'.$cancel.'", "CancellationURL":"'.$cancel.'", "NotificationURL":"'.$nudge.'" }'; $ch = curl_init("https://poliapi.apac.paywithpoli.com/api/Transaction/Initiate"); curl_setopt( $ch, CURLOPT_HTTPHEADER, $header); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, $transaction_json ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec( $ch ); curl_close ($ch); $response_json = json_decode($response, true); $redirect_url = ''; $error_message=null; if( isset( $response_json['NavigateURL'] ) and $response_json['NavigateURL'] != "" ){ $redirect_url=$response_json['NavigateURL']; } if( isset( $response_json['ErrorMessage'] ) and $response_json['ErrorMessage'] != "" ){ $error_message=$response_json['ErrorMessage']; } if( isset( $response_json['Message'] ) and $response_json['Message'] != "" ){ $error_message=$response_json['Message']; } if($error_message){ $woocommerce->add_error(__('Payment error:', 'woothemes') . $error_message); return; } // Reduce stock levels //$order->reduce_order_stock(); // Remove cart //$woocommerce->cart->empty_cart(); // Return thankyou redirect return array( 'result' => 'success', 'redirect' => $redirect_url ); } } /** * Add the Gateway to WooCommerce **/ function woocommerce_add_gateway_poli_gateway($methods) { $methods[] = 'WC_Gateway_POLi'; return $methods; } add_filter('woocommerce_payment_gateways', 'woocommerce_add_gateway_poli_gateway' ); new WC_Gateway_POLi; }
cải xoăn