use strict;
use vars qw($VERSION); # @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
+use Symbol;
require 5.005;
+#use Data::Dumper;
+
#require Exporter;
#@ISA = (); #qw(Exporter AutoLoader);
server => undef,
port => undef,
path => undef,
+ fraud_detect => undef,
server_response => undef,
+ maximum_risk => undef,
);
$self->$key($value);
}
+ {
+ 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();
+
+ }
+ }
+
return $self;
}
+sub _risk_detect {
+ my ($self, $risk_transaction) = @_;
+
+ my %parent_content = $self->content();
+ $parent_content{action} = 'Fraud Detect';
+ $risk_transaction->content( %parent_content );
+ $risk_transaction->submit();
+ if ($risk_transaction->is_success()) {
+ if ( $risk_transaction->fraud_score <= $self->maximum_fraud_score()) {
+ $self->{_child_submit}->($self);
+ } 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);
+ }
+}
+
+sub _pre_submit{
+ my ($self) = @_;
+ 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;
+
+ #
+
+ # Search for an appropriate FD module
+ #
+
+ foreach my $subclass ( q(Business::OnlinePayment::) . $fraud_detection,
+ q(Business::FraudDetect::).$fraud_detection) {
+
+ if (!defined(&$subclass)) {
+ eval "use $subclass";
+ if ($@) {
+ Carp::croak("serious problem loading fraud_detection module ($@)") unless
+ $@ =~ m/^Can\'t locate/;
+ } else {
+ my $risk_tx = bless ( { processor => $fraud_detection } , $subclass );
+ $risk_tx->build_subs(keys %fields);
+ if ($risk_tx->can('set_defaults')) {
+ $risk_tx->set_defaults();
+ }
+ $risk_tx->_glean_parameters_from_parent($self);
+ return $self->_risk_detect($risk_tx);
+ }
+ }
+ }
+};
+
sub content {
my($self,%params) = @_;
if($params{'type'}) { $self->transaction_type($params{'type'}); }
%{$self->{'_content'}} = %params;
}
- return %{$self->{'_content'}};
+ return exists $self->{'_content'} ? %{$self->{'_content'}} : ();
}
sub required_fields {
# AutoLoader::AUTOLOAD, instead of passing up the chain
sub build_subs {
my $self = shift;
- no warnings 'redefine';
+
foreach(@_) {
+ next if($self->can($_));
eval "sub $_ { my \$self = shift; if(\@_) { \$self->{$_} = shift; } return \$self->{$_}; }";
}
}
my $transaction = new Business::OnlinePayment($processor, %processor_info);
$transaction->content(
- type => 'Visa',
- amount => '49.95',
- cardnumber => '1234123412341238',
- expiration => '0100',
- name => 'John Q Doe',
+ type => 'Visa',
+ amount => '49.95',
+ card_number => '1234123412341238',
+ expiration => '0100',
+ name => 'John Q Doe',
);
$transaction->submit();