X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=OnlinePayment.pm;h=5e764a972a47316c7031b789036dfa579ed3a09c;hb=f0b9b398d11b68812ec480c05f8d484305ec9131;hp=28deb6d045d815800aa699250f751ec614b61f1b;hpb=250f659a476f4ed941228a2845d6dd89e78a7119;p=Business-OnlinePayment.git diff --git a/OnlinePayment.pm b/OnlinePayment.pm index 28deb6d..5e764a9 100644 --- a/OnlinePayment.pm +++ b/OnlinePayment.pm @@ -10,6 +10,9 @@ require 5.005; $VERSION = '3.00_04'; $VERSION = eval $VERSION; # modperlstyle: convert the string into a number +# Remember subclasses we have "wrapped" submit() with _pre_submit() +my %WrappedSubmitClassMethod = (); + my %fields = ( authorization => undef, error_message => undef, @@ -27,7 +30,6 @@ my %fields = ( transaction_type => undef, ); - sub new { my($class,$processor,%data) = @_; @@ -55,15 +57,20 @@ sub new { } unless ( $subclass->can('submit') eq $class->can('submit') ) { - no strict 'refs'; - no warnings 'redefine'; my $submit = qualify_to_ref('submit', $subclass); - $self->{_child_submit} = \&$submit; - *{"${subclass}::submit"} = sub { - my $self = shift; - $self->_pre_submit(); - } + # "wrap" submit ONLY once, cache info for later calls to new() + if ( ! exists $WrappedSubmitClassMethod{$subclass} ) { + no warnings 'redefine'; + no strict 'refs'; + + $WrappedSubmitClassMethod{$subclass} = \&$submit; + *{"${subclass}::submit"} = sub { + my $self = shift; + $self->_pre_submit(); + } + } + $self->{_child_submit} = $WrappedSubmitClassMethod{$subclass}; } return $self; @@ -89,7 +96,7 @@ sub _risk_detect { } } -sub _pre_submit{ +sub _pre_submit { my ($self) = @_; my $fraud_detection = $self->fraud_detect(); @@ -213,9 +220,9 @@ Business::OnlinePayment - Perl extension for online payment processing $transaction->submit(); if($transaction->is_success()) { - print "Card processed successfully: ".$transaction->authorization()."\n"; + print "Card processed successfully: ", $transaction->authorization(), "\n"; } else { - print "Card was rejected: ".$transaction->error_message()."\n"; + print "Card was rejected: ", $transaction->error_message(), "\n"; } =head1 DESCRIPTION