X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=USAePay.pm;h=a8eb4ee913645aacd4e7a935039f6b23ac5c1769;hb=c964be9bd8ed5cef5f51f8b4ded15fe626ee51d6;hp=0ebaf579ae79c43a17ffc901379098bd9fed071f;hpb=08916d3727cd4d463c06b2e595b4e38b3dcb358a;p=Business-OnlinePayment-USAePay.git diff --git a/USAePay.pm b/USAePay.pm index 0ebaf57..a8eb4ee 100644 --- a/USAePay.pm +++ b/USAePay.pm @@ -9,9 +9,32 @@ use URI::Escape; use vars qw($VERSION @ISA $DEBUG); @ISA = qw(Business::OnlinePayment::HTTPS); -$VERSION = '0.01'; - -$DEBUG = 1; +$VERSION = '0.03'; + +$DEBUG = 0; + +sub _info { + { + 'info_compat' => '0.01', + 'gateway_name' => 'USAePay', + 'gateway_url' => 'http://www.usaepay.com', + 'module_version' => $VERSION, + 'supported_types' => [ 'CC', 'ECHECK' ], + 'supported_actions' => { + CC => [ + 'Normal Authorization', + 'Authorization Only', + 'Post Authorization', + 'Credit', + 'Void', + ], + ECHECK => [ + 'Normal Authorization', + 'Credit', + ], + }, + }; +} my $default_path = '/gate.php'; my $default_cert_path = '/secure/gate.php'; @@ -21,8 +44,8 @@ sub set_defaults { $self->server('www.usaepay.com'); $self->port('443'); $self->path($default_path); + $self->build_subs(qw(avs_code cvv2_response)); - $self->build_subs(qw(order_number)); } sub map_fields { @@ -43,6 +66,8 @@ sub map_fields { my %cc_actions = ('normal authorization' => 'sale', 'authorization only' => 'authonly', 'post authorization' => 'postauth', + 'credit' => 'credit', + 'void' => 'void', ); my %ec_actions = ('normal authorization' => 'check', 'credit' => 'checkcredit', @@ -54,9 +79,12 @@ sub map_fields { } $content{'action'} = $actions{lc($content{'action'})} || $content{'action'}; - $content{'expiration'} =~ s/\D//g; + $content{'expiration'} =~ s/\D//g if exists $content{'expiration'}; - $content{'md5hash'} = md5_hex(join(':', map "$content{$_}", qw(action password amount invoice_number md5key))) if defined $content{'password'}; + $content{'md5hash'} = + md5_hex( join(':', map { defined($content{$_}) ? $content{$_} : '' } + qw(action password amount invoice_number md5key))) + if defined $content{'password'}; $self->content(%content); } @@ -87,6 +115,7 @@ sub submit { routing_code => 'UMrouting', account_number => 'UMaccount', customer_ssn => 'UMssn', + action => 'UMcommand', ); my %content = $self->content; if ( $DEBUG ) { @@ -95,17 +124,21 @@ sub submit { my @required_fields = qw(type action login); + my $action = $self->{_content}->{action}; 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') { + if ($action eq 'void' or $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 { + # sale, authonly, credit, postauth + push @required_fields, qw/card_number expiration amount address zip/; + if ($action eq 'postauth') { + push @required_fields, qw/authorization/; + } + } + } + elsif ($self->transaction_type() eq 'ECHECK' ) { + push @required_fields, qw/routing_code account_number amount name customer_ssn/; } else { croak("USAePay can't handle transaction type: ". $self->transaction_type()); @@ -121,7 +154,15 @@ sub submit { UMdlstate UMclerk UMterminal UMtable UMip UMsoftware UMredir UMredirApproved UMredirDeclined UMechofields UMtestmode ) ); - $post_data{'UMtestmode'} = $self->test_transaction() ? 1 : 0; + + # test_transaction(0): normal mode + # 1 : test mode (validates formatting only) + # 2 : use sandbox server + # 3 : test mode on sandbox server + my $test = $self->test_transaction || 0; + $self->server('sandbox.usaepay.com') if ( $test & 2 ); + $post_data{'UMtestmode'} = ($test & 1) ? 1 : 0; + $post_data{'UMsoftware'} = __PACKAGE__. " $VERSION"; if ( $DEBUG ) { warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data; @@ -143,7 +184,7 @@ sub submit { $response->{$_} =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg foreach keys %$response; - if ( 1 || $DEBUG ) { + if ( $DEBUG ) { warn "response:$_ => $response->{$_}\n" foreach keys %$response; } @@ -153,6 +194,9 @@ sub submit { } else { $self->is_success(0); } + $self->order_number($response->{UMrefNum}); + $self->avs_code($response->{UMavsResultCode}); + $self->cvv2_response($response->{UMcvv2ResultCode}); $self->result_code($response->{UMresult}); $self->error_message($response->{UMerror}); $self->server_response($response); @@ -171,7 +215,8 @@ Business::OnlinePayment::USAePay - USA ePay backend for Business::OnlinePayment my $tx = new Business::OnlinePayment("USAePay"); $tx->content( - login => 'igztOatyqbpd1wsxijl4xnxjodldwdxR', #USA ePay source key + login => 'igztOatyqbpd1wsxijl4xnxjodldwdxR', #USAePay source key + password => 'abcdef', #USAePay PIN action => 'Normal Authorization', description => 'Business::OnlinePayment test', amount => '49.95', @@ -194,20 +239,36 @@ Business::OnlinePayment::USAePay - USA ePay backend for Business::OnlinePayment For detailed information see L. -=head1 NOTE - =head1 COMPATIBILITY -This module implements USAePay's CGI Gateway API v2.9.5. See +This module was developed against USAePay's CGI Gateway API v2.9.5 and +also tested against v2.17.1 without problems. See http://www.usaepay.com/topics/api.html for details. =head1 AUTHOR -Jeff Finucane +Original author: Jeff Finucane + +0.02 update and current maintainer: Ivan Kohler + +=head1 COPYRIGHT & LICENSE + +Copyright (C) 2011 Freeside Internet Services, Inc. (http://freeside.biz/) + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + +=head1 ADVERTISEMENT + +Need a complete, open-source back-office and customer self-service solution? +The Freeside software includes support for credit card and electronic check +processing with USAePay and over 50 other gateways, invoicing, integrated +trouble ticketing, and customer signup and self-service web interfaces. + +http://freeside.biz/freeside/ =head1 SEE ALSO perl(1). L. =cut -