0.05?
[Business-OnlinePayment.git] / OnlinePayment.pm
index 5e764a9..dbb28ce 100644 (file)
@@ -3,15 +3,14 @@ package Business::OnlinePayment;
 use strict;
 use vars qw($VERSION);
 use Carp;
-use Symbol;
 
 require 5.005;
 
-$VERSION = '3.00_04';
+$VERSION = '3.00_05';
 $VERSION = eval $VERSION; # modperlstyle: convert the string into a number
 
 # Remember subclasses we have "wrapped" submit() with _pre_submit()
-my %WrappedSubmitClassMethod = ();
+my %Presubmit_Added = ();
 
 my %fields = (
     authorization    => undef,
@@ -56,21 +55,18 @@ sub new {
         $self->$key($value);
     }
 
-    unless ( $subclass->can('submit') eq $class->can('submit') ) {
-        my $submit = qualify_to_ref('submit', $subclass);
+    # "wrap" submit with _pre_submit only once
+    unless ( $Presubmit_Added{$subclass} ) {
+        my $real_submit = $subclass->can('submit');
 
-       # "wrap" submit ONLY once, cache info for later calls to new()
-       if ( ! exists $WrappedSubmitClassMethod{$subclass} ) {
-           no warnings 'redefine';
-           no strict 'refs';
+       no warnings 'redefine';
+       no strict 'refs';
 
-           $WrappedSubmitClassMethod{$subclass} = \&$submit;
-           *{"${subclass}::submit"} = sub {
-               my $self = shift;
-               $self->_pre_submit();
-           }
+       *{"${subclass}::submit"} = sub {
+           my $self = shift;
+           return unless $self->_pre_submit(@_);
+           return $real_submit->($self, @_);
        }
-       $self->{_child_submit} = $WrappedSubmitClassMethod{$subclass};
     }
 
     return $self;
@@ -85,15 +81,15 @@ sub _risk_detect {
     $risk_transaction->submit();
     if ($risk_transaction->is_success()) {
        if ( $risk_transaction->fraud_score <= $self->maximum_fraud_score()) {
-           $self->{_child_submit}->($self);
+           return 1;
        } else {
-           $self->is_success(0);
            $self->error_message('Excessive risk from risk management');
        }
     } else {
        $self->error_message('Error in risk detection stage: ' .  $risk_transaction->error_message);
-       $self->is_success(0);
     }
+    $self->is_success(0);
+    return 0;
 }
 
 sub _pre_submit {
@@ -101,7 +97,7 @@ sub _pre_submit {
     my $fraud_detection = $self->fraud_detect();
 
     # early return if user does not want optional risk mgt
-    return $self->{_child_submit}->($self,@_) unless $fraud_detection && length $fraud_detection;
+    return 1 unless $fraud_detection;
 
     # Search for an appropriate FD module
     foreach my $subclass ( q(Business::OnlinePayment::) . $fraud_detection,
@@ -123,7 +119,8 @@ sub _pre_submit {
            }
        }
     }
-};
+    return 1; # BUG?: success if fraud_detection module not found!
+}
 
 sub content {
     my($self,%params) = @_;