package Business::OnlinePayment;
use strict;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use vars qw($VERSION);
+use Carp;
+use Symbol;
-require 5.004;
-require Exporter;
+require 5.005;
-@ISA = qw(Exporter AutoLoader);
-@EXPORT = qw();
-@EXPORT_OK = qw();
-
-$VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d"x$#r,@r};
-
-use Carp();
+$VERSION = '3.00_04';
+$VERSION = eval $VERSION; # modperlstyle: convert the string into a number
my %fields = (
is_success => undef,
+ failure_status => undef,
result_code => undef,
test_transaction => undef,
require_avs => undef,
server => undef,
port => undef,
path => undef,
+ fraud_detect => undef,
server_response => undef,
+ maximum_risk => undef,
);
foreach(keys %data) {
my $key = lc($_);
my $value = $data{$_};
- $key =~ s/^\-//;
+ $key =~ s/^\-+//;
$self->build_subs($key);
$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 {
my($self,@fields) = @_;
+ my @missing;
my %content = $self->content();
foreach(@fields) {
- Carp::croak("missing required field $_") unless exists $content{$_};
+ push(@missing, $_) unless exists $content{$_};
}
+
+ Carp::croak("missing required field(s): " . join(", ", @missing) . "\n")
+ if(@missing);
}
sub get_fields {
- my($self,@fields) = @_;
+ my($self, @fields) = @_;
my %content = $self->content();
- my %new = ();
- foreach(@fields) { $new{$_} = $content{$_}; }
- return %new;
+
+ #my %new = ();
+ #foreach(@fields) { $new{$_} = $content{$_}; }
+ #return %new;
+ map { $_ => $content{$_} } grep defined $content{$_}, @fields;
}
sub remap_fields {
my($self,%map) = @_;
my %content = $self->content();
- foreach(%map) {
+ foreach( keys %map ) {
$content{$map{$_}} = $content{$_};
}
$self->content(%content);
# AutoLoader::AUTOLOAD, instead of passing up the chain
sub build_subs {
my $self = shift;
+
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();
Returns true if the transaction was submitted successfully, false if it failed (or undef if it has not been submitted yet).
+=head2 failure_status();
+
+If the transactdion failed, it can optionally return a specific failure status
+(normalized, not gateway-specific). Currently defined statuses are: "expired",
+"nsf" (non-sufficient funds), "stolen", "pickup", "blacklisted" and
+"declined" (card/transaction declines only, not other errors).
+
+Note that (as of Aug 2006) this is only supported by some of the newest
+processor modules, and that, even if supported, a failure status is an entirely
+optional field that is only set for specific kinds of failures.
+
=head2 result_code();
Returns the precise result code that the processor returned, these are normally one letter codes that don't mean much unless you understand the protocol they speak, you probably don't need this, but it's there just in case.
Retrieve or change the processor submission path (CHANGE AT YOUR OWN RISK).
-=head1 AUTHOR
+=head1 AUTHORS
Jason Kohles, email@jasonkohles.com
+(v3 rewrite) Ivan Kohler <ivan-business-onlinepayment@420.am>
+
=head1 DISCLAIMER
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
=head1 SEE ALSO
+http://420.am/business-onlinepayment/
+
For verification of credit card checksums, see L<Business::CreditCard>.
=cut