1 package Business::OnlinePayment::eSelectPlus;
6 use Business::OnlinePayment 3;
7 use Business::OnlinePayment::HTTPS 0.03;
8 use vars qw($VERSION $DEBUG @ISA);
10 @ISA = qw(Business::OnlinePayment::HTTPS);
18 #$self->server('esplusqa.moneris.com'); # development
19 $self->server('esplus.moneris.com'); # production
20 $self->path('/gateway_us/servlet/MpgRequest');
23 ##$self->server('esqa.moneris.com'); # development
24 #$self->server('www3.moneris.com'); # production
25 #$self->path('/gateway2/servlet/MpgRequest');
29 $self->build_subs(qw( order_number avs_code ));
30 # avs_code order_type md5 cvv2_response cavv_response
36 if ( $self->{_content}{'currency'} eq 'CAD' ) {
37 $self->server('www3.moneris.com');
38 $self->path('/gateway2/servlet/MpgRequest');
39 } else { #sorry, default to USD
40 $self->server('esplus.moneris.com');
41 $self->path('/gateway_us/servlet/MpgRequest');
44 if ($self->test_transaction) {
45 if ( $self->{_content}{'currency'} eq 'CAD' ) {
46 $self->server('esqa.moneris.com');
47 $self->{_content}{'login'} = 'store2'; # store[123]
48 $self->{_content}{'password'} = 'yesguy';
49 } else { #sorry, default to USD
50 $self->server('esplusqa.moneris.com');
51 $self->{_content}{'login'} = 'monusqa002'; # monusqa00[123]
52 $self->{_content}{'password'} = 'qatoken';
56 # BOP field => eSelectPlus field
60 # => 'transaction_type',
62 #password => 'api_token',
82 invoice_number => 'cust_id',
83 #customer_id => 'cust_id',
84 order_number => 'order_id', # must be unique number
85 authorization => 'txn_number' # reference to previous trans
90 my $action = $self->{_content}{'action'};
91 if ( $self->{_content}{'action'} =~ /^\s*normal\s*authorization\s*$/i ) {
93 } elsif ( $self->{_content}{'action'} =~ /^\s*authorization\s*only\s*$/i ) {
95 } elsif ( $self->{_content}{'action'} =~ /^\s*post\s*authorization\s*$/i ) {
96 $action = 'completion';
97 } elsif ( $self->{_content}{'action'} =~ /^\s*void\s*$/i ) {
99 } elsif ( $self->{_content}{'action'} =~ /^\s*credit\s*$/i ) {
100 if ( $self->{_content}{'authorization'} ) {
103 $action = 'ind_refund';
107 if ( $action =~ /^(purchase|preauth|ind_refund)$/ ) {
109 $self->required_fields(
110 qw( login password amount card_number expiration )
113 #cardexpiremonth & cardexpireyear
114 $self->{_content}{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/
115 or croak "unparsable expiration ". $self->{_content}{expiration};
116 my( $month, $year ) = ( $1, $2 );
117 $month = '0'. $month if $month =~ /^\d$/;
118 $self->{_content}{expdate} = $year.$month;
120 $self->generate_order_id;
122 $self->{_content}{amount} = sprintf('%.2f', $self->{_content}{amount} );
124 } elsif ( $action eq 'completion' || $action eq 'void' ) {
126 $self->required_fields( qw( login password order_number authorization ) );
128 } elsif ( $action eq 'refund' ) {
130 $self->required_fields(
131 qw( login password order_number authorization )
136 # E-Commerce Indicator (see eSelectPlus docs)
137 $self->{_content}{'crypt_type'} ||= 7;
139 $action = "us_$action" unless $self->{_content}{'currency'} eq 'CAD';
141 #no, values aren't escaped for XML. their "mpgClasses.pl" example doesn't
142 #appear to do so, i dunno
143 tie my %fields, 'Tie::IxHash', $self->get_fields( $self->fields );
145 '<?xml version="1.0"?>'.
147 '<store_id>'. $self->{_content}{'login'}. '</store_id>'.
148 '<api_token>'. $self->{_content}{'password'}. '</api_token>'.
150 join('', map "<$_>$fields{$_}</$_>", keys %fields ).
154 warn "POSTING: ".$post_data if $DEBUG > 1;
156 my( $page, $response, @reply_headers) = $self->https_post( $post_data );
158 #my %reply_headers = @reply_headers;
159 #warn join('', map { " $_ => $reply_headers{$_}\n" } keys %reply_headers )
162 if ($response !~ /^200/) {
164 $response =~ s/[\r\n]+/ /g; # ensure single line
165 $self->is_success(0);
166 my $diag_message = $response || "connection error";
171 # avs_code - eSELECTplus_Perl_IG.pdf Appendix F
172 my %avsTable = ('A' => 'A',
189 my $AvsResultCode = $self->GetXMLProp($page, 'AvsResultCode');
190 $self->avs_code( defined($AvsResultCode) && exists $avsTable{$AvsResultCode}
191 ? $avsTable{$AvsResultCode}
195 #md5 cvv2_response cavv_response ...?
197 $self->server_response($page);
199 my $result = $self->GetXMLProp($page, 'ResponseCode');
201 die "gateway error: ". $self->GetXMLProp( $page, 'Message' )
202 if $result =~ /^null$/i;
204 # New unique reference created by the gateway
205 $self->order_number($self->GetXMLProp($page, 'ReferenceNum'));
206 # Original order_id supplied to the gateway
207 #$self->order_number($self->GetXMLProp($page, 'ReceiptId'));
209 # We (Whizman & DonorWare) do not have enough info about "ISO"
210 # response codes to make use of them.
211 # There may be good reasons why the ISO codes could be preferable,
212 # but we would need more information. For now, the ResponseCode.
213 # $self->result_code( $self->GetXMLProp( $page, 'ISO' ) );
214 $self->result_code( $result );
216 if ( $result =~ /^\d+$/ && $result < 50 ) {
217 $self->is_success(1);
218 $self->authorization($self->GetXMLProp($page, 'AuthCode'));
219 } elsif ( $result =~ /^\d+$/ ) {
220 $self->is_success(0);
221 my $tmp_msg = $self->GetXMLProp( $page, 'Message' );
222 $tmp_msg =~ s/\s{2,}//g;
223 $tmp_msg =~ s/[\*\=]//g;
224 $self->error_message( $tmp_msg );
226 die "unparsable response received from gateway (response $result)".
227 ( $DEBUG ? ": $page" : '' );
232 use vars qw(@oidset);
233 @oidset = ( 'A'..'Z', '0'..'9' );
234 sub generate_order_id {
236 #generate an order_id if order_number not passed
237 unless ( exists ($self->{_content}{order_id})
238 && defined($self->{_content}{order_id})
239 && length ($self->{_content}{order_id})
241 $self->{_content}{'order_id'} =
242 join('', map { $oidset[int(rand(scalar(@oidset)))] } (1..23) );
249 #order is important to this processor
264 my( $self, $raw, $prop ) = @_;
268 ($data) = $raw =~ m"<$prop>(.*?)</$prop>"gsi;
269 #$data =~ s/<.*?>/ /gs;
280 Business::OnlinePayment::eSelectPlus - Moneris eSelect Plus backend module for Business::OnlinePayment
284 use Business::OnlinePayment;
287 # One step transaction, the simple case.
290 my $tx = new Business::OnlinePayment("eSelectPlus");
293 login => 'eSelect Store ID,
294 password => 'eSelect API Token',
295 action => 'Normal Authorization',
296 description => 'Business::OnlinePayment test',
298 currency => 'USD', #or CAD for compatibility with previous releases
299 name => 'Tofu Beast',
300 address => '123 Anystreet',
304 phone => '420-867-5309',
305 email => 'tofu.beast@example.com',
306 card_number => '4005550000000019',
307 expiration => '08/06',
308 cvv2 => '1234', #optional
312 if($tx->is_success()) {
313 print "Card processed successfully: ".$tx->authorization."\n";
315 print "Card was rejected: ".$tx->error_message."\n";
317 print "AVS code: ". $tx->avs_code. "\n"; # Y - Address and ZIP match
318 # A - Address matches but not ZIP
319 # Z - ZIP matches but not address
321 # E - AVS error or unsupported
322 # R - Retry (timeout)
323 # (empty) - not verified
325 =head1 SUPPORTED TRANSACTION TYPES
327 =head2 CC, Visa, MasterCard, American Express, Discover
329 Content required: type, login, password, action, amount, card_number, expiration.
336 Net::SSLeay _or_ ( Crypt::SSLeay and LWP )
340 For detailed information see L<Business::OnlinePayment>.
342 =head1 Note for Canadian merchants upgrading to 0.03
344 As of version 0.03, this module now defaults to the US Moneris. Make sure to
345 pass currency=>'CAD' for Canadian transactions.
349 Ivan Kohler <ivan-eselectplus@420.am>
350 Randall Whitman <www.whizman.com>
354 perl(1). L<Business::OnlinePayment>.