1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
package Business::OnlinePayment::USAePay;
use strict;
use Carp;
use Business::OnlinePayment 3;
use Business::OnlinePayment::HTTPS;
use Digest::MD5 qw(md5_hex);
use URI::Escape;
use vars qw($VERSION @ISA $DEBUG);
@ISA = qw(Business::OnlinePayment::HTTPS);
$VERSION = '0.01';
$DEBUG = 0;
my $default_path = '/gate.php';
my $default_cert_path = '/secure/gate.php';
sub set_defaults {
my $self = shift;
$self->server('www.usaepay.com');
$self->port('443');
$self->path($default_path);
$self->build_subs(qw(order_number));
}
sub map_fields {
my($self) = shift;
my %content = $self->content();
my %types = ('visa' => 'CC',
'mastercard' => 'CC',
'american express' => 'CC',
'discover' => 'CC',
'check' => 'ECHECK',
);
$content{'type'} = $types{lc($content{'type'})} || $content{'type'};
$self->transaction_type($content{'type'});
my %actions;
my %cc_actions = ('normal authorization' => 'sale',
'authorization only' => 'authonly',
'post authorization' => 'postauth',
);
my %ec_actions = ('normal authorization' => 'check',
'credit' => 'checkcredit',
);
if ($content{'type'} eq 'CC') {
(%actions) = (%cc_actions);
}elsif ($content{'type'} eq 'ECHECK') {
(%actions) = (%ec_actions);
}
$content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
$content{'expiration'} =~ s/\D//g;
$content{'md5hash'} = md5_hex(join(':', map "$content{$_}", qw(action password amount invoice_number md5key))) if defined $content{'password'};
$self->content(%content);
}
sub submit {
my($self) = @_;
$self->map_fields();
$self->remap_fields(
login => 'UMkey',
md5key => 'UMmd5key',
md5hash => 'UMmd5hash',
card_number => 'UMcard',
expiration => 'UMexpir',
amount => 'UMamount',
invoice_number => 'UMinvoice',
description => 'UMdescription',
customer_id => 'UMcustid',
cvv2 => 'UMcvv2',
email => 'UMcustemail',
name => 'UMname',
address => 'UMstreet',
zip => 'UMzip',
customer_ip => 'UMip',
order_number => 'UMrefNum',
authorization => 'UMauthCode',
routing_code => 'UMrouting',
account_number => 'UMaccount',
customer_ssn => 'UMssn',
);
my %content = $self->content;
if ( $DEBUG ) {
warn "content:$_ => $content{$_}\n" foreach keys %content;
}
my @required_fields = qw(type action login);
if ($self->transaction_type() eq 'CC' ) {
push @required_fields, qw/card_number expiration amount invoice_number name address zip/;
if ($self->{_content}->{action} eq 'postauth') {
push @required_fields, qw/authorization/;
}
if ( $self->{_content}->{action} eq 'void'
|| $self->{_content}->{action} eq 'capture') {
push @required_fields, qw/order_number/;
}
}elsif ($self->transaction_type() eq 'ECHECK' ) {
push @required_fields, qw/routing_code account_number amount invoice_number name customer_ssn/;
} else {
croak("USAePay can't handle transaction type: ".
$self->transaction_type());
}
$self->required_fields(@required_fields);
my %post_data = $self->get_fields( map "$_", qw(
UMcommand UMkey UMmd5hash UMmd5key UMauthCode UMrefNum UMcard UMexpir
UMrouting UMaccount UMamount Umtax UMnontaxable UMtip UMshipping
UMdiscount UMsubtotal UMcustid UMinvoice UMorderid UMponum UMdescription
UMcvv2 UMcustemail UMcustreceipt UMname UMStreet UMzip UMssn UMdlnum
UMdlstate UMclerk UMterminal UMtable UMip UMsoftware UMredir
UMredirApproved UMredirDeclined UMechofields UMtestmode
) );
$post_data{'UMtestmode'} = $self->test_transaction() ? 1 : 0;
$post_data{'UMsoftware'} = __PACKAGE__. " $VERSION";
if ( $DEBUG ) {
warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data;
}
my($page,$server_response) = $self->https_post(%post_data);
if ( $DEBUG ) {
warn "response page: $page\n";
}
my $response;
if ($server_response =~ /200/){
$response = {map { split '=', $_, 2 } split '&', $page};
}else{
$response->{UMstatus} = 'Error';
$response->{UMerror} = $server_response;
}
$response->{$_} =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg
foreach keys %$response;
if ( $DEBUG ) {
warn "response:$_ => $response->{$_}\n" foreach keys %$response;
}
if ( $response->{UMstatus} =~ /^Approved/ ) {
$self->is_success(1);
$self->authorization($response->{UMauthCode});
} else {
$self->is_success(0);
}
$self->result_code($response->{UMresult});
$self->error_message($response->{UMerror});
$self->server_response($response);
}
1;
__END__
=head1 NAME
Business::OnlinePayment::USAePay - USA ePay backend for Business::OnlinePayment
=head1 SYNOPSIS
use Business::OnlinePayment;
my $tx = new Business::OnlinePayment("USAePay");
$tx->content(
login => 'igztOatyqbpd1wsxijl4xnxjodldwdxR', #USA ePay source key
action => 'Normal Authorization',
description => 'Business::OnlinePayment test',
amount => '49.95',
invoice_number => '100100',
name => 'Tofu Beast',
card_number => '46464646464646',
expiration => '11/08',
address => '1234 Bean Curd Lane, San Francisco',
zip => '94102',
);
$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::OnlinePayment>.
=head1 NOTE
=head1 COMPATIBILITY
This module implements USAePay's CGI Gateway API v2.9.5. See
http://www.usaepay.com/topics/api.html for details.
=head1 AUTHOR
Jeff Finucane <jeff@cmh.net>
=head1 SEE ALSO
perl(1). L<Business::OnlinePayment>.
=cut
|