Katie Horn has submitted this change and it was merged.

Change subject: Next Attempt at a Luhn Algorithm
......................................................................


Next Attempt at a Luhn Algorithm

I have no idea why this works and the other implementation
doesn't. But it does... apparently. At least on my CC.

Change-Id: I1ed0b224bd129f7b5ed6092cf66c8104f3c39686
---
M gateway_common/DataValidator.php
1 file changed, 9 insertions(+), 7 deletions(-)

Approvals:
  Katie Horn: Verified; Looks good to me, approved



diff --git a/gateway_common/DataValidator.php b/gateway_common/DataValidator.php
index 3a8fc62..1301028 100644
--- a/gateway_common/DataValidator.php
+++ b/gateway_common/DataValidator.php
@@ -788,15 +788,17 @@
                $sum = 0;
 
                for( $i = 0; $i < strlen( $str ); $i++ ) {
-                       $n = 0 + $str[$i];
-                       $odd = !$odd;
-
-                       if( $odd ) {
-                               $sum += $n;
+                       if ( $odd ) {
+                               $sum += $str[$i];
                        } else {
-                               $x = 2 * $n;
-                               $sum += ($x > 9) ? ($x - 9) : $x;
+                               if (( $str[$i] * 2 ) > 9 ) {
+                                       $sum += $str[$i] * 2 - 9;
+                               } else {
+                                       $sum += $str[$i] * 2;
+                               }
                        }
+
+                       $odd = !$odd;
                }
                return( ( $sum % 10 ) == 0 );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/54606
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1ed0b224bd129f7b5ed6092cf66c8104f3c39686
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to