1 package Business::OnlinePayment::eWay;
5 use Business::OnlinePayment 3;
6 use Business::OnlinePayment::HTTPS;
7 use Business::CreditCard;
9 use vars qw($VERSION @ISA $DEBUG);
11 @ISA = qw(Business::OnlinePayment::HTTPS);
16 my $default_path = '/gateway/xmlpayment.asp';
17 my $default_cvn_path = '/gateway_cvn/xmlpayment.asp';
18 my $default_test_path = '/gateway/xmltest/testpage.asp';
19 my $default_cvn_test_path = '/gateway_cvn/xmltest/testpage.asp';
23 $self->server('www.eway.com.au');
25 $self->path($default_path);
30 my %content = $self->content();
32 $content{$_} = ref($map{$_})
34 : (exists($content{$map{$_}})
39 $self->content(%content);
43 my($self,@fields) = @_;
45 my %content = $self->content();
47 foreach( grep defined $content{$_}, @fields) { $new{$_} = $content{$_}; }
53 my %content = $self->content;
55 my $action = lc($content{'action'});
56 die 'eSec only supports "Normal Authorization" transactions'
57 unless $action eq 'normal authorization';
59 $content{'expiration'} =~ /^(\d+)\D+(\d+)$/
60 or croak "unparsable expiration $content{expiration}";
61 my ($month, $year) = ( $1, $2 );
63 $year %= 100; #not y2.1k safe
65 $content{'amount'} =~ /^(\d+\.+\d{0,2})$/
66 or croak "unparsable amount $content{amount}";
69 my $address = $content{'address'} if exists $content{'address'};
70 $address .= $content{'city'} if exists $content{'city'};
71 $address .= $content{'state'} if exists $content{'state'};
75 ewayCustomerID => 'login',
76 ewayTotalAmount => \$amount,
77 ewayCustomerFirstName => 'first_name',
78 ewayCustomerLastName => 'last_name',
79 ewayCustomerEmail => 'email',
80 ewayCustomerAddress => \$address,
81 ewayCustomerPostcode => 'zip',
82 ewayCustomerInvoiceDescription => 'description',
83 ewayCustomerInvoiceRef => 'invoice_number',
84 ewayCardHoldersName => 'name',
85 ewayCardNumber => 'card_number',
86 ewayCardExpiryMonth => \$month,
87 ewayCardExpiryYear => \$year,
88 ewayTrxnNumber => 'transaction_number',
89 ewayOption1 => 'option1',
90 ewayOption2 => 'option1',
91 ewayOption3 => 'option1',
94 %content = $self->content;
96 warn "content:$_ => $content{$_}\n" foreach keys %content;
99 if ($self->transaction_type() eq 'CC' ) {
100 $self->required_fields(qw/action login amount name card_number expiration/);
102 croak("eWay can't handle transaction type: ".
103 $self->transaction_type());
106 my %post_data = $self->get_fields( map "$_", qw(
107 ewayCustomerID ewayTotalAmount ewayCustomerFirstName ewayCustomerLastName
108 ewayCustomerEmail ewayCustomerAddress ewayCustomerPostcode
109 ewayCustomerInvoiceDescription ewayCustomerInvoiceRef ewayCardHoldersName
110 ewayCardNumber ewayCardExpiryMonth ewayCardExpiryYear ewayTrxnNumber
111 ewayOption1 ewayOption2 ewayOption3 ewayCVN
114 warn "post_data:$_ => $post_data{$_}\n" foreach keys %post_data;
117 my $pd = XMLout({%post_data}, 'NoAttr' => 1, 'RootName' => 'ewaygateway');
121 my $oldpath = $self->path;
122 if ($post_data{ewayCVN} && $self->path eq $default_path){
123 $self->path($default_cvn_path);
125 if ($self->test_transaction) {
126 if ($self->path eq $default_path) {
127 $self->path($default_test_path);
128 }elsif ($self->path eq $default_cvn_path){
129 $self->path($default_cvn_test_path);
131 croak "Test mode not supported for path: " . $self->path . "\n";
135 my($page,$server_response) = $self->https_post($pd);
136 $self->path($oldpath);
142 if ($server_response =~ /200/){
143 $response = XMLin($page);
145 $response->{ewayTrxnError} = $server_response;
148 if ( $response->{ewayTrxnStatus} =~ /^True/ ) {
149 $self->is_success(1);
150 $self->authorization($response->{ewayAuthCode});
152 $self->is_success(0);
154 $self->error_message($response->{ewayTrxnError});
155 $self->server_response($response);
163 Business::OnlinePayment::eWay - eWay backend for Business::OnlinePayment
167 use Business::OnlinePayment;
169 my $tx = new Business::OnlinePayment("eWay");
171 login => '87654321', #ewayCustomerID
172 action => 'Normal Authorization',
173 description => 'Business::OnlinePayment test',
175 invoice_number => '100100',
176 name => 'Tofu Beast',
177 card_number => '46464646464646',
178 expiration => '11/08',
182 if($tx->is_success()) {
183 print "Card processed successfully: ".$tx->authorization."\n";
185 print "Card was rejected: ".$tx->error_message."\n";
190 For detailed information see L<Business::OnlinePayment>.
196 This module implements eWay's XML API. See
197 http://www.eway.com.au/support/xml.aspx for details.
201 Jeff Finucane <jeff@cmh.net>
205 perl(1). L<Business::OnlinePayment>.