(no commit message)
[Business-OnlineThirdPartyPayment-Dummy.git] / Dummy.pm
1 package Business::OnlineThirdPartyPayment::Dummy;
2
3 use strict;
4 use Carp;
5 use Business::OnlineThirdPartyPayment 3;
6 use Business::CreditCard;
7 use vars qw($VERSION @ISA $DEBUG);
8
9 @ISA = qw(Business::OnlineThirdPartyPayment);
10 $VERSION = '0.01';
11
12 $DEBUG = 0;
13
14 sub get_fields {
15     my($self,@fields) = @_;
16
17     my %content = $self->content();
18     my %new = ();
19     foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
20     return %new;
21 }
22
23 sub reference {
24     my ($self, $data) = @_;
25     $data->{reference} || '';
26 }
27
28 sub submit {
29     my($self) = @_;
30     my %content = $self->content;
31
32     my $action = lc($content{'action'});
33     die 'Dummy only supports "Authorization Only" and "Post Authorization" transactions'
34       unless $action eq 'authorization only' || $action eq 'post authorization';
35
36     my @required = qw( login amount );
37     push @required, qw( reference ) if $action eq 'post authorization';
38     if ($self->transaction_type() eq 'CC' ) {
39       push @required, qw( name ) unless $action eq 'post authorization';
40     }elsif ($self->transaction_type() eq 'ECHECK' ) {
41       push @required, qw( account_name ) unless $action eq 'post authorization';
42     } else {
43       croak("Dummy can't handle transaction type: ".
44             $self->transaction_type());
45     }
46     $self->required_fields(@required);
47
48     $self->popup_url( "http://127.0.0.1/webpay/collect.cgi?".
49                       join('&', map { "$_=". $content{$_} }
50                                 qw( reference amount redirecturl )
51                       )
52                     );
53
54     $self->is_success(1);
55     $self->authorization('Authorized');
56 }
57
58 1;
59 __END__
60
61 =head1 NAME
62
63 Business::OnlineThirdPartyPayment::Dummy - dummy backend for Business::OnlineThirdPartyPayment
64
65 =head1 SYNOPSIS
66
67   use Business::OnlineThirdPartyPayment;
68
69   my $tx = new Business::OnlineThirdPartyPayment("Dummy");
70   $tx->content(
71       login          => '87654321', 
72       action         => 'Normal Authorization',
73       description    => 'Business::OnlinePayment test',
74       amount         => '49.95',
75       invoice_number => '100100',
76       name           => 'Tofu Beast',
77       card_number    => '46464646464646',
78       expiration     => '11/08',
79   );
80   $tx->submit();
81
82   if($tx->is_success()) {
83       print "Card processed successfully: ".$tx->authorization."\n";
84   } else {
85       print "Card was rejected: ".$tx->error_message."\n";
86   }
87
88 =head1 DESCRIPTION
89
90 For detailed information see L<Business::OnlineThirdPartyPayment>.
91
92 =head1 NOTE
93
94 =head1 COMPATIBILITY
95
96 This module implements a dummy payment gateway.
97
98 =head1 AUTHOR
99
100 Jeff Finucane <jeff@cmh.net>
101
102 =head1 SEE ALSO
103
104 perl(1). L<Business::OnlinePayment>.
105
106 =cut
107