add failure tests to Dummy
[Business-OnlinePayment-Dummy.git] / Dummy.pm
1 package Business::OnlinePayment::Dummy;
2
3 use strict;
4 use Carp;
5 use Business::OnlinePayment;
6 use vars qw($VERSION @ISA $me);
7
8 @ISA = qw(Business::OnlinePayment);
9 $VERSION = '0.01';
10 $me = 'Business::OnlinePayment::Dummy';
11
12 my %failure_status = (
13   1 => 'expired',
14   2 => 'nsf',
15   3 => 'stolen',
16   4 => 'pickup',
17   5 => 'blacklisted',
18   6 => 'declined',
19 );
20
21
22 sub submit {
23     my($self) = @_;
24     $self->order_number(time . '-' . int(rand(10000)));
25     my %c = $self->content;
26     if ( $c{'amount'} > 1.00 ) {
27       $self->is_success(1);
28       $self->authorization(int(rand(1000000)));
29     } elsif ( $c{'amount'} > 0.00 ) {
30       $self->is_success(0);
31       my $status = sprintf('%.0f', $c{'amount'} * 100);
32       if ($failure_status{$status}) {
33         $self->failure_status( $failure_status{$status} );
34         $self->error_message( uc($failure_status{$status}) );
35       }
36     } else {
37       die "Processor error";
38     }
39     return;
40 }
41
42 1;
43
44 __END__
45
46 =head1 NAME
47
48 Business::OnlinePayment::Dummy - Test backend for Business::OnlinePayment
49
50 =head1 SYNOPSIS
51
52 Submit returns success if the amount field is at least 1.00. If it's not,
53 instead returns the following status based on the cents part:
54
55 .01: expired
56 .02: nsf (non-sufficient funds)
57 .03: stolen
58 .04: pickup
59 .05: blacklisted
60 .06: declined
61
62 .00 throws an exception, to simulate a communication failure.
63
64 =head1 COPYRIGHT & LICENSE
65
66 Copyright 2016 Freeside Internet Services, Inc.
67
68 This program is free software; you can redistribute it and/or modify it
69 under the same terms as Perl itself.
70
71 =head1 SEE ALSO
72
73 perl(1). L<Business::OnlinePayment>.
74
75 =cut
76