[open-ils-commits] r16680 - in trunk/Open-ILS/src: extras perlmods/OpenILS/Application/Circ (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Jun 11 12:18:38 EDT 2010


Author: senator
Date: 2010-06-11 12:18:35 -0400 (Fri, 11 Jun 2010)
New Revision: 16680

Modified:
   trunk/Open-ILS/src/extras/ils_events.xml
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm
Log:
Improve the way information from payment card processors bubbles up to
callers of open-ils.circ.money.payment

This is done by replacing unneeded, weird data structures with ilsevents and
filling those events' payloads with result data from the processor.


Modified: trunk/Open-ILS/src/extras/ils_events.xml
===================================================================
--- trunk/Open-ILS/src/extras/ils_events.xml	2010-06-11 15:16:34 UTC (rev 16679)
+++ trunk/Open-ILS/src/extras/ils_events.xml	2010-06-11 16:18:35 UTC (rev 16680)
@@ -768,6 +768,9 @@
 	<event code='4010' textcode='CREDIT_PROCESSOR_NO_DEFAULT_SELECTED'>
 		<desc xml:lang="en-US">No default credit processor is selected</desc>
 	</event>
+	<event code='4019' textcode='CREDIT_PROCESSOR_INVALID_CC_NUMBER'>
+		<desc xml:lang="en-US">An invalid credit card number has been supplied.</desc>
+	</event>
 	<event code='4020' textcode='CREDIT_PROCESSOR_DECLINED_TRANSACTION'>
 		<desc xml:lang="en-US">The credit card processor has declined the transaction.</desc>
 	</event>

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm	2010-06-11 15:16:34 UTC (rev 16679)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm	2010-06-11 16:18:35 UTC (rev 16680)
@@ -100,7 +100,7 @@
 #              description: optional
 #                /, type => 'hash' }
 #        ],
-#        return => { desc => 'Hash of status information', type =>'hash' }
+#        return => { desc => 'an ilsevent' }
 #    }
 
 sub process_payment {
@@ -221,15 +221,9 @@
     if (!validate($argshash->{cc})) {
         # Although it might help a troubleshooter, it's probably not a good
         # idea to put the credit card number in the log file.
-        $logger->warn("Credit card number invalid");
+        $logger->info("Credit card number invalid");
 
-        # The idea of returning a hashref with statusText and statusCode
-        # comes from an older version handle_authorizenet(), but I'm not
-        # sure it's the best thing to do, really.
-        return {
-            statusText => "Credit card number invalid",
-            statusCode => 500
-        };
+        return new OpenILS::Event("CREDIT_PROCESSOR_INVALID_CC_NUMBER");
     }
 
     # cardtype() also comes from Business::CreditCard.  It is not certain that
@@ -257,38 +251,30 @@
     $transaction->content(prepare_bop_content($argshash, $patron, $cardtype));
     $transaction->submit();
 
-    # The data structures that we return based on success or failure are still
-    # basically from earlier code.  These might should be improved/reduced.
-    if ($transaction->is_success()) {
-        $logger->info($argshash->{processor} . " payment succeeded");
+    my $payload = {
+        "processor" => $argshash->{"processor"},
+        "card_type" => $cardtype,
+        "server_response" => $transaction->server_response
+    };
 
-        my $retval = {
-            statusText => "Transaction approved: " . $transaction->authorization,
-            processor => $argshash->{processor},
-            cardType => $cardtype,
-            statusCode => 200,
-            approvalCode => $transaction->authorization,
-            server_response => $transaction->server_response
-        };
-
-        # These result fields may be important in PayPal xactions? Not sure.
-        foreach (qw/correlationid avs_code cvv2_code/) {
-            if ($transaction->can($_)) {
-                $retval->{$_} = $transaction->$_;
-            }
-        }
-        return $retval;
+    foreach (qw/authorization correlationid avs_code cvv2_code error_message/) {
+        # authorization should always be present for successes, and
+        # error_message should always be present for failures. The remaining
+        # field may be important in PayPal transacations? Not sure.
+        $payload->{$_} = $transaction->$_ if $transaction->can($_);
     }
-    else {
+
+    my $event_name;
+
+    if ($transaction->is_success()) {
+        $logger->info($argshash->{processor} . " payment succeeded");
+        $event_name = "SUCCESS";
+    } else {
         $logger->info($argshash->{processor} . " payment failed");
-        return {
-            statusText => "Transaction declined: " . $transaction->error_message,
-            statusCode => 500,
-            errorMessage => $transaction->error_message,
-            server_response => $transaction->server_response
-        };
+        $event_name = "CREDIT_PROCESSOR_DECLINED_TRANSACTION";
     }
 
+    return new OpenILS::Event($event_name, "payload" => $payload);
 }
 
 

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm	2010-06-11 15:16:34 UTC (rev 16679)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm	2010-06-11 16:18:35 UTC (rev 16680)
@@ -250,28 +250,23 @@
                     "zip" => $cc_args->{billing_zip},
                 });
 
-            if (exists $response->{ilsevent}) {
+            if ($U->event_code($response)) { # non-success
                 $logger->info(
-                    "event response from process_payment(): " .
-                    $response->{"textcode"}
+                    "Credit card payment for user $user_id failed: " .
+                    $response->{"textcode"} . " " .
+                    $response->{"payload"}->{"error_message"}
                 );
+
                 return $response;
-            }
-            if ($response->{statusCode} != 200) {
-                $logger->info("Credit card payment for user $user_id " .
-                    "failed with message: " . $response->{statusText});
-                return OpenILS::Event->new(
-                    'CREDIT_PROCESSOR_DECLINED_TRANSACTION',
-                    note => $response->{statusText}
+            } else {
+                $approval_code = $response->{"payload"}->{"authorization"};
+                $cc_type = $response->{"payload"}->{"card_type"};
+                $cc_processor = $response->{"payload"}->{"processor"};
+                $logger->info(
+                    "Credit card payment for user $user_id succeeded"
                 );
             }
-            $approval_code = $response->{approvalCode};
-            $cc_type = $response->{cardType};
-            $cc_processor = $response->{processor};
-            $logger->info("Credit card payment processing for " .
-                "user $user_id succeeded");
-        }
-        else {
+        } else {
             return OpenILS::Event->new(
                 'BAD_PARAMS', note => 'Need approval code'
             ) if not $cc_args->{approval_code};



More information about the open-ils-commits mailing list