Variables are not being shown

So basically i’m new to php and trying to fix a problem with a gateway plugin for woocommerce on wordpress. The Author is unavailable at the moment but basically everything seems ok till i make a purchase that is confirmed on the webservice and on return back to the site it gives this error:

Transaction Failed:

Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.

Please attempt your purchase again or go to your account page.
Warning: end() expects parameter 1 to be array, null given in /home/content/56/11998056/html/wp-content/plugins/woocommerce-globalpay/woocommerce-globalpay.php on line 355

Warning: end() expects parameter 1 to be array, null given in /home/content/56/11998056/html/wp-content/plugins/woocommerce-globalpay/woocommerce-globalpay.php on line 357

Warning: end() expects parameter 1 to be array, null given in /home/content/56/11998056/html/wp-content/plugins/woocommerce-globalpay/woocommerce-globalpay.php on line 358

Warning: end() expects parameter 1 to be array, null given in /home/content/56/11998056/html/wp-content/plugins/woocommerce-globalpay/woocommerce-globalpay.php on line 359

Warning: end() expects parameter 1 to be array, null given in /home/content/56/11998056/html/wp-content/plugins/woocommerce-globalpay/woocommerce-globalpay.php on line 360

Warning: end() expects parameter 1 to be array, null given in /home/content/56/11998056/html/wp-content/plugins/woocommerce-globalpay/woocommerce-globalpay.php on line 361

Sorry. Your payment was not successful
Below are the details of your payment transaction:
Transaction reference: 149-3236-1399566876
Customer name:
Amount paid: 0.00
Currency:
Payment Channel:
GlobalPay reference:
Transaction status description:

From what i’ve been able to gather it seems theres a problem consuming the values (if thats the right phrase) and i’m not sure why its doing that. I’ve attached the source file so you can go through.
Please i’d really appreciate your help here.
Thanks.

Heres the part of the code that i think is important so i dont exceed the 2000 characters:
[php]<?php
/**

function woocommerce_globalpay_init() {
// The GlobalPay plugin should only be loaded if Woocommerce is installed.
if (!class_exists(‘WC_Payment_Gateway’)) {
return;
}

class WC_GlobalPay extends WC_Payment_Gateway {
/**
* Array that will hold payment information.
*
* The response from GlobalPay’s transaction lookup webservice is in XML.
* So SimpleXML is used to manipulate it but eventually it will be made into
* a single-dimension array so that it can stored as part of the order meta
* information. This variable needs to declared at class level at the
* function that converts the simpleXML object into an array is recursive.
*
* @var array
* @access private
*/
private $payment_info = array();

public function __construct() {
  global $woocommerce;

  $this->id = 'globalpay';
  $this->icon = apply_filters('woocommerce_globalpay_icon',
      plugins_url('/images/globalpay_logo.png', __FILE__ ));
  $this->has_fields = false;
  $this->liveurl = 'https://www.globalpay.com.ng/Paymentgatewaycapture.aspx';
  $this->testurl = 'https://demo.globalpay.com.ng/globalpay_demo/paymentgatewaycapture.aspx';
  $this->method_title = __('GlobalPay', 'woocommerce');

  // Load the form fields.
  $this->init_form_fields();

  // Load the settings.
  $this->init_settings();

  // Define user set variables.
  $this->title = $this->settings['title'];
  $this->description = $this->settings['description'];
  $this->merchant_id = $this->settings['merchant_id'];
  $this->testmode = $this->settings['testmode'];
  $this->debug = $this->settings['debug'];
  $this->thanks_message = $this->settings['thanks_message'];
  $this->error_message = $this->settings['error_message'];
  $this->feedback_message = '';
  $this->webservice_user = $this->settings['webservice_user'];
  $this->webservice_password = $this->settings['webservice_password'];

  // Actions.
  add_action('woocommerce_receipt_globalpay',
    array(&$this, 'receipt_page'));

  add_action('woocommerce_thankyou_' . $this->id,
    array(&$this, 'thankyou_page'));

  add_action( 'woocommerce_update_options_payment_gateways_' . $this->id,
    array( $this, 'process_admin_options' ) );

  // Logs
  if ($this->debug=='yes') $this->log = $woocommerce->logger();

  if ( !$this->is_valid_for_use() ) $this->enabled = false;
}

function is_valid_for_use() {
  
  if (!in_array(get_option('woocommerce_currency'), array('NGN'))) {
    return false;
  } else {
    return true;
  }
}
  
function admin_options() {
  echo '<h3>' . __('GlobalPay', 'woocommerce') . '</h3>';
  echo '<p>' . __('GlobalPay works by sending the user to GlobalPay to enter their payment information.', 'woocommerce') . '</p>';
  echo '<table class="form-table">';
    
  if ( $this->is_valid_for_use() ) {
    $this->generate_settings_html();
  } else {
    echo '<div class="inline error"><p><strong>' . __( 'Gateway Disabled', 'woocommerce' ) . '</strong>: ' . __( 'GlobalPay does not support your store currency.', 'woocommerce' ) . '</p></div>';
  }
    
  echo '</table>';
    
}

function init_form_fields() {
  $this->form_fields = array(
    'enabled' => array(
      'title' => __( 'Enable/Disable', 'woocommerce' ),
      'type' => 'checkbox',
      'label' => __( 'Enable GlobalPay', 'woocommerce' ),
      'default' => 'yes'
    ),
    'title' => array(
      'title' => __( 'Title', 'woocommerce' ),
      'type' => 'text',
      'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
      'default' => __( 'GlobalPay', 'woocommerce' )
    ),
    'description' => array(
      'title' => __( 'Description', 'woocommerce' ),
      'type' => 'textarea',
      'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce' ),
      'default' => __('Pay via GlobalPay', 'woocommerce')
    ),
    'merchant_id' => array(
      'title' => __( 'GlobalPay Merchant ID', 'woocommerce' ),
      'type' => 'text',
      'description' => __( 'Merchant ID given to you by GlobalPay', 'woocommerce' ),
      'default' => __('', 'woocommerce')
    ),
    'thanks_message' => array(
      'title' => __( 'Thanks message', 'woocommerce' ),
      'type' => 'textarea',
      'description' => __( 'The message to show on a successful payment', 'woocommerce' ),
      'default' => __('Thank you. Your payment was successful. Your order is status is now <strong>processing</strong>', 'woocommerce')
    ),
    'error_message' => array(
      'title' => __( 'Failure message', 'woocommerce' ),
      'type' => 'textarea',
      'description' => __( 'The message to show when a payment has failed', 'woocommerce' ),
      'default' => __('Sorry. Your payment was not successful', 'woocommerce')
    ),
    'testmode' => array(
      'title' => __( 'GlobalPay Test Mode', 'woocommerce' ),
      'type' => 'checkbox',
      'label' => __( 'Enable GlobalPay Test Mode', 'woocommerce' ),
      'default' => 'yes'
    ),
    'webservice_user' => array(
      'title' => __('GlobalPay webservice user ID', 'woocommerce' ),
      'type' => 'text',
      'description' => __( 'The user ID for the GlobalPay transaction lookup service', 'woocommerce' ),
      'label' => __( 'GlobalPay webservice user ID', 'woocommerce' )
    ),
    'webservice_password' => array(
      'title' => __('GlobalPay webservice password', 'woocommerce' ),
      'type' => 'text',
      'description' => __( 'The password for the GlobalPay transaction lookup service', 'woocommerce' ),
      'label' => __( 'GlobalPay webservice user ID', 'woocommerce' )
    ),
    'debug' => array(
      'title' => __( 'Debug', 'woocommerce' ),
      'type' => 'checkbox',
      'label' => __( 'Enable logging (<code>woocommerce/logs/globalpay.txt</code>)', 'woocommerce' ),
      'default' => 'no'
    )
  );

}
function get_globalpay_args( $order ) {
  global $woocommerce;

  $txn_ref = get_current_user_id() . '-' . $order->id . '-' . time();
  update_post_meta($order->id, 'merch_txnref', $txn_ref);

  $order_total = $order->get_order_total();

  if ($this->debug=='yes') {
    $this->log->add( 'globalpay', 'Generating payment form for order #' . $order->id . '.');
  }

  $globalpay_args = array(
    'merchantid' => $this->merchant_id,
    'amount' => $order_total,
    'currency' => get_woocommerce_currency(),
    'merch_txnref' => $txn_ref,
    'names' => trim($order->billing_first_name .
        ' ' . $order->billing_last_name),
    'email_address' => $order->billing_email,
    'phone_number' => $order->billing_phone
  );

  $globalpay_args = apply_filters('woocommerce_globalpay_args',
      $globalpay_args);
  
  return $globalpay_args;
}

function generate_globalpay_form( $order_id ) {
  global $woocommerce;
  
  $order = new WC_Order( $order_id );
  $globalpay_args = $this->get_globalpay_args( $order );
  $globalpay_args_array = array();
  
  $globalpay_adr = $this->liveurl;
  if ( $this->testmode == 'yes' ) {
    $globalpay_adr = $this->testurl;
  }

  foreach ($globalpay_args as $key => $value) {
    $globalpay_args_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
  }
  
  $woocommerce->add_inline_js('
    jQuery("body").block({
      message: "' . __('Thank you for your order. We are now redirecting you to GlobalPay to make payment.', 'woocommerce') .'",
      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_globalpay_payment_form").click();
  ');
  
  $form = '<form action="'.esc_url( $globalpay_adr ).'" method="post" id="globalpay_payment_form">
      ' . implode('', $globalpay_args_array) . '
      <input type="submit" class="button-alt" id="submit_globalpay_payment_form" value="'.__('Pay via GlobalPay', 'woocommerce').'" /> <a class="button cancel" href="'.esc_url( $order->get_cancel_order_url() ).'">'.__('Cancel order &amp; restore cart', 'woocommerce').'</a>
    </form>';
  
  if ('yes' == $this->debug) {
    $this->log->add('globalpay',
      'User redirected to GlobalPay with the following:' . "\r\n"
      . 'GlobalPay URL: ' . $globalpay_adr . "\r\n"
      . print_r($globalpay_args, TRUE));
  }
  
  // Place the order ID and redirect URL in the session. To be used when the
  // user is redirected back from GlobalPay
  $_SESSION['globalpay_order_id'] = $order_id;
  $_SESSION['globalpay_redirect_url'] = $this->get_return_url($order);
  
  return $form;
}

function check_transaction_on_user_return() {
  @ob_clean();
  global $woocommerce;
  
  if ('yes' == $this->debug) {
    $this->log->add('globalpay',
      'Transaction details received on user return from GlobalPay:' . "\r\n"
      . print_r($_GET, TRUE));
  }
  
  if (!isset($_SESSION['globalpay_order_id'])) {
    wp_redirect(home_url());
    exit;
  }
  $order_id = $_SESSION['globalpay_order_id'];
  unset($_SESSION['globalpay_order_id']);

  $order = new WC_Order( (int) $order_id );
  $merch_txnref = get_post_meta($order->id, 'merch_txnref', true);
  if (!$order) {
    // @todo: notify user and admin of this ie order not found
  }
  
  //fool the thanks page into working?
  $_GET['key'] = $order->order_key;
  $_GET['order'] = $order->id;

  $this->get_transaction_status($merch_txnref, $order->get_order_total());
  foreach ($this->payment_info as $k => $v) {
    if ('status' != $k){
      update_post_meta((int)$order_id, $k, $v);
    }
  }

  if ('completed' == $this->payment_info['status']) {
    // Payment completed
    $order->add_order_note( __('Payment completed', 'woocommerce') );
    $order->payment_complete();
    $woocommerce->cart->empty_cart();
    
    if ($this->debug=='yes') $this->log->add('globalpay', 'Payment complete.' );

    update_post_meta((int) $order_id, 'Payment Method', $this->method_title);

    $this->send_mail_successful_payment(
      $order->id,
      $order->get_order_total(),
      $this->payment_info['txnref'],
      $order->user_id
    );
  } else if ('failed' == $this->payment_info['status']) {
    $error_code = $this->payment_info['payment_status_description'];
    $order->add_order_note(__('Payment Failed - ' . $error_code, 'woocommerce'));
    $order->update_status('failed');

    $woocommerce->add_error('Transaction Failed: ' . $error_code);
  } else if ('on-hold' == $this->payment_info['status']) {
    $order->update_status('on-hold', sprintf(
        __( 'Payment pending: %s', 'woocommerce' ),
        'Amount discrepancy'
    ));
    $error_code = 'Amount discrepancy';
    // Notify admin of discrepancy in amount
    $this->send_mail_discrepancy_in_payment($order->id, $order->user_id,
        $order->get_order_total(), $this->payment_info['amount']);
    $woocommerce->add_error('Order on hold: ' . $error_code);
  } else if (FALSE == $this->payment_info['status']) {
    $order->update_status(
      'on-hold',
      sprintf (
        __( 'Payment pending: %s', 'woocommerce' ),
        $error
      )
    );
    $order->add_order_note(__('Payment on-hold - ' . $error, 'woocommerce'));
    $order->update_status('on-hold');
    
    $this->send_mail_payment_info_pending($order->id,
      $order->billing_first_name . ' ' . $order->billing_last_name);
    $woocommerce->add_error('There was an error while looking up the details of your payment information. A sales person has been notified');
  }
}

function thankyou_page($order_id) {
  $order = new WC_Order($order_id);
  // All elements of $order_payment_info are arrays. So when getting the
  // value get the value at the end of the array which should represent
  // the most current value
  $order_payment_info = get_post_meta($order_id);
  if ('completed' == $order->status || 'processing' == $order->status) {
    $this->feedback_message = $this->thanks_message
      . '<br/>Below are the details of your payment transaction:'
      . '<br/><strong>Transaction reference:</strong> ' . end($order_payment_info['merch_txnref'])
      . '<br/><strong>Customer name:</strong> ' . end($order_payment_info['names'])
      . '<br/><strong>Amount paid:</strong> '
        . number_format(end($order_payment_info['amount']), 2)
      . '<br/><strong>Currency:</strong> ' . end($order_payment_info['currency'])
      . '<br/><strong>Payment Channel:</strong> ' . end($order_payment_info['channel'])
      . '<br/><strong>GlobalPay reference:</strong> ' . end($order_payment_info['txnref'])
      . '<br/><strong>Transaction status description:</strong> ' . end($order_payment_info['payment_status_description']);
  } else if ('failed' == $order->status) {
    $this->feedback_message = $this->error_message
      . '<br/>Below are the details of your payment transaction:'
      . '<br/><strong>Transaction reference:</strong> ' . end($order_payment_info['merch_txnref'])
      . '<br/><strong>Customer name:</strong> ' . end($order_payment_info['names'])
      . '<br/><strong>Amount paid:</strong> '
        . number_format(end($order_payment_info['amount']), 2)
      . '<br/><strong>Currency:</strong> ' . end($order_payment_info['currency'])
      . '<br/><strong>Payment Channel:</strong> ' . end($order_payment_info['channel'])
      . '<br/><strong>GlobalPay reference:</strong> ' . end($order_payment_info['txnref'])
      . '<br/><strong>Transaction status description:</strong> ' . end($order_payment_info['payment_status_description']);
  } else if ('on-hold' == $order->status && TRUE == $order_payment_info['amount_discrepancy']) {
    $this->feedback_message = 'Your payment was successful. '
      . 'However there was a discrepancy in the amount paid.'
      . '<br/>The order amount is <strong>NGN' . number_format($order->get_order_total(), 2) . '</strong>'
      . '<br/>while the actual amount paid is <strong>NGN' . number_format(end($order_payment_info['amount']), 2) . '</strong>'
      . '<br/> A sales person has already been notified of this.<br/>'
      . '<br/>Below are the details of your payment transaction:'
      . '<br/><strong>Transaction reference:</strong> ' . end($order_payment_info['merch_txnref'])
      . '<br/><strong>Customer name:</strong> ' . end($order_payment_info['names'])
      . '<br/><strong>Amount paid:</strong> '
        . number_format(end($order_payment_info['amount']), 2)
      . '<br/><strong>Currency:</strong> ' . end($order_payment_info['currency'])
      . '<br/><strong>Payment Channel:</strong> ' . end($order_payment_info['channel'])
      . '<br/><strong>GlobalPay reference:</strong> ' . end($order_payment_info['txnref'])
      . '<br/><strong>Transaction status description:</strong> ' . end($order_payment_info['payment_status_description']);
  }

  echo wpautop($this->feedback_message);
}

function process_payment($order_id) {
  $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 receipt_page( $order ) {
  echo '<p>'.__('Thank you for your order, please click the button below to pay with GlobalPay.', 'woocommerce').'</p>';
  
  echo $this->generate_globalpay_form( $order );[/php]

Well, this is very complicated. First, you are a newbie to PHP. Next, this is a service being Wordpress template which means that you have two levels of knowledge needed. First, PHP and then how that interacts with Wordpress. Also, you need to know the current Wordpress template in depth to fix errors in it. This is the “WooCommerce” template.

So, first error note was on line 355. But, that is just the function for displaying a thank-you notice.
That is not where the error is. The error was the first two lines:
Transaction Failed: and Unfortunately… etc…

You need to find that text inside either your code or the template code to see where or why these two lines were printed. In THAT area, you should see what data is not in place and that might steer you to the real error which may be on the bank/merchant code system. (That code may be passing back the wrong data to your code.)

Hope that gets you started. Without full access to all your code, it would be hard for us to fix it for you.
But, start with wherever the “Transaction Failed:” line is displayed… Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service