CC payments: address situations where Business::CreditCard::validate() returns
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 6 Jul 2010 19:06:56 +0000 (19:06 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 6 Jul 2010 19:06:56 +0000 (19:06 +0000)
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

Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm

index d2e4c0a..01360e0 100644 (file)
@@ -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"},