(no commit message) master import
authorjeff <jeff>
Mon, 2 Mar 2009 23:50:16 +0000 (23:50 +0000)
committerjeff <jeff>
Mon, 2 Mar 2009 23:50:16 +0000 (23:50 +0000)
Dummy.pm [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
t/Dummy.t [new file with mode: 0644]

diff --git a/Dummy.pm b/Dummy.pm
new file mode 100644 (file)
index 0000000..92d1f24
--- /dev/null
+++ b/Dummy.pm
@@ -0,0 +1,107 @@
+package Business::OnlineThirdPartyPayment::Dummy;
+
+use strict;
+use Carp;
+use Business::OnlineThirdPartyPayment 3;
+use Business::CreditCard;
+use vars qw($VERSION @ISA $DEBUG);
+
+@ISA = qw(Business::OnlineThirdPartyPayment);
+$VERSION = '0.01';
+
+$DEBUG = 0;
+
+sub get_fields {
+    my($self,@fields) = @_;
+
+    my %content = $self->content();
+    my %new = ();
+    foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
+    return %new;
+}
+
+sub reference {
+    my ($self, $data) = @_;
+    $data->{reference} || '';
+}
+
+sub submit {
+    my($self) = @_;
+    my %content = $self->content;
+
+    my $action = lc($content{'action'});
+    die 'Dummy only supports "Authorization Only" and "Post Authorization" transactions'
+      unless $action eq 'authorization only' || $action eq 'post authorization';
+
+    my @required = qw( login amount );
+    push @required, qw( reference ) if $action eq 'post authorization';
+    if ($self->transaction_type() eq 'CC' ) {
+      push @required, qw( name ) unless $action eq 'post authorization';
+    }elsif ($self->transaction_type() eq 'ECHECK' ) {
+      push @required, qw( account_name ) unless $action eq 'post authorization';
+    } else {
+      croak("Dummy can't handle transaction type: ".
+            $self->transaction_type());
+    }
+    $self->required_fields(@required);
+
+    $self->popup_url( "http://127.0.0.1/webpay/collect.cgi?".
+                      join('&', map { "$_=". $content{$_} }
+                                qw( reference amount redirecturl )
+                      )
+                    );
+
+    $self->is_success(1);
+    $self->authorization('Authorized');
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Business::OnlineThirdPartyPayment::Dummy - dummy backend for Business::OnlineThirdPartyPayment
+
+=head1 SYNOPSIS
+
+  use Business::OnlineThirdPartyPayment;
+
+  my $tx = new Business::OnlineThirdPartyPayment("Dummy");
+  $tx->content(
+      login          => '87654321', 
+      action         => 'Normal Authorization',
+      description    => 'Business::OnlinePayment test',
+      amount         => '49.95',
+      invoice_number => '100100',
+      name           => 'Tofu Beast',
+      card_number    => '46464646464646',
+      expiration     => '11/08',
+  );
+  $tx->submit();
+
+  if($tx->is_success()) {
+      print "Card processed successfully: ".$tx->authorization."\n";
+  } else {
+      print "Card was rejected: ".$tx->error_message."\n";
+  }
+
+=head1 DESCRIPTION
+
+For detailed information see L<Business::OnlineThirdPartyPayment>.
+
+=head1 NOTE
+
+=head1 COMPATIBILITY
+
+This module implements a dummy payment gateway.
+
+=head1 AUTHOR
+
+Jeff Finucane <jeff@cmh.net>
+
+=head1 SEE ALSO
+
+perl(1). L<Business::OnlinePayment>.
+
+=cut
+
diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
index 0000000..c62b7c0
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,5 @@
+Makefile.PL
+MANIFEST
+README
+Dummy.pm
+t/Dummy.t
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..f119db4
--- /dev/null
@@ -0,0 +1,12 @@
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+    'NAME'         => 'Business::OnlineThirdPartyPayment::Dummy',
+    'VERSION_FROM' => 'Dummy.pm', # finds $VERSION
+    'AUTHOR'       => 'Jeff Finucane <jeff@cmh.net>',
+    'PREREQ_PM'    => { 
+                        'Business::OnlineThirdPartyPayment' => 3,
+                        'Business::CreditCard' => 0.27,
+                      },
+);
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/t/Dummy.t b/t/Dummy.t
new file mode 100644 (file)
index 0000000..ede60df
--- /dev/null
+++ b/t/Dummy.t
@@ -0,0 +1,28 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl eWay.t'
+
+use Test;
+BEGIN { plan tests => 6 };
+use Business::OnlineThirdPartyPayment::Dummy;
+
+# a test transaction
+my ($tx, $txnum, $res);
+ok($tx = new Business::OnlineThirdPartyPayment("Dummy"));
+ok(
+    $tx->content(
+        type           => 'CC',
+        login          => '87654321',
+        action         => 'Authorization Only',
+        description    => 'Business::OnlineThirdPartyPayment test',
+        amount         => '49.95',
+        invoice_number => '100100',
+        name           => 'Tofu Beast',
+        card_number    => '4646464646464646',
+        expiration     => '11/08',
+    )
+);
+ok($tx->test_transaction(1));
+ok($tx->submit());
+ok($tx->is_success());
+ok($tx->authorization(), 'Authorized');
+