1 package Business::OnlinePayment::USAePay;
5 use Business::OnlinePayment 3;
6 use Business::OnlinePayment::HTTPS;
7 use Digest::MD5 qw(md5_hex);
9 use vars qw($VERSION @ISA $DEBUG);
11 @ISA = qw(Business::OnlinePayment::HTTPS);
18 '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' => {
25 'Normal Authorization',
32 'Normal Authorization',
39 my $default_path = '/gate.php';
40 my $default_cert_path = '/secure/gate.php';
44 $self->server('www.usaepay.com');
46 $self->path($default_path);
47 $self->build_subs(qw(avs_code cvv2_response));
54 my %content = $self->content();
56 my %types = ('visa' => 'CC',
58 'american express' => 'CC',
62 $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
63 $self->transaction_type($content{'type'});
66 my %cc_actions = ('normal authorization' => 'sale',
67 'authorization only' => 'authonly',
68 'post authorization' => 'postauth',
72 my %ec_actions = ('normal authorization' => 'check',
73 'credit' => 'checkcredit',
75 if ($content{'type'} eq 'CC') {
76 (%actions) = (%cc_actions);
77 }elsif ($content{'type'} eq 'ECHECK') {
78 (%actions) = (%ec_actions);
80 $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
82 $content{'expiration'} =~ s/\D//g;
84 $content{'md5hash'} = md5_hex(join(':', map "$content{$_}", qw(action password amount invoice_number md5key))) if defined $content{'password'};
86 $self->content(%content);
97 md5hash => 'UMmd5hash',
98 card_number => 'UMcard',
99 expiration => 'UMexpir',
100 amount => 'UMamount',
101 invoice_number => 'UMinvoice',
102 description => 'UMdescription',
103 customer_id => 'UMcustid',
105 email => 'UMcustemail',
107 address => 'UMstreet',
109 customer_ip => 'UMip',
110 order_number => 'UMrefNum',
111 authorization => 'UMauthCode',
112 routing_code => 'UMrouting',
113 account_number => 'UMaccount',
114 customer_ssn => 'UMssn',
115 action => 'UMcommand',
117 my %content = $self->content;
119 warn "content:$_ => $content{$_}\n" foreach keys %content;
122 my @required_fields = qw(type action login);
124 my $action = $self->{_content}->{action};
125 if ($self->transaction_type() eq 'CC' ) {
126 if ($action eq 'void' or $action eq 'capture') {
127 push @required_fields, qw/order_number/;
130 # sale, authonly, credit, postauth
131 push @required_fields, qw/card_number expiration amount address zip/;
132 if ($action eq 'postauth') {
133 push @required_fields, qw/authorization/;
137 elsif ($self->transaction_type() eq 'ECHECK' ) {
138 push @required_fields, qw/routing_code account_number amount name customer_ssn/;
140 croak("USAePay can't handle transaction type: ".
141 $self->transaction_type());
144 $self->required_fields(@required_fields);
146 my %post_data = $self->get_fields( map "$_", qw(
147 UMcommand UMkey UMmd5hash UMmd5key UMauthCode UMrefNum UMcard UMexpir
148 UMrouting UMaccount UMamount Umtax UMnontaxable UMtip UMshipping
149 UMdiscount UMsubtotal UMcustid UMinvoice UMorderid UMponum UMdescription
150 UMcvv2 UMcustemail UMcustreceipt UMname UMStreet UMzip UMssn UMdlnum
151 UMdlstate UMclerk UMterminal UMtable UMip UMsoftware UMredir
152 UMredirApproved UMredirDeclined UMechofields UMtestmode
154 # test_transaction(0): normal mode
155 # 1 : test mode (validates formatting only)
156 # 2 : use sandbox server
157 # 3 : test mode on sandbox server
158 $self->server('sandbox.usaepay.com') if ( $self->test_transaction & 2 );
159 $post_data{'UMtestmode'} = ($self->test_transaction() & 1) ? 1 : 0;
160 $post_data{'UMsoftware'} = __PACKAGE__. " $VERSION";
162 warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data;
165 my($page,$server_response) = $self->https_post(%post_data);
167 warn "response page: $page\n";
171 if ($server_response =~ /200/){
172 $response = {map { split '=', $_, 2 } split '&', $page};
174 $response->{UMstatus} = 'Error';
175 $response->{UMerror} = $server_response;
178 $response->{$_} =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg
179 foreach keys %$response;
182 warn "response:$_ => $response->{$_}\n" foreach keys %$response;
185 if ( $response->{UMstatus} =~ /^Approved/ ) {
186 $self->is_success(1);
187 $self->authorization($response->{UMauthCode});
189 $self->is_success(0);
191 $self->order_number($response->{UMrefNum});
192 $self->avs_code($response->{UMavsResultCode});
193 $self->cvv2_response($response->{UMcvv2ResultCode});
194 $self->result_code($response->{UMresult});
195 $self->error_message($response->{UMerror});
196 $self->server_response($response);
204 Business::OnlinePayment::USAePay - USA ePay backend for Business::OnlinePayment
208 use Business::OnlinePayment;
210 my $tx = new Business::OnlinePayment("USAePay");
212 login => 'igztOatyqbpd1wsxijl4xnxjodldwdxR', #USA ePay source key
213 action => 'Normal Authorization',
214 description => 'Business::OnlinePayment test',
216 invoice_number => '100100',
217 name => 'Tofu Beast',
218 card_number => '46464646464646',
219 expiration => '11/08',
220 address => '1234 Bean Curd Lane, San Francisco',
225 if($tx->is_success()) {
226 print "Card processed successfully: ".$tx->authorization."\n";
228 print "Card was rejected: ".$tx->error_message."\n";
233 For detailed information see L<Business::OnlinePayment>.
239 This module implements USAePay's CGI Gateway API v2.9.5. See
240 http://www.usaepay.com/topics/api.html for details.
244 Jeff Finucane <jeff@cmh.net>
248 perl(1). L<Business::OnlinePayment>.