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);
16 my $default_path = '/gate.php';
17 my $default_cert_path = '/secure/gate.php';
21 $self->server('www.usaepay.com');
23 $self->path($default_path);
25 $self->build_subs(qw(order_number));
31 my %content = $self->content();
33 my %types = ('visa' => 'CC',
35 'american express' => 'CC',
39 $content{'type'} = $types{lc($content{'type'})} || $content{'type'};
40 $self->transaction_type($content{'type'});
43 my %cc_actions = ('normal authorization' => 'sale',
44 'authorization only' => 'authonly',
45 'post authorization' => 'postauth',
47 my %ec_actions = ('normal authorization' => 'check',
48 'credit' => 'checkcredit',
50 if ($content{'type'} eq 'CC') {
51 (%actions) = (%cc_actions);
52 }elsif ($content{'type'} eq 'ECHECK') {
53 (%actions) = (%ec_actions);
55 $content{'action'} = $actions{lc($content{'action'})} || $content{'action'};
57 $content{'expiration'} =~ s/\D//g;
59 $content{'md5hash'} = md5_hex(join(':', map "$content{$_}", qw(action password amount invoice_number md5key))) if defined $content{'password'};
61 $self->content(%content);
72 md5hash => 'UMmd5hash',
73 card_number => 'UMcard',
74 expiration => 'UMexpir',
76 invoice_number => 'UMinvoice',
77 description => 'UMdescription',
78 customer_id => 'UMcustid',
80 email => 'UMcustemail',
82 address => 'UMstreet',
84 customer_ip => 'UMip',
85 order_number => 'UMrefNum',
86 authorization => 'UMauthCode',
87 routing_code => 'UMrouting',
88 account_number => 'UMaccount',
89 customer_ssn => 'UMssn',
91 my %content = $self->content;
93 warn "content:$_ => $content{$_}\n" foreach keys %content;
96 my @required_fields = qw(type action login);
98 if ($self->transaction_type() eq 'CC' ) {
99 push @required_fields, qw/card_number expiration amount invoice_number name address zip/;
100 if ($self->{_content}->{action} eq 'postauth') {
101 push @required_fields, qw/authorization/;
103 if ( $self->{_content}->{action} eq 'void'
104 || $self->{_content}->{action} eq 'capture') {
105 push @required_fields, qw/order_number/;
107 }elsif ($self->transaction_type() eq 'ECHECK' ) {
108 push @required_fields, qw/routing_code account_number amount invoice_number name customer_ssn/;
110 croak("USAePay can't handle transaction type: ".
111 $self->transaction_type());
114 $self->required_fields(@required_fields);
116 my %post_data = $self->get_fields( map "$_", qw(
117 UMcommand UMkey UMmd5hash UMmd5key UMauthCode UMrefNum UMcard UMexpir
118 UMrouting UMaccount UMamount Umtax UMnontaxable UMtip UMshipping
119 UMdiscount UMsubtotal UMcustid UMinvoice UMorderid UMponum UMdescription
120 UMcvv2 UMcustemail UMcustreceipt UMname UMStreet UMzip UMssn UMdlnum
121 UMdlstate UMclerk UMterminal UMtable UMip UMsoftware UMredir
122 UMredirApproved UMredirDeclined UMechofields UMtestmode
124 $post_data{'UMtestmode'} = $self->test_transaction() ? 1 : 0;
125 $post_data{'UMsoftware'} = __PACKAGE__. " $VERSION";
127 warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data;
130 my($page,$server_response) = $self->https_post(%post_data);
132 warn "response page: $page\n";
136 if ($server_response =~ /200/){
137 $response = {map { split '=', $_, 2 } split '&', $page};
139 $response->{UMstatus} = 'Error';
140 $response->{UMerror} = $server_response;
143 $response->{$_} =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg
144 foreach keys %$response;
147 warn "response:$_ => $response->{$_}\n" foreach keys %$response;
150 if ( $response->{UMstatus} =~ /^Approved/ ) {
151 $self->is_success(1);
152 $self->authorization($response->{UMauthCode});
154 $self->is_success(0);
156 $self->result_code($response->{UMresult});
157 $self->error_message($response->{UMerror});
158 $self->server_response($response);
166 Business::OnlinePayment::USAePay - USA ePay backend for Business::OnlinePayment
170 use Business::OnlinePayment;
172 my $tx = new Business::OnlinePayment("USAePay");
174 login => 'igztOatyqbpd1wsxijl4xnxjodldwdxR', #USA ePay source key
175 action => 'Normal Authorization',
176 description => 'Business::OnlinePayment test',
178 invoice_number => '100100',
179 name => 'Tofu Beast',
180 card_number => '46464646464646',
181 expiration => '11/08',
182 address => '1234 Bean Curd Lane, San Francisco',
187 if($tx->is_success()) {
188 print "Card processed successfully: ".$tx->authorization."\n";
190 print "Card was rejected: ".$tx->error_message."\n";
195 For detailed information see L<Business::OnlinePayment>.
201 This module implements USAePay's CGI Gateway API v2.9.5. See
202 http://www.usaepay.com/topics/api.html for details.
206 Jeff Finucane <jeff@cmh.net>
210 perl(1). L<Business::OnlinePayment>.