+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->risk_level <= $self->maximum_risk()) {
+ $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 $risk_detection = $self->risk_management();
+
+ #
+ # early return if user does not want optional risk mgt
+ #
+
+ return $self->{_child_submit}->($self,@_) unless $risk_detection && length $risk_detection;
+
+ #
+
+ # Search for an appropriate FD module
+ #
+
+ foreach my $subclass ( q(Business::OnlinePayment::) . $risk_detection,
+ q(Business::FraudDetect::).$risk_detection) {
+
+ if (!defined(&$subclass)) {
+ eval "use $subclass";
+ if ($@) {
+ Carp::croak("serious problem loading risk_detection module ($@)") unless
+ $@ =~ m/^Can\'t locate/;
+ } else {
+ my $risk_tx = bless ( { processor => $risk_detection } , $subclass );
+ $risk_tx->build_subs(keys %fields);
+ if ($risk_tx->can('set_defaults')) {
+ $risk_tx->set_defaults();
+ }
+ my %risk_params = %{$self->risk_management_params()};
+ foreach my $key ( keys %risk_params ) {
+ my $value = $risk_params{$key};
+ $key = lc($key);
+ $key =~ s/^\-//;
+ $risk_tx->build_subs($key);
+ $risk_tx->$key($value);
+ }
+ return $self->_risk_detect($risk_tx);
+ }
+ }
+ }
+};
+