Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/unipay-payment-gateway-for-woocommerce/includes/class-back-link-handler.php
+++ b/unipay-payment-gateway-for-woocommerce/includes/class-back-link-handler.php
@@ -1,57 +1,73 @@
-<?php
-/**
- * Handles backlink.
- *
- * @package WooCommerce/UniPAY
- * @version 1.0.1
- */
-
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
-}
-
-class WC_Gateway_Unipay_Back_Link_Handler extends WC_Payment_Gateway {
-
- /**
- * Success and failed messages.
- * @var array $messages.
- */
- private $messages;
-
- /**
- * Constructor.
- *
- * @param array @messages
- */
- public function __construct( array $messages ) {
- $this->messages = $messages;
-
- add_action( 'woocommerce_api_wc_gateway_unipay_order', array( $this, 'handle_order' ) );
- }
-
- public function handle_order(){
-
- if(!empty( sanitize_text_field($_GET['ordercode']) )){
-
- $this->successOrder(sanitize_text_field($_GET['ordercode']));
- }
- }
-
- /**
- * success order and redirect url.
- * @param $orderId
- */
- protected function successOrder($orderId){
-
- global $woocommerce;
-
- $order = new WC_Order( $orderId );
-
- WC_Gateway_Wocommerce_Unipay::log( 'Complete payment order: '.$order->get_id().'. and redirect order receive page', 'success' );
- wc_add_notice( sprintf( __( $this->messages['success']) , "unipay" ) ,'success' );
- $woocommerce->cart->empty_cart();
- $redirectUrl = esc_url_raw($this->get_return_url( $order ));
- wp_redirect( $redirectUrl ); exit;
- }
-
-}
No newline at end of file
+<?php
+/**
+ * Handles backlink.
+ *
+ * @package WooCommerce/UniPAY
+ * @version 2.4
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class Unipay_PGW_Back_Link_Handler extends WC_Payment_Gateway {
+
+ /**
+ * Success and failed messages.
+ * @var array $messages.
+ */
+ private $messages;
+
+ /**
+ * Constructor.
+ *
+ * @param array @messages
+ */
+ public function __construct( array $messages ) {
+ $this->messages = $messages;
+
+ add_action( 'woocommerce_api_wc_gateway_unipay_order', array( $this, 'handle_order' ) );
+ }
+
+ /**
+ * Redirect the customer to the order received page.
+ *
+ * The link is only honoured when it carries the order key that was put into the
+ * return URL when the order was created, so an order id alone reveals nothing.
+ */
+ public function handle_order() {
+
+ // The order key below authenticates the request, a nonce cannot be used for a redirect coming from the payment page.
+ // phpcs:disable WordPress.Security.NonceVerification.Recommended
+ $orderId = isset( $_GET['ordercode'] ) ? absint( wp_unslash( $_GET['ordercode'] ) ) : 0;
+ $key = isset( $_GET['key'] ) ? sanitize_text_field( wp_unslash( $_GET['key'] ) ) : '';
+ // phpcs:enable WordPress.Security.NonceVerification.Recommended
+
+ $order = $orderId ? wc_get_order( $orderId ) : false;
+
+ if ( ! $order || '' === $key || 'unipay' !== $order->get_payment_method() || ! hash_equals( $order->get_order_key(), $key ) ) {
+ wp_safe_redirect( home_url( '/' ) );
+ exit;
+ }
+
+ $this->successOrder( $order );
+ }
+
+ /**
+ * success order and redirect url.
+ * @param WC_Order $order
+ */
+ protected function successOrder( $order ) {
+
+ Unipay_PGW_Gateway::log( 'Customer returned for order: ' . $order->get_id() . '. and redirect order receive page', 'info' );
+ wc_add_notice( esc_html( $this->messages['success'] ), 'success' );
+
+ if ( function_exists( 'WC' ) && WC()->cart ) {
+ WC()->cart->empty_cart();
+ }
+
+ wp_safe_redirect( $order->get_checkout_order_received_url() );
+ exit;
+ }
+
+}
--- a/unipay-payment-gateway-for-woocommerce/includes/class-ipn-handler.php
+++ b/unipay-payment-gateway-for-woocommerce/includes/class-ipn-handler.php
@@ -1,109 +1,182 @@
-<?php
-/**
- * Handles responses from UniPAY IPN.
- *
- * @package WooCommerce/UniPAY
- * @version 1.0.1
- */
-
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
-}
-
-class WC_Gateway_Unipay_IPN_Handler extends WC_Payment_Gateway {
-
- /**
- * User choose order statuses.
- * @var array
- */
- private $selectedStatuses;
-
- /**
- * Merchant secret key.
- * @var string
- */
- private $secretkey;
-
- /**
- * Constructor.
- *
- * @param array $selectedStatuses User choose order statuses.
- * @param @secretkey
- */
- public function __construct( array $selectedStatuses, $secretkey ) {
- $this->selectedStatuses = $selectedStatuses;
- $this->secretkey = $secretkey;
-
- add_action( 'woocommerce_api_wc_gateway_unipay', array( $this, 'handle_callback' ) );
- }
-
- /**
- * Check order status.
- */
- public function handle_callback(){
-
- global $woocommerce;
-
- if( empty(sanitize_text_field($_GET['Hash'])) ) return;
-
- /**
- * Calculated hash.
- * @var string
- */
- $Hash = !empty(sanitize_text_field($_GET['Hash'])) ? sanitize_text_field($_GET['Hash']) : '';
-
- /**
- * Unipay order id. it's unique.
- * @var string
- */
- $UnipayOrderID = !empty(sanitize_text_field($_GET['UnipayOrderID'])) ? sanitize_text_field($_GET['UnipayOrderID']) : '';
-
- /**
- * Changeable merchant odrer id.
- * @var string
- */
- $MerchantOrderID = !empty(sanitize_text_field($_GET['MerchantOrderID'])) ? sanitize_text_field($_GET['MerchantOrderID']): '';
-
- /**
- * Payment status. (COMPLETED, CANCELED, PENDING, FAILED).
- * @var string
- */
- $Status = !empty(sanitize_text_field($_GET['Status'])) ? sanitize_text_field($_GET['Status']) : '';
-
- /**
- * Transaction reason.
- * @var string
- */
- $Reason = !empty(sanitize_text_field($_GET['Reason'])) ? sanitize_text_field($_GET['Reason']) : '';
-
- /**
- * Calculate hash with secret key and all string parameters which are passed to function.
- * @param String $unipayOrderId.
- * @param String $merchandOrderId.
- * @param String $status.
- * @param String $secretKey.
- */
- $calculateHash = $UnipayOrderID.'|'. $MerchantOrderID.'|'.$Status.'|'.$this->secretkey;
-
- /**
- * Compare passed $hash and calcualted new hash.
- * If equals @param $hash and @param $calculateHash update order status by which user selected status.
- * If not equals order update status cancelled.
- */
- if( $Hash == md5($calculateHash) ){
- $orderID = explode("-", $MerchantOrderID);
- $order = new WC_Order( $orderID[1] );
- $order->update_status($this->selectedStatuses[$Status],__( 'Awaiting REDSYS payment', 'woocommerce' ));
- WC_Gateway_Wocommerce_Unipay::log( 'Update order ('.$order->get_id().') status. set '.$this->selectedStatuses[$Status].' status. UniPAY status is '.$Status.' Reason: '.$Reason, 'info' );
- if($Status === 'COMPLETED'){
- WC_Gateway_Wocommerce_Unipay::log( 'Complete payment order: '.$order->get_id(), 'success' );
- $order->payment_complete();
- $woocommerce->cart->empty_cart();
- }
- }
- else{
- WC_Gateway_Wocommerce_Unipay::log( 'Calculate hash not equal hash '.$Hash.'!=='.md5($calculateHash).' Reason: '.$Reason,'error' );
- }
-
- }
-}
+<?php
+/**
+ * Handles responses from UniPAY IPN.
+ *
+ * @package WooCommerce/UniPAY
+ * @version 2.4
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+class Unipay_PGW_IPN_Handler extends WC_Payment_Gateway {
+
+ /**
+ * User choose order statuses.
+ * @var array
+ */
+ private $selectedStatuses;
+
+ /**
+ * Merchant secret key.
+ * @var string
+ */
+ private $secretkey;
+
+ /**
+ * Constructor.
+ *
+ * @param array $selectedStatuses User choose order statuses.
+ * @param string $secretkey
+ */
+ public function __construct( array $selectedStatuses, $secretkey ) {
+ $this->selectedStatuses = $selectedStatuses;
+ $this->secretkey = (string) $secretkey;
+
+ add_action( 'woocommerce_api_wc_gateway_unipay', array( $this, 'handle_callback' ) );
+ }
+
+ /**
+ * Read a sanitized query parameter.
+ *
+ * @param string $name
+ * @return string
+ */
+ private function get_param( $name ) {
+ // The request is authenticated by the Hash parameter, not by a nonce: UniPAY calls this endpoint server to server.
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+ return isset( $_GET[ $name ] ) ? sanitize_text_field( wp_unslash( $_GET[ $name ] ) ) : '';
+ }
+
+ /**
+ * Stop processing the callback with an HTTP status.
+ *
+ * @param int $code
+ */
+ private function respond( $code ) {
+ status_header( $code );
+ exit;
+ }
+
+ /**
+ * Check order status.
+ */
+ public function handle_callback() {
+
+ $Hash = $this->get_param( 'Hash' );
+
+ if ( '' === $Hash ) {
+ return;
+ }
+
+ /**
+ * Without a configured secret key anyone can compute a valid hash, so never process the callback.
+ */
+ if ( '' === trim( $this->secretkey ) ) {
+ Unipay_PGW_Gateway::log( 'IPN rejected: SecretKey is not configured.', 'error' );
+ $this->respond( 403 );
+ }
+
+ /**
+ * Unipay order id. it's unique.
+ * @var string
+ */
+ $UnipayOrderID = $this->get_param( 'UnipayOrderID' );
+
+ /**
+ * Changeable merchant odrer id.
+ * @var string
+ */
+ $MerchantOrderID = $this->get_param( 'MerchantOrderID' );
+
+ /**
+ * Payment status. (COMPLETED, CANCELED, PENDING, FAILED).
+ * @var string
+ */
+ $Status = $this->get_param( 'Status' );
+
+ /**
+ * Transaction reason.
+ * @var string
+ */
+ $Reason = $this->get_param( 'Reason' );
+
+ /**
+ * Transaction version.
+ * @var string
+ */
+ $Version = $this->get_param( 'Version' );
+
+ /**
+ * Calculate hash with secret key and all string parameters which are passed to function.
+ * UnipayOrderID | MerchantOrderID | Status | SecretKey
+ */
+ $calculateHash = $UnipayOrderID . '|' . $MerchantOrderID . '|' . $Status . '|' . $this->secretkey;
+
+ if ( '2' === $Version ) {
+ $correct_hash = hash( 'sha256', $calculateHash );
+
+ switch ( $Status ) {
+ case '3':
+ $StatusString = 'COMPLETED';
+ break;
+ case '13':
+ case '22':
+ case '23':
+ $StatusString = 'FAILED';
+ break;
+ case '-1':
+ $StatusString = 'CANCELED';
+ break;
+ default:
+ $StatusString = 'PENDING';
+ }
+
+ $order_id = $MerchantOrderID;
+
+ } else {
+ $correct_hash = md5( $calculateHash );
+ $StatusString = $Status;
+ $orderID = explode( '-', $MerchantOrderID );
+ $order_id = isset( $orderID[1] ) ? $orderID[1] : '';
+ }
+
+ if ( ! hash_equals( $correct_hash, strtolower( $Hash ) ) ) {
+ Unipay_PGW_Gateway::log( 'IPN rejected: invalid hash. Reason: ' . $Reason, 'error' );
+ $this->respond( 403 );
+ }
+
+ if ( ! ctype_digit( (string) $order_id ) || ! isset( $this->selectedStatuses[ $StatusString ] ) ) {
+ Unipay_PGW_Gateway::log( 'IPN rejected: unknown order or status.', 'error' );
+ $this->respond( 400 );
+ }
+
+ $order = wc_get_order( (int) $order_id );
+
+ // Only orders that were placed with this gateway may be changed by the callback.
+ if ( ! $order || 'unipay' !== $order->get_payment_method() ) {
+ Unipay_PGW_Gateway::log( 'IPN rejected: order ' . (int) $order_id . ' not found or not paid with UniPAY.', 'error' );
+ $this->respond( 400 );
+ }
+
+ // A paid order must not be moved back by a replayed notification.
+ if ( $order->is_paid() ) {
+ $this->respond( 200 );
+ }
+
+ if ( 'COMPLETED' === $StatusString && '' !== $UnipayOrderID ) {
+ $order->set_transaction_id( $UnipayOrderID );
+ }
+
+ $order->update_status( $this->selectedStatuses[ $StatusString ], __( 'UniPAY payment notification', 'unipay-payment-gateway-for-woocommerce' ) );
+ Unipay_PGW_Gateway::log( 'Update order (' . $order->get_id() . ') status. set ' . $this->selectedStatuses[ $StatusString ] . ' status. UniPAY status is ' . $StatusString . ' Reason: ' . $Reason, 'info' );
+
+ if ( 'COMPLETED' === $StatusString ) {
+ Unipay_PGW_Gateway::log( 'Complete payment order: ' . $order->get_id(), 'success' );
+ $order->payment_complete( $UnipayOrderID );
+ }
+
+ $this->respond( 200 );
+ }
+}
--- a/unipay-payment-gateway-for-woocommerce/includes/settings.php
+++ b/unipay-payment-gateway-for-woocommerce/includes/settings.php
@@ -1,208 +1,194 @@
-<?php
-
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
-}
-
-wc_enqueue_js( "
- jQuery( function( $ ) {
- var ppec_mark_fields = '#woocommerce_unipay_image-color, #woocommerce_unipay_image-type, #woocommerce_unipay_image-size';
-
- $( '#woocommerce_unipay_image-status' ).change(function(){
- if ( $( this ).is( ':checked' ) ) {
- $( ppec_mark_fields ).closest( 'tr' ).show();
- } else {
- $( ppec_mark_fields ).closest( 'tr' ).hide();
- }
- }).change();
-
- });
-" );
-
-$settings = array(
- 'enabled' => array(
- 'title' => __('Enable/Disable', 'unipay'),
- 'type' => 'checkbox',
- 'label' => __('Enable UniPAY Payment Module.', 'unipay'),
- 'default' => 'yes',
- ),
- 'merchantid' => array(
- 'title' => __('MerchantID', 'unipay'),
- 'type' => 'text',
- 'desc_tip' => __('The unique wallet number assigned to the Merchant during registration','unipay'),
- ),
- 'secretkey' => array(
- 'title' => __('SecretKey', 'unipay'),
- 'type' => 'password',
- 'desc_tip' => __('Activation parameter which provides payment platform integration','unipay'),
- ),
- 'call_back_URL' => array(
- 'title' => 'Call Back URL',
- 'type' => 'title',
- 'desc_tip' => __('Call back URL is authorizing UniPAY transaction on merchants side', 'unipay'),
- 'description' => sprintf('%s','<code>'.get_site_url()."/?wc-api=WC_Gateway_Unipay".'</code>'),
- ),
- 'debug' => array(
- 'title' => __( 'Log', 'woocommerce' ),
- 'type' => 'checkbox',
- 'label' => __( 'Enable log', 'woocommerce' ),
- 'desc_tip' => __('This controls to log messages of contextual information', 'unipay'),
- 'description' => sprintf( __( '%s', 'unipay' ), '<code>' . WC_Log_Handler_File::get_log_file_path( 'unipay' ) . '</code>' ),
- ),
- 'checkout-page' => array(
- 'title' => __( 'Checkout Page', 'unipay' ),
- 'type' => 'title',
- 'description' => __('Advanced options of Checkout page','unipay'),
- ),
- 'title' => array(
- 'title' => __('Title:', 'unipay'),
- 'type' => 'text',
- 'default' => __('UniPAY Checkout', 'unipay'),
- 'desc_tip' => __('This controls the title which the user sees during checkout', 'unipay'),
- ),
- 'description' => array(
- 'title' => __('Description:', 'unipay'),
- 'type' => 'textarea',
- 'default' => __('Pay securely by Credit or Debit Card through UniPAY Secure Servers.', 'unipay'),
- 'css' => 'max-width:400px;',
- 'desc_tip' => __('This controls the description which the user sees during checkout','unipay'),
- ),
- 'button-title' => array(
- 'title' => __('Button', 'unipay'),
- 'type' => 'text',
- 'default' => __('Pay Now', 'unipay'),
- 'desc_tip' => __('This controls the button text which the user sees during checkout', 'unipay'),
- ),
- 'image-status' => array(
- 'title' => __('Image', 'unipay'),
- 'type' => 'checkbox',
- 'label' => __('Enable payment logo', 'unipay'),
- 'default' => 'yes',
- 'desc_tip' => __('Optionally Enable image is displayed as your payment logo of the checkout page','unipay'),
- ),
- 'image-color' => array(
- 'title' => __('Logo color', 'unipay'),
- 'type' => 'select',
- 'description' => __('This controls logo color which the user sees during checkout', 'unipay'),
- 'options' => array(
- 'color' => __('Color','unipay'),
- 'black' => __('Black','unipay'),
- 'white' => __('White','unipay'),
- )
- ),
- 'image-size' => array(
- 'title' => __('Choose logo size', 'unipay'),
- 'type' => 'select',
- 'description' => __('This controls the payment logo size which the user sees during checkout.', 'unipay'),
- 'options' => array(
- 'medium' => __('Medium','unipay'),
- 'small' => __('Small','unipay'),
- 'large' => __('Large','unipay'),
- )
- ),
- 'image-type' => array(
- 'title' => __('Payment logo type', 'unipay'),
- 'type' => 'select',
- 'default' => 'no',
- 'description' => __('This controls payment logo type which the user sees during checkout', 'unipay'),
- 'options' => array(
- '1' => __('With amex','unipay'),
- '0' => __('Without amex','unipay'),
- )
- ),
- 'process-payment' => array(
- 'title' => __( 'Payment status', 'unipay' ),
- 'type' => 'title',
- 'description' => __('UniPAY process status','unipay'),
- ),
- 'completed' => array(
- 'title' => __('UniPAY Completed status', 'unipay'),
- 'type' => 'select',
- 'description' => __('Set status, when UniPAY order is "Completed"', 'unipay'),
- 'options' => array(
- 'completed' => __('completed','unipay'),
- 'processing' => __('processing','unipay'),
- 'cancelled' => __('cancelled','unipay'),
- 'pending' => __('pending','unipay'),
- 'on-hold' => __('on-hold','unipay'),
- 'refuned' => __('refuned','unipay'),
- 'failed' => __('failed', 'unipay'),
- )
- ),
- 'processing' => array(
- 'title' => __('UniPAY Processing Status', 'unipay'),
- 'type' => 'select',
- 'description' => __('Set status, when UniPAY order is "Processing"', 'unipay'),
- 'options' => array(
- 'processing' => __('processing','unipay'),
- 'completed' => __('completed','unipay'),
- 'cancelled' => __('cancelled','unipay'),
- 'pending' => __('pending','unipay'),
- 'on-hold' => __('on-hold','unipay'),
- 'refuned' => __('refuned','unipay'),
- 'failed' => __('failed', 'unipay'),
- )
- ),
- 'success_message_en_US'=> array(
- 'title' => __('Success Message (English)', 'unipay'),
- 'type' => 'textarea',
- 'desc_tip' => __('Message to be displayed on successful transaction.', 'unipay'),
- 'default' => __('Your Transaction has been processed successfully.', 'unipay'),
- 'css' => 'max-width:400px;',
- ),
- 'failed_message_en_US' => array(
- 'title' => __('Failed Message (English)', 'unipay'),
- 'type' => 'textarea',
- 'desc_tip' => __('Message to be displayed on failed transaction.', 'unipay'),
- 'default' => __('Your has been declined.', 'unipay'),
- 'css' => 'max-width:400px;',
- ),
- 'success_message_ka_GE'=> array(
- 'title' => __('Success Message (Georgian)', 'unipay'),
- 'type' => 'textarea',
- 'desc_tip' => __('Message to be displayed on successful transaction.', 'unipay'),
- 'default' => __('ტრანზაქცია წარმატებით განხორციელდა.', 'unipay'),
- 'css' => 'max-width:400px;',
- ),
- 'failed_message_ka_GE' => array(
- 'title' => __('Failed Message (Georgian)', 'unipay'),
- 'type' => 'textarea',
- 'desc_tip' => __('Message to be displayed on failed transaction.', 'unipay'),
- 'default' => __('ტრანზაქცია უარყოფილია.', 'unipay'),
- 'css' => 'max-width:400px;',
- ),
- 'unipay-checkout-page' => array(
- 'title' => __( 'UniPAY Checkout page', 'unipay' ),
- 'type' => 'title',
- 'description' => __('Advanced options of UniPAY Checkout page','unipay'),
- ),
- 'order-description' => array(
- 'title' => __('Order Description', 'unipay'),
- 'type' => 'checkbox',
- 'label' => __('Enable Order Description', 'unipay'),
- 'default' => 'yes',
- 'desc_tip' => __('This controls the description which the user sees during UniPAY checkout page', 'unipay'),
- ),
- 'order-quantity' => array(
- 'title' => __('Order Quantity', 'unipay'),
- 'type' => 'checkbox',
- 'label' => __('Enable Order Quantity', 'unipay'),
- 'default' => 'yes',
- 'desc_tip' => __('This controls the order quantity which the user sees during UniPAY checkout page', 'unipay'),
- ),
- 'slogan' => array(
- 'title' => __('Slogan', 'unipay'),
- 'type' => 'text',
- 'desc_tip' => __('Add text is displayed as your slogan of the UniPAY checkout page (max. 70 symbols)', 'unipay'),
- 'placeholder' => 'Optional',
- ),
- 'logo_image_url' => array(
- 'title' => __( 'Logo Image (150x80)', 'unipay' ),
- 'type' => 'image',
- 'desc_tip' => __('Upload image is displayed as your logo in the upper left corner of the UniPAY checkout page', 'unipay'),
- 'description' => __( 'The image must be PNG or JPG format.', 'unipay' ),
-
- ),
-);
-
-return apply_filters( 'woocommerce_unipay_checkout_settings', $settings );
No newline at end of file
+<?php
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
+
+$unipay_pgw_settings = array(
+ 'enabled' => array(
+ 'title' => __('Enable/Disable', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'checkbox',
+ 'label' => __('Enable UniPAY Payment Module.', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => 'no',
+ ),
+ 'merchantid' => array(
+ 'title' => __('MerchantID', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'text',
+ 'desc_tip' => __('The unique wallet number assigned to the Merchant during registration', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'secretkey' => array(
+ 'title' => __('SecretKey', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'password',
+ 'desc_tip' => __('Required. Signs your orders and authenticates payment notifications from UniPAY; the gateway stays unavailable without it.', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'debug' => array(
+ 'title' => __( 'Log', 'unipay-payment-gateway-for-woocommerce' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'Enable log', 'unipay-payment-gateway-for-woocommerce' ),
+ 'desc_tip' => __('This controls to log messages of contextual information', 'unipay-payment-gateway-for-woocommerce'),
+ 'description' => '<code>' . esc_html( WC_Log_Handler_File::get_log_file_path( 'unipay' ) ) . '</code>',
+ ),
+ 'checkout-page' => array(
+ 'title' => __( 'Checkout Page', 'unipay-payment-gateway-for-woocommerce' ),
+ 'type' => 'title',
+ 'description' => __('Advanced options of Checkout page', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'title' => array(
+ 'title' => __('Title:', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'text',
+ 'default' => __('Credit Card (UniPAY)', 'unipay-payment-gateway-for-woocommerce'),
+ 'desc_tip' => __('This controls the title which the user sees during checkout', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'description' => array(
+ 'title' => __('Description:', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'textarea',
+ 'default' => __('Pay with your credit card via UniPAY payment gateway', 'unipay-payment-gateway-for-woocommerce'),
+ 'css' => 'max-width:400px;',
+ 'desc_tip' => __('This controls the description which the user sees during checkout', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'button-title' => array(
+ 'title' => __('Button', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'text',
+ 'default' => __('Pay Now', 'unipay-payment-gateway-for-woocommerce'),
+ 'desc_tip' => __('This controls the button text which the user sees during checkout', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'image-status' => array(
+ 'title' => __('Image', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'checkbox',
+ 'label' => __('Enable payment logo', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => 'yes',
+ 'desc_tip' => __('Optionally Enable image is displayed as your payment logo of the checkout page', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'image-color' => array(
+ 'title' => __('Logo color', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'select',
+ 'description' => __('This controls logo color which the user sees during checkout', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => 'color',
+ 'options' => array(
+ 'color' => __('Color', 'unipay-payment-gateway-for-woocommerce'),
+ 'black' => __('Black', 'unipay-payment-gateway-for-woocommerce'),
+ 'white' => __('White', 'unipay-payment-gateway-for-woocommerce'),
+ )
+ ),
+ 'image-size' => array(
+ 'title' => __('Choose logo size', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'select',
+ 'description' => __('This controls the payment logo size which the user sees during checkout.', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => 'large',
+ 'options' => array(
+ 'medium' => __('Medium', 'unipay-payment-gateway-for-woocommerce'),
+ 'small' => __('Small', 'unipay-payment-gateway-for-woocommerce'),
+ 'large' => __('Large', 'unipay-payment-gateway-for-woocommerce'),
+ )
+ ),
+ 'image-type' => array(
+ 'title' => __('Payment logo type', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'multiselect',
+ 'class' => 'wc-enhanced-select',
+ 'default' => 'unipay',
+ 'description' => __('This controls payment logo type which the user sees during checkout', 'unipay-payment-gateway-for-woocommerce'),
+ 'options' => array(
+ 'unipay' => __('UniPAY', 'unipay-payment-gateway-for-woocommerce'),
+ 'visa' => __('Visa', 'unipay-payment-gateway-for-woocommerce'),
+ 'mastercard' => __('Mastercard', 'unipay-payment-gateway-for-woocommerce'),
+ 'amex' => __('Amex', 'unipay-payment-gateway-for-woocommerce'),
+ // 'qrcode' => __('QrPAY', 'unipay-payment-gateway-for-woocommerce'),
+ )
+ ),
+ 'process-payment' => array(
+ 'title' => __( 'Payment status', 'unipay-payment-gateway-for-woocommerce' ),
+ 'type' => 'title',
+ 'description' => __('UniPAY process status', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'completed' => array(
+ 'title' => __('UniPAY Completed status', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'select',
+ 'description' => __('Set status, when UniPAY order is "Completed"', 'unipay-payment-gateway-for-woocommerce'),
+ 'options' => array(
+ 'completed' => __('completed', 'unipay-payment-gateway-for-woocommerce'),
+ 'processing' => __('processing', 'unipay-payment-gateway-for-woocommerce'),
+ 'cancelled' => __('cancelled', 'unipay-payment-gateway-for-woocommerce'),
+ 'pending' => __('pending', 'unipay-payment-gateway-for-woocommerce'),
+ 'on-hold' => __('on-hold', 'unipay-payment-gateway-for-woocommerce'),
+ 'refuned' => __('refuned', 'unipay-payment-gateway-for-woocommerce'),
+ 'failed' => __('failed', 'unipay-payment-gateway-for-woocommerce'),
+ )
+ ),
+ 'processing' => array(
+ 'title' => __('UniPAY Processing Status', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'select',
+ 'description' => __('Set status, when UniPAY order is "Processing"', 'unipay-payment-gateway-for-woocommerce'),
+ 'options' => array(
+ 'processing' => __('processing', 'unipay-payment-gateway-for-woocommerce'),
+ 'completed' => __('completed', 'unipay-payment-gateway-for-woocommerce'),
+ 'cancelled' => __('cancelled', 'unipay-payment-gateway-for-woocommerce'),
+ 'pending' => __('pending', 'unipay-payment-gateway-for-woocommerce'),
+ 'on-hold' => __('on-hold', 'unipay-payment-gateway-for-woocommerce'),
+ 'refuned' => __('refuned', 'unipay-payment-gateway-for-woocommerce'),
+ 'failed' => __('failed', 'unipay-payment-gateway-for-woocommerce'),
+ )
+ ),
+ 'success_message_en_US'=> array(
+ 'title' => __('Success Message (English)', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'textarea',
+ 'desc_tip' => __('Message to be displayed on successful transaction.', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => __('Transaction has been processed successfully.', 'unipay-payment-gateway-for-woocommerce'),
+ 'css' => 'max-width:400px;',
+ ),
+ 'failed_message_en_US' => array(
+ 'title' => __('Failed Message (English)', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'textarea',
+ 'desc_tip' => __('Message to be displayed on failed transaction.', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => __('Transaction has been declined.', 'unipay-payment-gateway-for-woocommerce'),
+ 'css' => 'max-width:400px;',
+ ),
+ 'success_message_ka_GE'=> array(
+ 'title' => __('Success Message (Georgian)', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'textarea',
+ 'desc_tip' => __('Message to be displayed on successful transaction.', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => __('ტრანზაქცია წარმატებით განხორციელდა.', 'unipay-payment-gateway-for-woocommerce'),
+ 'css' => 'max-width:400px;',
+ ),
+ 'failed_message_ka_GE' => array(
+ 'title' => __('Failed Message (Georgian)', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'textarea',
+ 'desc_tip' => __('Message to be displayed on failed transaction.', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => __('ტრანზაქცია უარყოფილია.', 'unipay-payment-gateway-for-woocommerce'),
+ 'css' => 'max-width:400px;',
+ ),
+ 'unipay-checkout-page' => array(
+ 'title' => __( 'UniPAY Checkout page', 'unipay-payment-gateway-for-woocommerce' ),
+ 'type' => 'title',
+ 'description' => __('Advanced options of UniPAY Checkout page', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'order-description' => array(
+ 'title' => __('Order Description', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'checkbox',
+ 'label' => __('Enable Order Description', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => 'yes',
+ 'desc_tip' => __('This controls the description which the user sees during UniPAY checkout page', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'order-quantity' => array(
+ 'title' => __('Order Quantity', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'checkbox',
+ 'label' => __('Enable Order Quantity', 'unipay-payment-gateway-for-woocommerce'),
+ 'default' => 'yes',
+ 'desc_tip' => __('This controls the order quantity which the user sees during UniPAY checkout page', 'unipay-payment-gateway-for-woocommerce'),
+ ),
+ 'slogan' => array(
+ 'title' => __('Slogan', 'unipay-payment-gateway-for-woocommerce'),
+ 'type' => 'text',
+ 'desc_tip' => __('Add text is displayed as your slogan of the UniPAY checkout page (max. 70 symbols)', 'unipay-payment-gateway-for-woocommerce'),
+ 'placeholder' => 'Optional',
+ ),
+ 'logo_image_url' => array(
+ 'title' => __( 'Logo Image (150x80)', 'unipay-payment-gateway-for-woocommerce' ),
+ 'type' => 'image',
+ 'desc_tip' => __('Upload image is displayed as your logo in the upper left corner of the UniPAY checkout page', 'unipay-payment-gateway-for-woocommerce'),
+ 'description' => __( 'The image must be PNG or JPG format.', 'unipay-payment-gateway-for-woocommerce' ),
+
+ ),
+);
+
+return apply_filters( 'woocommerce_unipay_checkout_settings', $unipay_pgw_settings );
No newline at end of file
--- a/unipay-payment-gateway-for-woocommerce/woocommerce-unipay.php
+++ b/unipay-payment-gateway-for-woocommerce/woocommerce-unipay.php
@@ -1,685 +1,935 @@
-<?php
-/*
- Plugin Name: UniPAY Payment Gateway For WooCommerce
- Description: Extends WooCommerce 3.0.0 to Process Payments with UniPAY gateway.
- Version: 1.0.3
- Plugin URI: http://woocommerce.ge/
- Author: UniPAY
- Author URI: https://www.unipay.com/
- License: Under GPL3
- Text Domain: unipay
- Domain Path: /languages
-*/
-
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
-}
-
-add_action( 'plugins_loaded', 'init_woocommerce_unipay_class' );
-
-function init_woocommerce_unipay_class() {
-
- if (!class_exists('WC_Payment_Gateway')) {
- return;
- }
-
- class WC_Gateway_Wocommerce_Unipay extends WC_Payment_Gateway {
-
- /**
- * Whether or not logging is enabled
- *
- * @var bool
- */
- public static $log_enabled = false;
-
- /**
- * Logger instance
- *
- * @var WC_Logger
- */
- public static $log = false;
-
- /**
- * Set if the place order button should be renamed on selection.
- * @var string
- */
- public $order_button_text;
-
- /**
- * yes or no based on whether the method is enabled.
- * @var string
- */
- public $enabled;
-
- /**
- * Payment method title for the frontend.
- * @var string
- */
- public $title;
-
- /**
- * Payment method description for the frontend.
- * @var string
- */
- public $description;
-
- /**
- * Gateway title.
- * @var string
- */
- public $method_title = '';
-
- /**
- * Gateway description.
- * @var string
- */
- public $method_description = '';
-
- /**
- * Icon for the gateway.
- * @var string
- */
- public $icon;
-
- /**
- * Unique Gateway ID.
- * @var string
- */
- public $id;
-
- /**
- * UniPAY create order live url.
- * @var string
- */
- public $liveurl;
-
- /**
- * API Merchant ID.
- * @var string
- */
- private $merchantid;
-
- /**
- * Merchant secret key.
- * @var string
- */
- private $secretkey;
-
- /**
- * Message to be displayed on successful transaction.
- * @var string
- */
- private $success_message;
-
- /**
- * Message to be displayed on failed transaction.
- * @var string
- */
- private $failed_message;
-
- /**
- * Call back url.
- * @var string
- */
- private $call_back_URL;
-
- /**
- * Logo which the user see during create order.
- * @var string
- */
- private $logo;
-
- /**
- * Slogan which the user see during create order.
- * @var string
- */
- private $slogan;
-
- /**
- * User choose order statuses.
- * @var array
- */
- private $selectedStatuses = array();
-
- /**
- * Enable/Disable order-description in create order page.
- * @var string yes/no
- */
- private $orderDescriptionStatus;
-
- /**
- * Constructor for the gateway.
- */
- public function __construct(){
-
- // Setup general properties
- $this->setup_properties();
-
- // Define fields.
- $this->init_form_fields();
-
- // Load the settings.
- $this->init_settings();
-
- // Get settings.
- $this->settings();
-
- 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' ) );
- }
-
- add_action('woocommerce_cancel_unipay',array(&$this, 'cancel_page'));
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
-
- require_once plugin_dir_path( __FILE__ ) . '/includes/class-ipn-handler.php';
- new WC_Gateway_Unipay_IPN_Handler( $this->selectedStatuses, $this->secretkey);
-
- require_once plugin_dir_path( __FILE__ ) . '/includes/class-back-link-handler.php';
- new WC_Gateway_Unipay_Back_Link_Handler( array('success' => $this->success_message, 'failed' => $this->failed_message));
-
- global $woocommerce;
- }
-
- /**
- * Enqueues admin scripts.
- *
- * @since 1.5.2
- */
- public function enqueue_scripts() {
- // Image upload.
- wp_enqueue_media();
-
- wp_enqueue_script( 'wc-unipay-settings', plugins_url( 'assets/js/wc-unipay-settings.js', __FILE__ ), array( 'jquery' ), '0.1', true );
- }
-
- /**
- * Setup general properties for the gateway.
- */
- protected function setup_properties() {
- $this->id = 'unipay';
- $this->method_title = __('UniPAY Checkout', 'unipay');
- $this->method_description = __('UniPAY Checkout is a payment gateway plugin that allows you to take credit card payments via UniPAY.com','unipay');
- $this->liveurl = 'https://api.unipay.com/checkout/createorder';
- }
-
- /**
- * Generate Title HTML.
- *
- * @param mixed $key
- * @param mixed $data
- * @since 1.0.0
- * @return string
- */
- public function generate_title_html( $key, $data ) {
- $field_key = $this->get_field_key( $key );
- $defaults = array(
- 'title' => '',
- 'class' => '',
- 'description' => '',
- );
-
- $data = wp_parse_args( $data, $defaults );
-
- ob_start();
- if($key !== 'call_back_URL') {
- ?>
- </table>
- <h3 class="wc-settings-sub-title <?php echo esc_attr( $data['class'] ); ?>" id="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></h3>
- <?php if ( ! empty( $data['description'] ) ) : ?>
- <p><?php echo wp_kses_post( $data['description'] ); ?></p>
- <?php endif; ?>
- <table class="form-table">
- <hr>
- <?php
- }
- else { ?>
- <tr valign="top">
- <th scope="row" class="titledesc">
- <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
- <?php echo wp_kses_post($this->get_tooltip_html( $data )); ?>
- </th>
- <td class="forminp">
- <fieldset>
- <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
- <?php echo wp_kses_post($this->get_description_html( $data )); ?>
- </fieldset>
- </td>
- </tr> <?php
- }
- return ob_get_clean();
- }
-
- /**
- * Get gateway icon.
- *
- * @return string
- */
- public function get_icon() {
- $icon_html = '';
- $icon = (array) $this->get_icon_image();
-
- foreach ( $icon as $i ) {
- $icon_html .= '<img src="' . esc_attr( $i ) . '" alt="' . esc_attr__( 'UniPAY', 'unipay' ) . '" />';
- }
-
- return apply_filters( 'woocommerce_gateway_icon', $icon_html, $this->id );
- }
-
- /**
- * Get UniPAY images for a size.
- *
- * @return array of image URLs
- */
- protected function get_icon_image( ) {
-
- if( $this->settings['image-status'] === 'no' ) return array();
-
- $this->settings['image-type'] == '0' ? $imageType = 'no-amex' : $imageType = 'amex';
-
- $icon = esc_url(WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/assets/images/logo-'.$this->settings['image-size'].'-'.$this->settings['image-color'].'-'.$imageType.'.png');
-
- return apply_filters( 'woocommerce_unipay_icon', $icon );
- }
-
- /**
- * Generate Image HTML.
- *
- * @param mixed $key
- * @param mixed $data
- * @since 1.5.0
- * @return string
- */
- public function generate_image_html( $key, $data ) {
- $field_key = $this->get_field_key( $key );
- $defaults = array(
- 'title' => '',
- 'disabled' => false,
- 'class' => '',
- 'css' => '',
- 'placeholder' => '',
- 'type' => 'text',
- 'desc_tip' => false,
- 'description' => '',
- 'custom_attributes' => array(),
- );
-
- $data = wp_parse_args( $data, $defaults );
- $value = $this->get_option( $key );
-
- // Hide show add remove buttons.
- $maybe_hide_add_style = '';
- $maybe_hide_remove_style = '';
-
- // For backwards compatibility (customers that already have set a url)
- $value_is_url = filter_var( $value, FILTER_VALIDATE_URL ) !== false;
-
- if ( empty( $value ) || $value_is_url ) {
- $maybe_hide_remove_style = 'display: none;';
- } else {
- $maybe_hide_add_style = 'display: none;';
- }
-
- ob_start();
- ?>
- <tr valign="top">
- <th scope="row" class="titledesc">
- <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label>
- </th>
-
- <td class="image-component-wrapper">
- <div class="image-preview-wrapper">
- <?php
- if ( ! $value_is_url ) {
- echo wp_get_attachment_image( $value, 'thumbnail' );
- } else {
- echo sprintf( __( 'Already using URL as image: %s', 'unipay' ), $value );
- }
- ?>
- </div>
-
- <button
- class="button image_upload"
- data-field-id="<?php echo esc_attr( $field_key ); ?>"
- data-media-frame-title="<?php echo esc_attr( __( 'Select a image to upload', 'unipay' ) ); ?>"
- data-media-frame-button="<?php echo esc_attr( __( 'Use this image', 'unipay' ) ); ?>"
- data-add-image-text="<?php echo esc_attr( __( 'Add image', 'unipay' ) ); ?>"
- style="<?php echo esc_attr( $maybe_hide_add_style ); ?>"
- >
- <?php echo esc_html__( 'Add image', 'unipay' ); ?>
- </button>
-
- <button
- class="button image_remove"
- data-field-id="<?php echo esc_attr( $field_key ); ?>"
- style="<?php echo esc_attr( $maybe_hide_remove_style ); ?>"
- >
- <?php echo esc_html__( 'Remove image', 'unipay' ); ?>
- </button>
-
- <input type="hidden"
- name="<?php echo esc_attr( $field_key ); ?>"
- id="<?php echo esc_attr( $field_key ); ?>"
- value="<?php echo esc_attr( $value ); ?>"
- />
- <?php if ( ! empty( $data['description'] ) ) : ?>
- <p><?php echo $this->get_description_html( $data ); ?></p>
- <?php endif; ?>
- </td>
- </tr>
- <?php
-
- return ob_get_clean();
- }
-
-
- /**
- * Output the admin options table.
- */
- public function admin_options(){
- ?>
- <div class="simplify-commerce-banner updated">
- <img src="<?php echo esc_attr(WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/assets/images/logo-admin.png'); ?>" />
- <p class="main">
- <h3>
- <?php esc_html_e( 'UniPAY Checkout', 'unipay' ); ?>
- </h3>
- <strong><?php esc_html_e( 'Getting started', 'unipay' ); ?></strong>
- </p>
- <p>
- <?php esc_html_e( 'UniPAY.com is one of the most popular payment processors in Georgia, UniPAY Checkout extension provides the most integrated checkout experience possible with WooCommerce to accept ewallet and credit card processing. ( Visa, Mastercard and AMEX )', 'unipay' ); ?>
- </p>
- <p>
- <a href="<?php esc_html_e("https://www.unipay.com/register") ?>" target="_blank" class="button button-primary"><?php esc_html_e( 'Register in UniPAY', 'unipay' ); ?></a>
- <a href="<?php esc_html_e("https://www.unipay.com/ecommerce") ?>" target="_blank" class="button"><?php esc_html_e( 'Learn more woocommerce', 'unipay' ); ?></a>
- </p>
- <hr>
- <strong><?php esc_html_e("UniPAY Support", 'unipay'); ?></strong>
- <p><?php esc_html_e("(+995 32) 2 193 194"); ?><br>
- <a href="<?php esc_html_e("https://www.unipay.com/support") ?>" target="_blank"><?php esc_html_e("We are here to help you 24/7 Support", 'unipay'); ?></a></p>
- <p><strong><?php esc_html_e("Version: 1.0.3"); ?></strong><p>
-
- </div>
-
- <table class="form-table">
- <?php esc_html($this->generate_settings_html()); ?>
- </table>
- <?php
- }
-
- /**
- * Define user set variables.
- */
- protected function settings(){
-
- // Get current locale
- get_locale() == 'ka_GE' ? $locale = 'ka_GE' : $locale = 'en_US';
-
- 'yes' === $this->settings['debug'] ? $this->debug = true : $this->debug = false;
-
- self::$log_enabled = $this->debug;
- $this->title = __($this->settings['title'], 'unipay');
- $this->description = __($this->settings['description'], 'unipay');
- $this->order_button_text = __($this->settings['button-title'], 'unipay');
- $this->merchantid = $this->settings['merchantid'];
- $this->secretkey = $this->settings['secretkey'];
- $this->success_message = $this->settings['success_message_'.$locale];
- $this->failed_message = $this->settings['failed_message_'.$locale];
- $this->call_back_URL = $this->settings['call_back_URL'];
- $this->logo = wp_get_attachment_image_src($this->settings['logo_image_url'],'medium')[0];
- $this->slogan = $this->settings['slogan'];
- $this->orderDescriptionStatus = $this->settings['order-description'];
- $this->orderQuantityStatus = $this->settings['order-quantity'];
- $this->selectedStatuses = array(
- 'COMPLETED' => $this->settings['completed'],
- 'PENDING' => $this->settings['processing'],
- 'FAILED' => 'failed',
- 'CANCELED' => 'cancelled'
- );
-
- }
-
- /**
- * Logging method.
- *
- * @param string $message Log message.
- * @param string $level Optional. Default 'info'. Possible values:
- * emergency|alert|critical|error|warning|notice|info|debug.
- */
- public static function log( $message, $level = 'info' ) {
- if ( self::$log_enabled ) {
- if ( empty( self::$log ) ) {
- self::$log = wc_get_logger();
- }
- self::$log->log( $level, $message, array( 'source' => 'unipay' ) );
- }
- }
-
- /**
- * Initialise settings form fields.
- *
- * Add an array of fields to be displayed
- * on the gateway's settings screen.
- *
- * @since 1.0.0
- */
- public function init_form_fields(){
- $this->form_fields = include( 'includes/settings.php' );
- }
-
- /**
- * Process the payment and return the result.
- *
- * return the success and redirect in an array. e.g:
- *
- * return array(
- * 'result' => 'success',
- * 'redirect' => $this->get_return_url( $order )
- * );
- *
- * @param int $order_id
- * @return array
- */
- public function process_payment( $order_id ) {
-
- global $woocommerce;
-
- /**
- * Create new order object.
- * @var string $order_id
- */
- $order = new WC_Order( $order_id );
-
- $responseItem = $this->item( $order, $woocommerce->cart->get_cart() );
- $responseCurl = $this->curl(array('environmentUrl' => esc_url($this->liveurl), 'merchantId' => $this->merchantid, 'password' => $responseItem['password'], 'opts' => $responseItem['opts']));
-
- if(empty($responseCurl)){
- wc_add_notice( sprintf( __( 'Incorect some parameters', "unipay" ) ) ,'error' );
- }
-
- /**
- * Done payment and return array if @var $responseCurl->Errorcode not zero and isset @var $responseCurl->Data->Checkout
- */
- if ( $responseCurl->Errorcode === 0 && !empty($responseCurl->Data->Checkout) ){
-
- add_post_meta($order_id, 'UnipayOrderID', $responseCurl->Data->UnipayOrderHashID);
- $order->add_order_note( __( $responseCurl->Data->UnipayOrderHashID, 'unipay' ) );
- $order->reduce_order_stock();
- $this->log( 'Success order '.$order->get_id().' and redirect UniPAY checkout page', 'success' );
- return array(
- 'result' => 'success',
- 'redirect' => esc_url($responseCurl->Data->Checkout),
- );
- }else{
- $order->add_order_note( esc_html(__( 'Unipay payment failed. Payment declined. Please Check your Admin settings', 'unipay' )) );
- $this->log( 'Payment Error: ' . $responseCurl->Message, 'error' );
- wc_add_notice( sprintf( __( $responseCurl->Message, "unipay" ) ) ,'error' );
- }
-
- }
-
- /**
- * Parse each items.
- * @var object $order
- * @var object $items
- * @return array hash and opts
- */
- protected function item( $order, $items ){
-
- /**
- * count total items.
- * @var $totalItems
- */
- $totalItems = count($items);
-
- /**
- * Get cart page url for backLink.
- * @var string $cartPageUrl
- */
- $cartPageUrl = get_permalink( wc_get_page_id( 'cart' ) );
-
- is_user_logged_in() ? $merchantUser = get_current_user_id() : $merchantUser = 'GUEST';
- get_locale() == "ka_GE" ? $language = "GE" : $language = "EN";
-
- $backLink = base64_encode(add_query_arg(array('wc-api'=>'WC_Gateway_Unipay_Order','ordercode'=>$order->id),home_url('/')) . "|" . $cartPageUrl);
-
- /**
- * Get each item and assemble array for crypt.
- * If $totalItems > 1 @var array $itemsArray
- */
- foreach ( $items as $item ){
-
- $this->orderDescriptionStatus == 'yes' ? $productDescription = preg_replace( '/[^p{L}0-9s]+/u', ' ',substr( get_post($item['product_id'])->post_content, 0,250 )) : $productDescription = '';
- $productTitle = preg_replace('/[^p{L}0-9s]+/u',' ',$item['data']->post->post_title);
-
- if($totalItems > 1){
- $this->orderQuantityStatus == 'yes' ? $quantity = $item['quantity'] : $quantity = '';
- $price = $item['line_subtotal'] * 100;
- $itemsArray[] = $price.'|'.$quantity.'|'.$productTitle.'|'.$productDescription;
- }
- }
-
- $arr = array(
- "MerchantID" => $this->merchantid,
- "MerchantUser" => $merchantUser,
- "MerchantOrderID" => uniqid('UN') . '-' . $order->id,
- "OrderPrice" => $order->order_total * 100,
- "OrderCurrency" => 'GEL',
- "BackLink" => $backLink,
- "Mlogo" => base64_encode($this->logo),
- "Mslogan" => preg_replace( '/[^p{L}0-9s]+/u', '',substr($this->slogan,0,70)),
- "Language" => $language
- );
-
- $orderItems = array();
-
- if($totalItems == 1){
- $arr['OrderName'] = $productTitle;
- $arr['OrderDescription'] = $productDescription;
- } else {
- $orderItems['Items'] = $itemsArray;
- }
-
- $hash = array('Hash'=> md5($this->secretkey.'|'.implode('|',$arr)));
- $hash = !is_null($orderItems) ? array_merge($hash, $orderItems) : $hash;
- $result = array_merge($hash, $arr);
-
- // Return thank you redirect
- return array(
- 'password' => $hash['Hash'],
- 'opts' => json_encode($result)
- );
- }
-
- /**
- * Curl
- * @param array $params
- * @return curl $response
- */
- protected function curl(array $params){
-
- $curl = curl_init($params['environmentUrl']);
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_USERPWD, "$params[merchantId]:$params[password]"); //Your credentials goes here
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $params['opts']);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //IMP if the url has https and you don't want to verify source certificate
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($params['opts']))
- );
- curl_setopt($curl, CURLOPT_HEADER, false);
-
- $curlResponse = curl_exec($curl);
- $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
-
- if ( $status != 200 ) {
- $this->log( "Error: call to URL failed with status $status, response $curlResponse, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl), 'error' );
- die("Error: call to URL failed with status $status, response $curlResponse, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
- }
-
- $response = json_decode($curlResponse);
-
- curl_close($curl);
-
- return $response;
- }
-
- /**
- * Cancel page
- * @param $oder_id
- */
- public function cancel_page($order_id){
- $this->log( 'Cancell order '.$order_id.' and redirect cart page', 'info' );
- echo sprintf(__($this->failed_message, 'unipay'), 'error');
- }
-
- }
-}
-
-
-/**
- * Add this Gateway to WooCommerce
-**/
-function woocommerce_add_unipay_gateway($methods) {
-
- $methods[] = 'WC_Gateway_Wocommerce_Unipay';
- return $methods;
-}
-add_filter('woocommerce_payment_gateways', 'woocommerce_add_unipay_gateway' );
-
-add_filter('manage_edit-shop_order_columns', 'ST4_columns_head', 10);
-add_action('manage_shop_order_posts_custom_column', 'ST4_columns_shop_order_content', 10, 2);
-//ADD TWO NEW COLUMNS
-
-function ST4_columns_head($defaults) {
- $defaults['UnipayOrderID'] = 'UnipayOrderID';
- return $defaults;
-}
-function ST4_columns_shop_order_content($column_name, $post_ID) {
- if ($column_name == 'UnipayOrderID') {
- echo get_post_meta($post_ID,'UnipayOrderID',true);
- }
-}
-
-function filter_gateways($gateways){
- global $woocommerce;
-
- $currenctCurrency = get_woocommerce_currency();
-
- if ($currenctCurrency != "GEL") {
- unset($gateways['unipay']);
- }
-
- return $gateways;
-}
-
-add_filter('woocommerce_available_payment_gateways','filter_gateways');
-
-add_filter( 'woocommerce_currencies', 'add_my_currency' );
-function add_my_currency( $currencies ) {
- $currencies['GEL'] = __( 'Georgia', 'woocommerce' );
- return $currencies;
-}
No newline at end of file
+<?php
+/*
+ Plugin Name: UniPAY Payment Gateway For WooCommerce
+ Description: Extends WooCommerce 5.6.0 to Process Payments with UniPAY gateway.
+ Version: 2.4
+ Plugin URI: https://wordpress.org/plugins/unipay-payment-gateway-for-woocommerce/
+ Author: UniPAY
+ Author URI: https://www.unipay.com/
+ License: GPLv3 or later
+ License URI: https://www.gnu.org/licenses/gpl-3.0.html
+ Text Domain: unipay-payment-gateway-for-woocommerce
+ Requires at least: 6.0
+ Requires PHP: 7.4
+ Requires Plugins: woocommerce
+*/
+
+if (!defined('ABSPATH')) {
+ exit;
+}
+
+add_action('plugins_loaded', 'unipay_pgw_init_gateway');
+
+function unipay_pgw_init_gateway()
+{
+
+ if (!class_exists('WC_Payment_Gateway')) {
+ return;
+ }
+
+ class Unipay_PGW_Gateway extends WC_Payment_Gateway
+ {
+
+ /**
+ * Whether or not logging is enabled
+ *
+ * @var bool
+ */
+ public static $log_enabled = false;
+
+ /**
+ * Logger instance
+ *
+ * @var WC_Logger
+ */
+ public static $log = false;
+
+ /**
+ * Set if the place order button should be renamed on selection.
+ * @var string
+ */
+ public $order_button_text;
+
+ /**
+ * yes or no based on whether the method is enabled.
+ * @var string
+ */
+ public $enabled;
+
+ /**
+ * Payment method title for the frontend.
+ * @var string
+ */
+ public $title;
+
+ /**
+ * Payment method description for the frontend.
+ * @var string
+ */
+ public $description;
+
+ /**
+ * Gateway title.
+ * @var string
+ */
+ public $method_title = '';
+
+ /**
+ * Gateway description.
+ * @var string
+ */
+ public $method_description = '';
+
+ /**
+ * Icon for the gateway.
+ * @var string
+ */
+ public $icon;
+
+ /**
+ * Unique Gateway ID.
+ * @var string
+ */
+ public $id;
+
+ /**
+ * UniPAY create order live url.
+ * @var string
+ */
+ public $liveurl;
+
+ /**
+ * UniPAY create order live url.
+ * @var string
+ */
+ public $liveurlv2;
+
+ /**
+ * API Merchant ID.
+ * @var string
+ */
+ private $merchantid;
+
+ /**
+ * Merchant secret key.
+ * @var string
+ */
+ private $secretkey;
+
+ /**
+ * Message to be displayed on successful transaction.
+ * @var string
+ */
+ private $success_message;
+
+ /**
+ * Message to be displayed on failed transaction.
+ * @var string
+ */
+ private $failed_message;
+
+ /**
+ * Call back url.
+ * @var string
+ */
+ private $call_back_URL;
+
+ /**
+ * Logo which the user see during create order.
+ * @var string
+ */
+ private $logo;
+
+ /**
+ * Slogan which the user see during create order.
+ * @var string
+ */
+ private $slogan;
+
+ /**
+ * User choose order statuses.
+ * @var array
+ */
+ private $selectedStatuses = array();
+
+ /**
+ * Enable/Disable order-description in create order page.
+ * @var string yes/no
+ */
+ private $orderDescriptionStatus;
+
+ /**
+ * Enable/Disable order-quantity in create order page.
+ * @var string yes/no
+ */
+ private $orderQuantityStatus;
+
+ /**
+ * Whether debug logging is on.
+ * @var bool
+ */
+ protected $debug = false;
+
+ /**
+ * Constructor for the gateway.
+ */
+ public function __construct()
+ {
+
+ // Setup general properties
+ $this->setup_properties();
+
+ // Define fields.
+ $this->init_form_fields();
+
+ // Load the settings.
+ $this->init_settings();
+
+ // Get settings.
+ $this->settings();
+
+ 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'));
+ }
+
+ add_action('woocommerce_cancel_unipay', array(&$this, 'cancel_page'));
+ add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
+
+ require_once plugin_dir_path(__FILE__) . '/includes/class-ipn-handler.php';
+ new Unipay_PGW_IPN_Handler($this->selectedStatuses, $this->secretkey);
+
+ require_once plugin_dir_path(__FILE__) . '/includes/class-back-link-handler.php';
+ new Unipay_PGW_Back_Link_Handler(array('success' => $this->success_message, 'failed' => $this->failed_message));
+
+ global $woocommerce;
+ }
+
+ /**
+ * Enqueues admin scripts.
+ *
+ * @since 1.5.2
+ */
+ public function enqueue_scripts()
+ {
+ // Image upload.
+ wp_enqueue_media();
+
+ wp_enqueue_script('wc-unipay-settings', plugins_url('assets/js/wc-unipay-settings.js', __FILE__), array('jquery'),