VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: EsSa55 on September 18, 2019, 10:17:24 AM

Title: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: EsSa55 on September 18, 2019, 10:17:24 AM
TIA


PHP 7.2.22
JM   3.9.11
VM  3.6.1.10144


PHP Warning:  A non-numeric value encountered in /public_html/administrator/components/com_virtuemart/helpers/creditcard.php on line 133


96   static function mod10($card_number) {      
97         
98      $digit_array = array();   
99      $cnt = 0;   
100         
101      //Reverse the card number   
102      $card_temp = strrev($card_number);   
103         
104      //Multiple every other number by 2 then ( even placement )   
105      //Add the digits and place in an array   
106      for ($i = 1; $i <= strlen($card_temp) - 1; $i = $i + 2) {   
107         //multiply every other digit by 2
108         $t = substr($card_temp, $i, 1);
109         $t = $t * 2;
110         //if there are more than one digit in the
111         //result of multipling by two ex: 7 * 2 = 14
112         //then add the two digits together ex: 1 + 4 = 5
113         if (strlen($t) > 1) {
114         
115         
116         
117         
118         
119         
120         
121         
122         } else { // result of (* 2) is only one digit long
123         
124         }
125         //place the result in an array for later
126         //adding to the odd digits in the credit card number
127         $digit_array [$cnt++] = $tmp;
128      }   
129      $tmp = 0;   
130         
131      //Add the numbers not doubled earlier ( odd placement )   
132      for ($i = 0; $i <= strlen($card_temp); $i = $i + 2) {   
133         $tmp = substr($card_temp, $i, 1) + $tmp;
134      }   
135         
136      //Add the earlier doubled and digit-added numbers to the result   
137      $result = $tmp + array_sum($digit_array);   
138         
139      //Check to make sure that the remainder   
140      //of dividing by 10 is 0 by using the modulas   
141      //operator   
142      return ($result % 10 == 0);   
143   }      
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: stemithy on September 30, 2019, 18:28:09 PM
Exact same issue and versions here.  For me it results in the user being stuck in a loop between the cart checkout screen and the enter credit card screen.  It shows that it retained the payment information but won't complete the transaction.

Thanks,
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: GJC Web Design on September 30, 2019, 19:20:40 PM
try to debug what is parsed there

e.g. add after line 132

print 'Debug Line '.__LINE__.' substr($card_temp, $i, 1) <pre>'; print_r (substr($card_temp, $i, 1)); print "</pre><br />\n";

then die(); after line 134

all numeric? no blanks? etc
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: ssc3 on September 30, 2019, 23:44:19 PM
For users of the PayPal Pro plugin from Virtuemart Extensions there was an update released last week to address this issue.

PHP 7.2 seems to be giving out a warning message ignored by earlier versions.

However in this case the warning message had no effect on the processing of the order.

If using our plugin use the update link at the top of the page in the PayPal Pro plugin setup.

The latest version is also working correctly in VM 3.6.x
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: stemithy on October 01, 2019, 15:41:34 PM
I'm having the issue using the Authorize.net plugin.
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: ssc3 on October 01, 2019, 21:00:33 PM
Quote from: stemithy on October 01, 2019, 15:41:34 PM
I'm having the issue using the Authorize.net plugin.

The native Authorize.Net plugin is currently broke in 3.6.1 and 3.6.2 and orders can not be processed.

The Authorize.Net Accept plugin from Virtuemart Extensions is still working in 3.6.1 and 3.6.2
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: Milbo on October 02, 2019, 08:57:21 AM
Quote from: ssc3 on October 01, 2019, 21:00:33 PM
The native Authorize.Net plugin is currently broke in 3.6.1 and 3.6.2 and orders can not be processed.

What is broken? Should work.
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: Milbo on October 02, 2019, 08:58:00 AM
Quote from: ssc3 on September 30, 2019, 23:44:19 PM
PHP 7.2 seems to be giving out a warning message ignored by earlier versions.

However in this case the warning message had no effect on the processing of the order.

What should be changed? So that the file is working "clean" again.
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: ssc3 on October 02, 2019, 09:19:33 AM
Quote from: Milbo on October 02, 2019, 08:57:21 AM
Quote from: ssc3 on October 01, 2019, 21:00:33 PM
The native Authorize.Net plugin is currently broke in 3.6.1 and 3.6.2 and orders can not be processed.

What is broken? Should work.

http://forum.virtuemart.net/index.php?topic=143438.0

Still using old code.
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: ssc3 on October 02, 2019, 09:32:22 AM
Quote from: Milbo on October 02, 2019, 08:58:00 AM
What should be changed? So that the file is working "clean" again.


131      //Add the numbers not doubled earlier ( odd placement )   
132      for ($i = 0; $i <= strlen($card_temp); $i = $i + 2) {   
133         $tmp = substr($card_temp, $i, 1) + $tmp;
134      } 


as far as i can tell this is making one loop too many.

but a none too subtle fix.


//Add the numbers not doubled earlier ( odd placement )
for ($i = 0; $i <= strlen($card_temp); $i = $i + 2) {

$sub = substr($card_temp, $i, 1);

//echo "*$sub#";
//echo is_numeric($sub);

if(is_numeric($sub))
{
$tmp = $sub + $tmp;
}
}

Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: Milbo on October 02, 2019, 10:41:21 AM
or maybe

for ($i = 0; $i < (strlen($card_temp)); $i = $i + 2) {


Of course it runs to far, because we have $i+2, or? So either length -1 or lets remove the =
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: Milbo on October 02, 2019, 12:29:54 PM
I will replace it by


//Add the numbers not doubled earlier ( odd placement )
$l = strlen($card_temp);
for ($i = 0; $i < $l; $i = $i + 2) {
$tmp = substr($card_temp, $i, 1) + $tmp;
}
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: ssc3 on October 02, 2019, 12:39:19 PM
I was thinking about trying

for ($i = 0; $i < strlen($card_temp); $i = $i + 2)

but the original code on which this based was first written in 2002, according to the copyright. I was a little reluctant to change something that had been "working" since then.

The code I used for debugging which filtered the non numberic values also worked, so I just left that in place.
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: ssc3 on October 02, 2019, 12:55:33 PM
Quote from: Milbo on October 02, 2019, 12:29:54 PM

//Add the numbers not doubled earlier ( odd placement )
$l = strlen($card_temp);
for ($i = 0; $i < $l; $i = $i + 2) {
$tmp = substr($card_temp, $i, 1) + $tmp;
}


Works as far as I can tell.

Both odd and even digit credit card numbers. Amex and Visa tested
Title: Re: PHP Warning: A non-numeric value encountered in creditcard.php
Post by: Milbo on October 02, 2019, 19:15:33 PM
yeh I tested it in my "play" view, which is just there to test snippets. I tested it with 12345678 and 123..89