line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::OnlinePayment::USAePay; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24393
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
4
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
5
|
1
|
|
|
1
|
|
1074
|
use Business::OnlinePayment 3; |
|
1
|
|
|
|
|
4108
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
1204
|
use Business::OnlinePayment::HTTPS; |
|
1
|
|
|
|
|
41634
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
10
|
use Digest::MD5 qw(md5_hex); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
8
|
1
|
|
|
1
|
|
4
|
use URI::Escape; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
9
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION @ISA $DEBUG); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1253
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(Business::OnlinePayment::HTTPS); |
12
|
|
|
|
|
|
|
$VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$DEBUG = 0; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _info { |
17
|
|
|
|
|
|
|
{ |
18
|
0
|
|
|
0
|
|
0
|
'info_compat' => '0.01', |
19
|
|
|
|
|
|
|
'gateway_name' => 'USAePay', |
20
|
|
|
|
|
|
|
'gateway_url' => 'http://www.usaepay.com', |
21
|
|
|
|
|
|
|
'module_version' => $VERSION, |
22
|
|
|
|
|
|
|
'supported_types' => [ 'CC', 'ECHECK' ], |
23
|
|
|
|
|
|
|
'supported_actions' => { |
24
|
|
|
|
|
|
|
CC => [ |
25
|
|
|
|
|
|
|
'Normal Authorization', |
26
|
|
|
|
|
|
|
'Authorization Only', |
27
|
|
|
|
|
|
|
'Post Authorization', |
28
|
|
|
|
|
|
|
'Credit', |
29
|
|
|
|
|
|
|
'Void', |
30
|
|
|
|
|
|
|
], |
31
|
|
|
|
|
|
|
ECHECK => [ |
32
|
|
|
|
|
|
|
'Normal Authorization', |
33
|
|
|
|
|
|
|
'Credit', |
34
|
|
|
|
|
|
|
], |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $default_path = '/gate.php'; |
40
|
|
|
|
|
|
|
my $default_cert_path = '/secure/gate.php'; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub set_defaults { |
43
|
1
|
|
|
1
|
0
|
785
|
my $self = shift; |
44
|
1
|
|
|
|
|
31
|
$self->server('www.usaepay.com'); |
45
|
1
|
|
|
|
|
40
|
$self->port('443'); |
46
|
1
|
|
|
|
|
39
|
$self->path($default_path); |
47
|
1
|
|
|
|
|
13
|
$self->build_subs(qw(avs_code cvv2_response)); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub map_fields { |
52
|
29
|
|
|
29
|
0
|
5677
|
my($self) = shift; |
53
|
|
|
|
|
|
|
|
54
|
29
|
|
|
|
|
114
|
my %content = $self->content(); |
55
|
|
|
|
|
|
|
|
56
|
29
|
|
|
|
|
750
|
my %types = ('visa' => 'CC', |
57
|
|
|
|
|
|
|
'mastercard' => 'CC', |
58
|
|
|
|
|
|
|
'american express' => 'CC', |
59
|
|
|
|
|
|
|
'discover' => 'CC', |
60
|
|
|
|
|
|
|
'check' => 'ECHECK', |
61
|
|
|
|
|
|
|
); |
62
|
29
|
|
33
|
|
|
276
|
$content{'type'} = $types{lc($content{'type'})} || $content{'type'}; |
63
|
29
|
|
|
|
|
1102
|
$self->transaction_type($content{'type'}); |
64
|
|
|
|
|
|
|
|
65
|
29
|
|
|
|
|
197
|
my %actions; |
66
|
29
|
|
|
|
|
260
|
my %cc_actions = ('normal authorization' => 'sale', |
67
|
|
|
|
|
|
|
'authorization only' => 'authonly', |
68
|
|
|
|
|
|
|
'post authorization' => 'postauth', |
69
|
|
|
|
|
|
|
'credit' => 'credit', |
70
|
|
|
|
|
|
|
'void' => 'void', |
71
|
|
|
|
|
|
|
); |
72
|
29
|
|
|
|
|
97
|
my %ec_actions = ('normal authorization' => 'check', |
73
|
|
|
|
|
|
|
'credit' => 'checkcredit', |
74
|
|
|
|
|
|
|
); |
75
|
29
|
100
|
|
|
|
114
|
if ($content{'type'} eq 'CC') { |
|
|
50
|
|
|
|
|
|
76
|
27
|
|
|
|
|
306
|
(%actions) = (%cc_actions); |
77
|
|
|
|
|
|
|
}elsif ($content{'type'} eq 'ECHECK') { |
78
|
2
|
|
|
|
|
7
|
(%actions) = (%ec_actions); |
79
|
|
|
|
|
|
|
} |
80
|
29
|
|
66
|
|
|
170
|
$content{'action'} = $actions{lc($content{'action'})} || $content{'action'}; |
81
|
|
|
|
|
|
|
|
82
|
29
|
100
|
|
|
|
239
|
$content{'expiration'} =~ s/\D//g if exists $content{'expiration'}; |
83
|
|
|
|
|
|
|
|
84
|
145
|
100
|
|
|
|
1028
|
$content{'md5hash'} = |
85
|
29
|
50
|
|
|
|
139
|
md5_hex( join(':', map { defined($content{$_}) ? $content{$_} : '' } |
86
|
|
|
|
|
|
|
qw(action password amount invoice_number md5key))) |
87
|
|
|
|
|
|
|
if defined $content{'password'}; |
88
|
|
|
|
|
|
|
|
89
|
29
|
|
|
|
|
259
|
$self->content(%content); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub submit { |
93
|
29
|
|
|
29
|
|
198394
|
my($self) = @_; |
94
|
|
|
|
|
|
|
|
95
|
29
|
|
|
|
|
5957
|
$self->map_fields(); |
96
|
|
|
|
|
|
|
|
97
|
29
|
|
|
|
|
5728
|
$self->remap_fields( |
98
|
|
|
|
|
|
|
login => 'UMkey', |
99
|
|
|
|
|
|
|
md5key => 'UMmd5key', |
100
|
|
|
|
|
|
|
md5hash => 'UMmd5hash', |
101
|
|
|
|
|
|
|
card_number => 'UMcard', |
102
|
|
|
|
|
|
|
expiration => 'UMexpir', |
103
|
|
|
|
|
|
|
amount => 'UMamount', |
104
|
|
|
|
|
|
|
invoice_number => 'UMinvoice', |
105
|
|
|
|
|
|
|
description => 'UMdescription', |
106
|
|
|
|
|
|
|
customer_id => 'UMcustid', |
107
|
|
|
|
|
|
|
cvv2 => 'UMcvv2', |
108
|
|
|
|
|
|
|
email => 'UMcustemail', |
109
|
|
|
|
|
|
|
name => 'UMname', |
110
|
|
|
|
|
|
|
address => 'UMstreet', |
111
|
|
|
|
|
|
|
zip => 'UMzip', |
112
|
|
|
|
|
|
|
customer_ip => 'UMip', |
113
|
|
|
|
|
|
|
order_number => 'UMrefNum', |
114
|
|
|
|
|
|
|
authorization => 'UMauthCode', |
115
|
|
|
|
|
|
|
routing_code => 'UMrouting', |
116
|
|
|
|
|
|
|
account_number => 'UMaccount', |
117
|
|
|
|
|
|
|
customer_ssn => 'UMssn', |
118
|
|
|
|
|
|
|
action => 'UMcommand', |
119
|
|
|
|
|
|
|
); |
120
|
29
|
|
|
|
|
7047
|
my %content = $self->content; |
121
|
29
|
50
|
|
|
|
945
|
if ( $DEBUG ) { |
122
|
0
|
|
|
|
|
0
|
warn "content:$_ => $content{$_}\n" foreach keys %content; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
29
|
|
|
|
|
95
|
my @required_fields = qw(type action login); |
126
|
|
|
|
|
|
|
|
127
|
29
|
|
|
|
|
73
|
my $action = $self->{_content}->{action}; |
128
|
29
|
100
|
|
|
|
735
|
if ($self->transaction_type() eq 'CC' ) { |
|
|
50
|
|
|
|
|
|
129
|
27
|
50
|
33
|
|
|
374
|
if ($action eq 'void' or $action eq 'capture') { |
130
|
0
|
|
|
|
|
0
|
push @required_fields, qw/order_number/; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else { |
133
|
|
|
|
|
|
|
# sale, authonly, credit, postauth |
134
|
27
|
|
|
|
|
92
|
push @required_fields, qw/card_number expiration amount address zip/; |
135
|
27
|
50
|
|
|
|
76
|
if ($action eq 'postauth') { |
136
|
0
|
|
|
|
|
0
|
push @required_fields, qw/authorization/; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif ($self->transaction_type() eq 'ECHECK' ) { |
141
|
2
|
|
|
|
|
59
|
push @required_fields, qw/routing_code account_number amount name customer_ssn/; |
142
|
|
|
|
|
|
|
} else { |
143
|
0
|
|
|
|
|
0
|
croak("USAePay can't handle transaction type: ". |
144
|
|
|
|
|
|
|
$self->transaction_type()); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
29
|
|
|
|
|
172
|
$self->required_fields(@required_fields); |
148
|
|
|
|
|
|
|
|
149
|
29
|
|
|
|
|
2158
|
my %post_data = $self->get_fields( map "$_", qw( |
150
|
|
|
|
|
|
|
UMcommand UMkey UMmd5hash UMmd5key UMauthCode UMrefNum UMcard UMexpir |
151
|
|
|
|
|
|
|
UMrouting UMaccount UMamount Umtax UMnontaxable UMtip UMshipping |
152
|
|
|
|
|
|
|
UMdiscount UMsubtotal UMcustid UMinvoice UMorderid UMponum UMdescription |
153
|
|
|
|
|
|
|
UMcvv2 UMcustemail UMcustreceipt UMname UMStreet UMzip UMssn UMdlnum |
154
|
|
|
|
|
|
|
UMdlstate UMclerk UMterminal UMtable UMip UMsoftware UMredir |
155
|
|
|
|
|
|
|
UMredirApproved UMredirDeclined UMechofields UMtestmode |
156
|
|
|
|
|
|
|
) ); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# test_transaction(0): normal mode |
159
|
|
|
|
|
|
|
# 1 : test mode (validates formatting only) |
160
|
|
|
|
|
|
|
# 2 : use sandbox server |
161
|
|
|
|
|
|
|
# 3 : test mode on sandbox server |
162
|
29
|
|
50
|
|
|
4540
|
my $test = $self->test_transaction || 0; |
163
|
29
|
50
|
|
|
|
1032
|
$self->server('sandbox.usaepay.com') if ( $test & 2 ); |
164
|
29
|
50
|
|
|
|
278
|
$post_data{'UMtestmode'} = ($test & 1) ? 1 : 0; |
165
|
|
|
|
|
|
|
|
166
|
29
|
|
|
|
|
106
|
$post_data{'UMsoftware'} = __PACKAGE__. " $VERSION"; |
167
|
29
|
50
|
|
|
|
70
|
if ( $DEBUG ) { |
168
|
0
|
|
|
|
|
0
|
warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
29
|
|
|
|
|
225
|
my($page,$server_response) = $self->https_post(%post_data); |
172
|
29
|
50
|
|
|
|
21958409
|
if ( $DEBUG ) { |
173
|
0
|
|
|
|
|
0
|
warn "response page: $page\n"; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
29
|
|
|
|
|
62
|
my $response; |
177
|
29
|
50
|
|
|
|
178
|
if ($server_response =~ /200/){ |
178
|
29
|
|
|
|
|
191
|
$response = {map { split '=', $_, 2 } split '&', $page}; |
|
203
|
|
|
|
|
579
|
|
179
|
|
|
|
|
|
|
}else{ |
180
|
0
|
|
|
|
|
0
|
$response->{UMstatus} = 'Error'; |
181
|
0
|
|
|
|
|
0
|
$response->{UMerror} = $server_response; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
116
|
|
|
|
|
567
|
$response->{$_} =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg |
185
|
29
|
|
|
|
|
445
|
foreach keys %$response; |
186
|
|
|
|
|
|
|
|
187
|
29
|
50
|
|
|
|
126
|
if ( $DEBUG ) { |
188
|
0
|
|
|
|
|
0
|
warn "response:$_ => $response->{$_}\n" foreach keys %$response; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
29
|
50
|
|
|
|
145
|
if ( $response->{UMstatus} =~ /^Approved/ ) { |
192
|
0
|
|
|
|
|
0
|
$self->is_success(1); |
193
|
0
|
|
|
|
|
0
|
$self->authorization($response->{UMauthCode}); |
194
|
|
|
|
|
|
|
} else { |
195
|
29
|
|
|
|
|
854
|
$self->is_success(0); |
196
|
|
|
|
|
|
|
} |
197
|
29
|
|
|
|
|
1025
|
$self->order_number($response->{UMrefNum}); |
198
|
29
|
|
|
|
|
1032
|
$self->avs_code($response->{UMavsResultCode}); |
199
|
29
|
|
|
|
|
998
|
$self->cvv2_response($response->{UMcvv2ResultCode}); |
200
|
29
|
|
|
|
|
991
|
$self->result_code($response->{UMresult}); |
201
|
29
|
|
|
|
|
944
|
$self->error_message($response->{UMerror}); |
202
|
29
|
|
|
|
|
947
|
$self->server_response($response); |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |
206
|
|
|
|
|
|
|
__END__ |