From: senator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Tue, 6 Jul 2010 19:06:56 +0000 (+0000)
Subject: CC payments: address situations where Business::CreditCard::validate() returns
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2e85f82d1046ea15a7d488b1f8d730969c490958;p=evergreen%2Ftadl.git

CC payments: address situations where Business::CreditCard::validate() returns
true yet Business::CreditCard::cardtype() returns the string "Unknown"

Curse you inconsistent APIs! :-)


git-svn-id: svn://svn.open-ils.org/ILS/trunk@16857 dcc99617-32d9-48b4-a31d-7c20da2025e4
---

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm
index d2e4c0a43d..01360e07d9 100644
--- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm
+++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm
@@ -231,7 +231,15 @@ sub dispatch {
     #   a payment processor, nor that
     # b) it is even necessary to supply this argument to processors in all
     #   cases.  Testing this with several processors would be a good idea.
-    (my $cardtype = cardtype($argshash->{cc})) =~ s/ card//;
+    (my $cardtype = cardtype($argshash->{cc})) =~ s/ card//i;
+
+    if (lc($cardtype) eq "unknown") {
+        $logger->info("Credit card number passed validate(), " .
+            "yet cardtype() returned $cardtype");
+        return new OpenILS::Event(
+            "CREDIT_PROCESSOR_INVALID_CC_NUMBER", "note" => "cardtype $cardtype"
+        );
+    }
 
     $logger->debug(
         "applying payment via processor '" . $argshash->{processor} . "'"
@@ -249,7 +257,10 @@ sub dispatch {
     );
 
     $transaction->content(prepare_bop_content($argshash, $patron, $cardtype));
-    $transaction->submit();
+
+    # XXX submit() does not return a value, although crashing is possible here
+    # with some bad input depending on the payment processor.
+    $transaction->submit;
 
     my $payload = {
         "processor" => $argshash->{"processor"},