Forums / Addon Payment Modules / nab_transact payment module has php error when installing to fresh install of zencart

nab_transact payment module has php error when installing to fresh install of zencart

Views: 2,819

Results 1 to 17 of 17
23 Sep 2020, 12:47 AM
#1
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

nab_transact payment module has php error when installing to fresh install of zencart

Hi,
I'm doing a fresh install of a zencart 1.5.7 , php version 7.0 and I've copied the files over for the NAB_transact payment module. I've used this module before for earlier versions of zencart; however this time the module is giving me the following PHP error.

PHP Parse error: syntax error, unexpected '[', expecting ',' or ';'
in "myadress"/includes/modules/payment/nab_transact_hpp.php on line 304

/myshop/admin/index.php?cmd=modules&set=payment, IP address: my ip
--> PHP Parse error: syntax error, unexpected '[', expecting ',' or ';' in "myaddress/includes/modules/payment/nab_transact_hpp.php on line 304.

I think line 304 is this.
global $$order_totals[$i]['code'];

Not knowing much about PHP I need some one to tell me what this line should be. In the past I was using PHP5.6 so I expect its got something to do with changes in the PHP version.

23 Sep 2020, 12:57 AM
#2
raptar avatar

raptar

New Zenner

Join Date:
Jan 2019
Location:
New Zealand
Posts:
38
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

Hi p1drobert2

Changes to Php 7+ requires it to be wrapped in curly braces like this.```html
global ${$order_totals[$i]['code']};


Regards raptar
23 Sep 2020, 1:25 AM
#3
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

Thank you very much. That's fixed the problem.

someone should update the Nab_transact module to reflect this.

Edit> although I'm now getting a configuration error. Am investigating.

23 Sep 2020, 1:52 AM
#4
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

When installing the NAB_transact module with the above fix it reports a configuration error.
Despite that the module seems to work any way. A test order was placed and payment through NAB occurred.

The error in my logs shows the following? Is this an issue that needs looking at? or can I ignore it.

Request URI: /admin/index.php?cmd=modules&set=payment&module=nab_transact_hpp&action=edit, IP address: myip
#1 include() called at [/admin/modules.php:201]
#2 require(admin/modules.php) called at [admin/index.php:11]
--> PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; nab_transact_hpp has a deprecated constructor in /myshop/includes/modules/payment/nab_transact_hpp.php on line 41.

23 Sep 2020, 2:05 AM
#5
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

line 41 is

class nab_transact_hpp {

the full paragraph is this.

class nab_transact_hpp {
//$code-internal code for this payment module
var $code;
//$title contains name of this module
var $title;
//$description-description of the payment module
var $description;
//$enabled is a boolean flag which indicates is this payment options should be presented to the customer
var $enabled;

23 Sep 2020, 2:46 AM
#6
raptar avatar

raptar

New Zenner

Join Date:
Jan 2019
Location:
New Zealand
Posts:
38
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

Hi p1drobert2

I believe you will have to change the line of code where it reads "function nab_transact_hpp {}" to "function __construct {}" at about line 56. Don't add the quotes...

Regards raptar

23 Sep 2020, 2:53 AM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: nab_transact payment module has php error when installing to fresh install of zencart

What it appears to be reporting is that later on down you may see:

function nab_transact_hpp(

I've ended the above just after the opening parentheses because I don't know what is "supposed" to follow.

Generally the above line could and should be changed to

function __construct(

Pretty much as of at least php 5.2. I haven't done a fact check to be able to with surety say that it was possible before then. There are exceptions to making that basic change, but usually requires either searching through the code to see if there is an instance of: ->nab_transact_hpp or some other similar code and then evaluating that code further...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

24 Sep 2020, 1:11 AM
#8
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

Thank you mc12345678 and raptar for your help.

I'll make the changes and will see what happens.

25 Sep 2020, 11:22 PM
#9
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

I'm still having issues with this module. Having made the above changes it fixed the listed errors generated above but its introduced some sort of callback error when coming back from the NAB bank site. The order is created in zencart but the cart remains with the products still listed, and the products are not shown in the order. An order confirmation email is not sent from zencart.
Unfortunately the original creator of this module is long gone and uncontactable.

The logs show this.

#1 trigger_error() called at [myaddress/includes/classes/db/mysql/query_factory.php:170]
#2 queryFactory->show_error() called at [myaddress/includes/classes/db/mysql/query_factory.php:142]
#3 queryFactory->set_error() called at [myaddress/includes/classes/db/mysql/query_factory.php:269]
#4 queryFactory->Execute() called at [myaddress/includes/functions/database.php:44]
#5 zen_db_perform() called at [myaddress/includes/modules/payment/nab_transact_hpp.php:444]
#6 nab_transact_hpp->after_order_create() called at [myaddress/includes/classes/payment.php:270]
#7 payment->after_order_create() called at myaddress/includes/modules/checkout_process.php:96]
#8 require(myaddress/includes/modules/checkout_process.php) called at myaddress/includes/modules/pages/checkout_process/header_php.php:14]
#9 require(myaddress/includes/modules/pages/checkout_process/header_php.php) called at [myaddress/index.php:35]

--> PHP Fatal error: 1366:Incorrect integer value: 'after_order_create' for column 'orders_id' at row 1 :: INSERT INTO orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) VALUES ('after_order_create', '1', now(), '0', 'Payment Information\nPayment Status: PAID IN FULL (LIVE PAYMENT)\nAmount Paid: 1.10\nCard Type: VISA\nNAB Transact Payment Reference#: 1-mydatashown\nBank Reference#: xxxxxx\n') ==> (as called by) myaddress/includes/functions/database.php on line 44 <== in myaddress/includes/classes/db/mysql/query_factory.php on line 170.

Unfortunately I can't seem to pin point a particular line in the nab_transact_hpp.php that's causing the issue. Anyone out there with the knowledge to figure this out?

26 Sep 2020, 10:43 AM
#10
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,110
Plugin Contributions:
56

Re: nab_transact payment module has php error when installing to fresh install of zencart

p1drobert2:

I'm still having issues with this module. Having made the above changes it fixed the listed errors generated above but its introduced some sort of callback error when coming back from the NAB bank site. The order is created in zencart but the cart remains with the products still listed, and the products are not shown in the order. An order confirmation email is not sent from zencart.
Unfortunately the original creator of this module is long gone and uncontactable.

The logs show this.

#1 trigger_error() called at [myaddress/includes/classes/db/mysql/query_factory.php:170]
#2 queryFactory->show_error() called at [myaddress/includes/classes/db/mysql/query_factory.php:142]
#3 queryFactory->set_error() called at [myaddress/includes/classes/db/mysql/query_factory.php:269]
#4 queryFactory->Execute() called at [myaddress/includes/functions/database.php:44]
#5 zen_db_perform() called at [myaddress/includes/modules/payment/nab_transact_hpp.php:444]
#6 nab_transact_hpp->after_order_create() called at [myaddress/includes/classes/payment.php:270]
#7 payment->after_order_create() called at myaddress/includes/modules/checkout_process.php:96]
#8 require(myaddress/includes/modules/checkout_process.php) called at myaddress/includes/modules/pages/checkout_process/header_php.php:14]
#9 require(myaddress/includes/modules/pages/checkout_process/header_php.php) called at [myaddress/index.php:35]

--> PHP Fatal error: 1366:Incorrect integer value: 'after_order_create' for column 'orders_id' at row 1 :: INSERT INTO orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) VALUES ('after_order_create', '1', now(), '0', 'Payment Information\nPayment Status: PAID IN FULL (LIVE PAYMENT)\nAmount Paid: 1.10\nCard Type: VISA\nNAB Transact Payment Reference#: 1-mydatashown\nBank Reference#: xxxxxx\n') ==> (as called by) myaddress/includes/functions/database.php on line 44 <== in myaddress/includes/classes/db/mysql/query_factory.php on line 170.

Unfortunately I can't seem to pin point a particular line in the nab_transact_hpp.php that's causing the issue. Anyone out there with the knowledge to figure this out?
The payment module is attempting to 'stuff' that character string (after_order_create) into an integer-field (orders_id). That's occurring with code on/around line 444 of /includes/modules/payment/nab_transact_hpp.php.

27 Sep 2020, 12:52 AM
#11
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

Thank you LAT9 for your answer.

I don't have a proper PHP file viewer but notepad indicates line 444 should be inside the code shown on the bottom of this post. Now, so far, I've been updating the file to fix errors caused by going from php5.6 to PHP7.
So far I changed
function nab_transact_hpp(
to
function __construct(

and
global $$order_totals[$i]['code'];
to
global ${$order_totals[$i]['code']};

which fixed warnings and errors, thanks to the help of users above. Since this module worked in zencart versions 1.5.6, using PHP5.6 I'm assuming there's either something in zencart 1.5.7 or changes in php7 that is causing this following sections of code to misbehave now. I've recently had a new geotrust SSL certificate installed on my web site but since the NAB servers has processed the payment and returned to my site I'm assuming its not a SSL issue.
Unfortunately I have no real PHP knowledge. Can anyone quickly glance through the following code and see why the error is occurring, in particular why a string should now be getting written to a variable that only accepts integers? More importantly how I should rewrite it to fix it.

/**

  • This function is called after the order has been created
  • @param int $order_id
    */
    function after_order_create($order_id) {
    global $order, $amount_paid;
$customer_ip = $_SESSION['customer_ip'];
//Write the payment specific values to the order history
if ($_SERVER['REMOTE_ADDR'] != $customer_ip || empty($customer_ip)){
    $order_status = $order->info['order_status'];
    $payment_status = 'NOT PAID/PARTIALLY PAID';
    //If the full amount has been paid update the order status
    //otherwise leave the status as it is
    if (round((float)$order->info['total'],2) == round((float)$amount_paid, 2)) {
      if (MODULE_PAYMENT_NAB_TRANSACT_HPP_ORDER_STATUS_ID > 0) {
        $order_status = MODULE_PAYMENT_NAB_TRANSACT_HPP_ORDER_STATUS_ID;
      }
      $payment_status = 'PAID IN FULL';
    }
    $sql_data_array = array(
      'orders_id' => $order_id, 
      'orders_status_id' => $order_status, 
      'date_added' => 'now()', 
      'customer_notified' => 0, 
      'comments' =>
        '***'.MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_HEADING.'***'.chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_STATUS.': '.$payment_status.' ('.strtoupper($this->in_test_mode() ? MODULE_PAYMENT_NAB_TRANSACT_CONST_TEST : MODULE_PAYMENT_NAB_TRANSACT_CONST_LIVE).' PAYMENT)'.chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_AMOUNT.': '.$amount_paid.chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_CARD.': '.urldecode($_GET[MODULE_PAYMENT_NAB_TRANSACT_QS_PARAM_NAME_CARD_TYPE]).chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_TXN_REF.'#: '.$_SESSION['nt_hpp_payment_reference'].':'.urldecode($_GET[MODULE_PAYMENT_NAB_TRANSACT_QS_PARAM_NAME_REF_NUM]).chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_BANK_REF.'#: '.urldecode($_GET[MODULE_PAYMENT_NAB_TRANSACT_QS_PARAM_NAME_BANK_REF]).chr(10)
      );
    zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
    //unregister the session variables
    unset($_SESSION['nt_hpp_payment_reference']);
    unset($_SESSION['customer_ip']);
} else {
  zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . MODULE_PAYMENT_NAB_TRANSACT_ERR_UNAUTH_CHECKOUT_CALL, 'NONSSL'));
}
return true;

}

function after_process() {
global $insert_id, $db;
}

27 Sep 2020, 5:43 AM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: nab_transact payment module has php error when installing to fresh install of zencart

p1drobert2:

I don't have a proper PHP file viewer but notepad ...

Stop everything and install one of:

  • Visual Studio Code
  • Notepad++

or another from this list:
https://docs.zen-cart.com/user/first_steps/useful_tools/

There's no reason not to install a suitable text editor. It'll make your life way easier.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

27 Sep 2020, 12:07 PM
#13
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,110
Plugin Contributions:
56

Re: nab_transact payment module has php error when installing to fresh install of zencart

p1drobert2:

Thank you LAT9 for your answer.

I don't have a proper PHP file viewer but notepad indicates line 444 should be inside the code shown on the bottom of this post. Now, so far, I've been updating the file to fix errors caused by going from php5.6 to PHP7.
So far I changed
function nab_transact_hpp(
to
function __construct(

and
global $$order_totals[$i]['code'];
to
global ${$order_totals[$i]['code']};

which fixed warnings and errors, thanks to the help of users above. Since this module worked in zencart versions 1.5.6, using PHP5.6 I'm assuming there's either something in zencart 1.5.7 or changes in php7 that is causing this following sections of code to misbehave now. I've recently had a new geotrust SSL certificate installed on my web site but since the NAB servers has processed the payment and returned to my site I'm assuming its not a SSL issue.
Unfortunately I have no real PHP knowledge. Can anyone quickly glance through the following code and see why the error is occurring, in particular why a string should now be getting written to a variable that only accepts integers? More importantly how I should rewrite it to fix it.

/**

  • This function is called after the order has been created
  • @param int $order_id
    */
    function after_order_create($order_id) {
    global $order, $amount_paid;
$customer_ip = $_SESSION['customer_ip'];
//Write the payment specific values to the order history
if ($_SERVER['REMOTE_ADDR'] != $customer_ip || empty($customer_ip)){
    $order_status = $order->info['order_status'];
    $payment_status = 'NOT PAID/PARTIALLY PAID';
    //If the full amount has been paid update the order status
    //otherwise leave the status as it is
    if (round((float)$order->info['total'],2) == round((float)$amount_paid, 2)) {
      if (MODULE_PAYMENT_NAB_TRANSACT_HPP_ORDER_STATUS_ID > 0) {
        $order_status = MODULE_PAYMENT_NAB_TRANSACT_HPP_ORDER_STATUS_ID;
      }
      $payment_status = 'PAID IN FULL';
    }
    $sql_data_array = array(
      'orders_id' => $order_id, 
      'orders_status_id' => $order_status, 
      'date_added' => 'now()', 
      'customer_notified' => 0, 
      'comments' =>
        '***'.MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_HEADING.'***'.chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_STATUS.': '.$payment_status.' ('.strtoupper($this->in_test_mode() ? MODULE_PAYMENT_NAB_TRANSACT_CONST_TEST : MODULE_PAYMENT_NAB_TRANSACT_CONST_LIVE).' PAYMENT)'.chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_AMOUNT.': '.$amount_paid.chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_CARD.': '.urldecode($_GET[MODULE_PAYMENT_NAB_TRANSACT_QS_PARAM_NAME_CARD_TYPE]).chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_TXN_REF.'#: '.$_SESSION['nt_hpp_payment_reference'].':'.urldecode($_GET[MODULE_PAYMENT_NAB_TRANSACT_QS_PARAM_NAME_REF_NUM]).chr(10).
        MODULE_PAYMENT_NAB_TRANSACT_HPP_PAY_INFO_BANK_REF.'#: '.urldecode($_GET[MODULE_PAYMENT_NAB_TRANSACT_QS_PARAM_NAME_BANK_REF]).chr(10)
      );
    zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
    //unregister the session variables
    unset($_SESSION['nt_hpp_payment_reference']);
    unset($_SESSION['customer_ip']);
} else {
  zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . MODULE_PAYMENT_NAB_TRANSACT_ERR_UNAUTH_CHECKOUT_CALL, 'NONSSL'));
}
return true;

}

function after_process() {
global $insert_id, $db;
}
Ah, that's due to a zc157-introduced bug whose correction is identified here: https://www.zen-cart.com/showthread.php?226872-Known-bugs-%28and-fixes%29-for-v1-5-7-series&p=1371437#post1371437.

You should really review and apply all those zc157 bugfixes (https://www.zen-cart.com/showthread.php?226872-Known-bugs-%28and-fixes%29-for-v1-5-7-series%29 to be sure that your site's on a solid footing.

28 Sep 2020, 12:35 AM
#14
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

lat9:

Ah, that's due to a zc157-introduced bug whose correction is identified here: https://www.zen-cart.com/showthread.php?226872-Known-bugs-%28and-fixes%29-for-v1-5-7-series&p=1371437#post1371437.

You should really review and apply all those zc157 bugfixes (https://www.zen-cart.com/showthread.php?226872-Known-bugs-%28and-fixes%29-for-v1-5-7-series%29 to be sure that your site's on a solid footing.

Allaluya!!!! Thank you very much Lat9, I can finally get my shopping cart back on line weeks after I got hacked.
Now all I need to worry about are hackers.
I didn't realize there was a section for bug fixes. I always assumed that any bug fix would immediately go into the latest version ready for download. Will have to log into this forum more regularly I think.

28 Sep 2020, 12:38 AM
#15
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

DrByte:

Stop everything and install one of:

  • Visual Studio Code
  • Notepad++

or another from this list:
https://docs.zen-cart.com/user/first_steps/useful_tools/

There's no reason not to install a suitable text editor. It'll make your life way easier.

Thank you Drbyte. I've downloaded NOTEPAD++, very nice improvement over notepad.

28 Sep 2020, 12:43 AM
#16
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,848
Plugin Contributions:
17

Re: nab_transact payment module has php error when installing to fresh install of zencart

p1drobert2:

I didn't realize there was a section for bug fixes. I always assumed that any bug fix would immediately go into the latest version ready for download. Will have to log into this forum more regularly I think.
When you check out the fixes thread, be sure to subscribe (under Thread Tools). Then it will notify you of any new posts.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

28 Sep 2020, 1:18 AM
#17
p1drobert2 avatar

p1drobert2

New Zenner

Join Date:
Feb 2019
Location:
Melbourne Australia
Posts:
61
Plugin Contributions:
0

Re: nab_transact payment module has php error when installing to fresh install of zencart

dbltoe:

When you check out the fixes thread, be sure to subscribe (under Thread Tools). Then it will notify you of any new posts.

thank you. I did not notice that before. Good tip.