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 push @required_fields, qw/card_number expiration amount name address zip/;
101 if ($self->{_content}->{action} eq 'postauth') {
102 push @required_fields, qw/authorization/;
104 if ( $self->{_content}->{action} eq 'void'
105 || $self->{_content}->{action} eq 'capture') {
106 push @required_fields, qw/order_number/;
108 }elsif ($self->transaction_type() eq 'ECHECK' ) {
109 # push @required_fields, qw/routing_code account_number amount invoice_number name customer_ssn/;
110 push @required_fields, qw/routing_code account_number amount name customer_ssn/;
112 croak("USAePay can't handle transaction type: ".
113 $self->transaction_type());
116 $self->required_fields(@required_fields);
118 my %post_data = $self->get_fields( map "$_", qw(
119 UMcommand UMkey UMmd5hash UMmd5key UMauthCode UMrefNum UMcard UMexpir
120 UMrouting UMaccount UMamount Umtax UMnontaxable UMtip UMshipping
121 UMdiscount UMsubtotal UMcustid UMinvoice UMorderid UMponum UMdescription
122 UMcvv2 UMcustemail UMcustreceipt UMname UMStreet UMzip UMssn UMdlnum
123 UMdlstate UMclerk UMterminal UMtable UMip UMsoftware UMredir
124 UMredirApproved UMredirDeclined UMechofields UMtestmode
126 $post_data{'UMtestmode'} = $self->test_transaction() ? 1 : 0;
127 $post_data{'UMsoftware'} = __PACKAGE__. " $VERSION";
129 warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data;
132 my($page,$server_response) = $self->https_post(%post_data);
134 warn "response page: $page\n";
138 if ($server_response =~ /200/){
139 $response = {map { split '=', $_, 2 } split '&', $page};
141 $response->{UMstatus} = 'Error';
142 $response->{UMerror} = $server_response;
145 $response->{$_} =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg
146 foreach keys %$response;
149 warn "response:$_ => $response->{$_}\n" foreach keys %$response;
152 if ( $response->{UMstatus} =~ /^Approved/ ) {
153 $self->is_success(1);
154 $self->authorization($response->{UMauthCode});
156 $self->is_success(0);
158 $self->result_code($response->{UMresult});
159 $self->error_message($response->{UMerror});
160 $self->server_response($response);
168 Business::OnlinePayment::USAePay - USA ePay backend for Business::OnlinePayment
172 use Business::OnlinePayment;
174 my $tx = new Business::OnlinePayment("USAePay");
176 login => 'igztOatyqbpd1wsxijl4xnxjodldwdxR', #USA ePay source key
177 action => 'Normal Authorization',
178 description => 'Business::OnlinePayment test',
180 invoice_number => '100100',
181 name => 'Tofu Beast',
182 card_number => '46464646464646',
183 expiration => '11/08',
184 address => '1234 Bean Curd Lane, San Francisco',
189 if($tx->is_success()) {
190 print "Card processed successfully: ".$tx->authorization."\n";
192 print "Card was rejected: ".$tx->error_message."\n";
197 For detailed information see L<Business::OnlinePayment>.
203 This module implements USAePay's CGI Gateway API v2.9.5. See
204 http://www.usaepay.com/topics/api.html for details.
208 Jeff Finucane <jeff@cmh.net>
212 perl(1). L<Business::OnlinePayment>.