Enable retrieval of fraud transaction score and transaction ID, B:OP and B:FD:preChar...
authorivan <ivan>
Wed, 13 Jun 2007 23:02:59 +0000 (23:02 +0000)
committerivan <ivan>
Wed, 13 Jun 2007 23:02:59 +0000 (23:02 +0000)
Changes
FraudDetect.pm
FraudDetect/preCharge.pm
OnlinePayment.pm

diff --git a/Changes b/Changes
index 57af63c..3afc308 100644 (file)
--- a/Changes
+++ b/Changes
@@ -4,6 +4,8 @@ Revision history for Perl extension Business::OnlinePayment.
         - B:OP:HTTPS: set response_page, response_code, response_headers
         - B:OP: defined &$class is not how you detect if a class has been loaded
           (just using use should be fine).  Closes: CPAN#22071
+        - Enable retrieval of fraud transaction score and transaction ID,
+          B:OP and B:FD:preCharge patch from Jason Hall, thanks!
 
 3.00_07  Fri Mar 23 14:54:57 PDT 2007
        - B:OP:HTTPS request headers now work with Crypt::SSLeay too.
index d624f3c..c193239 100644 (file)
@@ -70,7 +70,10 @@ submit method to interpose an additional Fraud Detection phase.
 
 =head1 AUTHORS
 
-Lawrence Statton <lawrence@cluon.com>
+Original author: Lawrence Statton <lawrence@cluon.com>
+
+Current maintainer: Ivan Kohler <ivan-bop@420.am> as part of the
+Business::OnlinePayment distribution.
 
 =head1 DISCLAIMER
 
@@ -78,6 +81,7 @@ THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
 
 =head1 SEE ALSO
 
-http://420.am/business-onlinepayment
+L<Business::OnlinePayment>, http://420.am/business-onlinepayment
+
 
 =cut
index aa8bcb3..310adfb 100644 (file)
@@ -1,15 +1,13 @@
-
 package Business::FraudDetect::preCharge;
 
 use strict;
 use Carp;
 use vars qw($VERSION @ISA);
-#use Data::Dumper;
-
 use Business::OnlinePayment::HTTPS;
-@ISA = qw / Business::OnlinePayment::HTTPS /;
 
-$VERSION = '0.01';
+@ISA = qw( Business::OnlinePayment::HTTPS );
+
+$VERSION = '0.02';
 
 sub _glean_parameters_from_parent {
     my ($self, $parent) = @_;
@@ -24,7 +22,7 @@ sub set_defaults {
     $self->port(443);
     $self->path('/charge');
     $self->build_subs(qw /currency fraud_score error_code
-                     precharge_id precharge_security1 precharge_security2 force_success / );
+                     precharge_id precharge_security1 precharge_security2 force_success fraud_transaction_id / );
     $self->currency('USD');
     return $self;
 }
@@ -47,21 +45,28 @@ sub submit {
                              ip_address
                              ));
 
-    $self->remap_fields( qw /
-                        ip_address             ecom_billto_online_ip 
-                        zip                    ecom_billto_postal_code 
-                        phone                  ecom_billto_telecom_phone_number 
-                        first_name             ecom_billto_postal_name_first
-                        last_name              ecom_billto_postal_name_last
-                        email                  ecom_billto_online_email 
-                        amount                 ecom_transaction_amount  /
-                        );
-
-
-    my %post_data = $self->get_fields(qw ( ecom_billto_online_ip ecom_billto_postal_code
-                                          ecom_billto_telecom_phone_number ecom_billto_online_email
-                                          ecom_transaction_amount currency
-                                          ));
+    $self->remap_fields( qw/
+                            ip_address         ecom_billto_online_ip 
+                            zip                ecom_billto_postal_postalcode 
+                            phone              ecom_billto_telecom_phone_number 
+                            first_name         ecom_billto_postal_name_first
+                            last_name          ecom_billto_postal_name_last
+                            email              ecom_billto_online_email 
+                            country            ecom_billto_postal_countrycode
+                            card_number        ecom_payment_card_number
+                            amount             ecom_transaction_amount
+                           /
+                       );
+
+
+    my %post_data = $self->get_fields(qw(
+      ecom_billto_online_ip ecom_billto_postal_postalcode
+      ecom_billto_telecom_phone_number ecom_billto_online_email
+      ecom_transaction_amount currency
+      ecom_billto_postal_name_first ecom_billto_postal_name_last
+      ecom_billto_postal_countrycode
+      ecom_payment_card_number
+    ));
 
     # set up some reasonable defaults
 
@@ -69,16 +74,20 @@ sub submit {
     # split out MM/YY from exp date
     #
 
-    @post_data{qw/ecom_payment_card_expdate_month ecom_payment_card_expdate_year/} = $content{expiration} =~ m/(\d{1,2})(\d{2})/;
-    @post_data{qw/merchant_id security_1 security_2/} = ($self->precharge_id,
-                                                        $self->precharge_security1,
-                                                        $self->precharge_security2);
+    @post_data{ qw/ ecom_payment_card_expdate_month
+                    ecom_payment_card_expdate_year
+                  /
+              } = split(/\//,$content{expiration});
+
+    @post_data{qw/merchant_id security_1 security_2/} = (
+      $self->precharge_id,
+      $self->precharge_security1,
+      $self->precharge_security2
+    );
 
     if ($self->test_transaction()) {
        $post_data{test} = 1;
     }
-
-#    warn Dumper \%post_data;
     my ($page, $response, %headers) = $self->https_post(\%post_data);
 
     $self->server_response($page);
@@ -132,24 +141,26 @@ sub submit {
     }
 
     if ($output{response} == 1 )  {
-       $self->is_success(1);
-       $self->fraud_score($output{score});
-       $self->result_code($output{response});
-       $self->error_message('No Error.  Risk assesment transaction successful');
+        $self->is_success(1);
+        $self->fraud_score($output{score});
+        $self->result_code($output{response});
+        $self->fraud_transaction_id($output{transaction});
+        $self->error_message('No Error.  Risk assesment transaction successful');
     } else {
-       $self->is_success(0);
-       $self->result_code($output{error});
-       $self->error_message(exists $error_map{$output{error}} ? $error_map{$output{error}} :  "preCharge error $output{error} occurred.");
+        $self->is_success(0);
+        $self->fraud_score($output{score});
+        $self->result_code($output{error});
+        $self->error_message( exists( $error_map{$output{error}} )
+                                ? $error_map{$output{error}}
+                                :  "preCharge error $output{error} occurred."
+                            );
     }
 }
 
 
-
-
 1;
 
 
-
 =pod
 
 =head1 NAME 
@@ -160,7 +171,7 @@ Business::FraudDetect::preCharge - backend for Business::FraudDetect (part of Bu
 
  use Business::OnlinePayment
  my $tx = new Business::OnlinePayment ( 'someGateway',
-                                        fruad_detection => 'preCharge',
+                                        fruad_detect => 'preCharge',
                                         maximum_fraud_score => 500,
                                         preCharge_id => '1000000000000001',
                                         preCharge_security1 => 'abcdef0123',
@@ -186,8 +197,12 @@ Business::FraudDetect::preCharge - backend for Business::FraudDetect (part of Bu
  $tx->submit();
  if ($tx->is_success()) {
     # successful charge
+    my $score = $tx->fraud_score;
+    my $id = $tx->fraud_transaction_id;
+       #returns the preCharge transaction id
  } else {
     # unsucessful 
+    my $score = $tx->fraud_score;
  }
 
 =head1 DESCRIPTION
@@ -227,6 +242,8 @@ This module provides no public methods.
 
 Lawrence Statton <lawrence@cluon.com>
 
+Jason Hall <jayce@lug-nut.com>
+
 =head1 DISCLAIMER
 
 THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
index 632c822..da75db4 100644 (file)
@@ -13,20 +13,22 @@ $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 my %Presubmit_Added = ();
 
 my %fields = (
-    authorization    => undef,
-    error_message    => undef,
-    failure_status   => undef,
-    fraud_detect     => undef,
-    is_success       => undef,
-    maximum_risk     => undef,
-    path             => undef,
-    port             => undef,
-    require_avs      => undef,
-    result_code      => undef,
-    server           => undef,
-    server_response  => undef,
-    test_transaction => undef,
-    transaction_type => undef,
+    authorization        => undef,
+    error_message        => undef,
+    failure_status       => undef,
+    fraud_detect         => undef,
+    is_success           => undef,
+    maximum_risk         => undef,
+    path                 => undef,
+    port                 => undef,
+    require_avs          => undef,
+    result_code          => undef,
+    server               => undef,
+    server_response      => undef,
+    test_transaction     => undef,
+    transaction_type     => undef,
+    fraud_score          => undef,
+    fraud_transaction_id => undef,
 );
 
 sub new {
@@ -78,6 +80,8 @@ sub _risk_detect {
     $risk_transaction->content( %parent_content );
     $risk_transaction->submit();
     if ($risk_transaction->is_success()) {
+         $self->fraud_score( $risk_transaction->fraud_score );
+         $self->fraud_transaction_id( $risk_transaction->fraud_transaction_id );
        if ( $risk_transaction->fraud_score <= $self->maximum_fraud_score()) {
            return 1;
        } else {
@@ -527,6 +531,14 @@ RISK).
 Retrieve or change the processor submission path (CHANGE AT YOUR OWN
 RISK).
 
+=head2 fraud_score();
+
+Retrieve or change the fraud score from any Business::FraudDetect plugin
+
+=head2 fraud_transaction_id();
+
+Retrieve or change the transaction id from any Business::FraudDetect plugin
+
 =head1 AUTHORS
 
 Jason Kohles, email@jasonkohles.com