package Business::OnlinePayment;
use strict;
-use vars qw($VERSION); # @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use vars qw($VERSION);
use Carp;
use Symbol;
require 5.005;
-#use Data::Dumper;
-
-#require Exporter;
-
-#@ISA = (); #qw(Exporter AutoLoader);
-#@EXPORT = qw();
-#@EXPORT_OK = qw();
$VERSION = '3.00_04';
-sub VERSION { #Argument "3.00_01" isn't numeric in subroutine entry
- local($^W)=0;
- UNIVERSAL::VERSION(@_);
-}
+$VERSION = eval $VERSION; # modperlstyle: convert the string into a number
my %fields = (
is_success => undef,
sub new {
-
my($class,$processor,%data) = @_;
Carp::croak("unspecified processor") unless $processor;
foreach(keys %data) {
my $key = lc($_);
my $value = $data{$_};
- $key =~ s/^\-//;
+ $key =~ s/^\-+//;
$self->build_subs($key);
$self->$key($value);
}
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 {
# 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();