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 ( defined( $self->{_content}{'currency'} )
37 && $self->{_content}{'currency'} eq 'CAD' ) {
38 $self->server('www3.moneris.com');
39 $self->path('/gateway2/servlet/MpgRequest');
40 } else { #sorry, default to USD
41 $self->server('esplus.moneris.com');
42 $self->path('/gateway_us/servlet/MpgRequest');
45 if ($self->test_transaction) {
46 if ( defined( $self->{_content}{'currency'} )
47 && $self->{_content}{'currency'} eq 'CAD' ) {
48 $self->server('esqa.moneris.com');
49 $self->{_content}{'login'} = 'store2'; # store[123]
50 $self->{_content}{'password'} = 'yesguy';
51 } else { #sorry, default to USD
52 $self->server('esplusqa.moneris.com');
53 $self->{_content}{'login'} = 'monusqa002'; # monusqa00[123]
54 $self->{_content}{'password'} = 'qatoken';
58 # BOP field => eSelectPlus field
62 # => 'transaction_type',
64 #password => 'api_token',
84 invoice_number => 'cust_id',
85 #customer_id => 'cust_id',
86 order_number => 'order_id', # must be unique number
87 authorization => 'txn_number' # reference to previous trans
92 my $action = $self->{_content}{'action'};
93 if ( $self->{_content}{'action'} =~ /^\s*normal\s*authorization\s*$/i ) {
95 } elsif ( $self->{_content}{'action'} =~ /^\s*authorization\s*only\s*$/i ) {
97 } elsif ( $self->{_content}{'action'} =~ /^\s*post\s*authorization\s*$/i ) {
98 $action = 'completion';
99 } elsif ( $self->{_content}{'action'} =~ /^\s*void\s*$/i ) {
100 $action = 'purchasecorrection';
101 } elsif ( $self->{_content}{'action'} =~ /^\s*credit\s*$/i ) {
102 if ( $self->{_content}{'authorization'} ) {
105 $action = 'ind_refund';
109 if ( $action =~ /^(purchase|preauth|ind_refund)$/ ) {
111 $self->required_fields(
112 qw( login password amount card_number expiration )
115 #cardexpiremonth & cardexpireyear
116 $self->{_content}{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/
117 or croak "unparsable expiration ". $self->{_content}{expiration};
118 my( $month, $year ) = ( $1, $2 );
119 $month = '0'. $month if $month =~ /^\d$/;
120 $self->{_content}{expdate} = $year.$month;
122 $self->generate_order_id;
124 $self->{_content}{amount} = sprintf('%.2f', $self->{_content}{amount} );
126 } elsif ( $action eq 'completion' || $action eq 'purchasecorrection' ) {
128 $self->{_content}{comp_amount} = delete $self->{_content}{amount}
129 if $action eq 'completion';
131 $self->required_fields( qw( login password order_number authorization ) );
133 } elsif ( $action eq 'refund' ) {
135 $self->required_fields(
136 qw( login password order_number authorization )
141 # E-Commerce Indicator (see eSelectPlus docs)
142 $self->{_content}{'crypt_type'} ||= 7;
144 $action = "us_$action"
145 unless defined( $self->{_content}{'currency'} )
146 && $self->{_content}{'currency'} eq 'CAD';
148 #no, values aren't escaped for XML. their "mpgClasses.pl" example doesn't
149 #appear to do so, i dunno
150 tie my %fields, 'Tie::IxHash', $self->get_fields( $self->fields );
152 '<?xml version="1.0"?>'.
154 '<store_id>'. $self->{_content}{'login'}. '</store_id>'.
155 '<api_token>'. $self->{_content}{'password'}. '</api_token>'.
157 join('', map "<$_>$fields{$_}</$_>", keys %fields ).
161 warn "POSTING: ".$post_data if $DEBUG > 1;
163 my( $page, $response, @reply_headers) = $self->https_post( $post_data );
166 my %reply_headers = @reply_headers;
167 warn join('', map { " $_ => $reply_headers{$_}\n" } keys %reply_headers)
170 if ($response !~ /^200/) {
172 $response =~ s/[\r\n]+/ /g; # ensure single line
173 $self->is_success(0);
174 my $diag_message = $response || "connection error";
178 # avs_code - eSELECTplus_Perl_IG.pdf Appendix F
179 my %avsTable = ('A' => 'A',
196 my $AvsResultCode = $self->GetXMLProp($page, 'AvsResultCode');
197 $self->avs_code( defined($AvsResultCode) && exists $avsTable{$AvsResultCode}
198 ? $avsTable{$AvsResultCode}
202 #md5 cvv2_response cavv_response ...?
204 $self->server_response($page);
206 my $result = $self->GetXMLProp($page, 'ResponseCode');
208 die "gateway error: ". $self->GetXMLProp( $page, 'Message' )
209 if $result =~ /^null$/i;
211 # Original order_id supplied to the gateway
212 $self->order_number($self->GetXMLProp($page, 'ReceiptId'));
214 # We (Whizman & DonorWare) do not have enough info about "ISO"
215 # response codes to make use of them.
216 # There may be good reasons why the ISO codes could be preferable,
217 # but we would need more information. For now, the ResponseCode.
218 # $self->result_code( $self->GetXMLProp( $page, 'ISO' ) );
219 $self->result_code( $result );
221 if ( $result =~ /^\d+$/ && $result < 50 ) {
222 $self->is_success(1);
223 $self->authorization($self->GetXMLProp($page, 'TransID'));
224 } elsif ( $result =~ /^\d+$/ ) {
225 $self->is_success(0);
226 my $tmp_msg = $self->GetXMLProp( $page, 'Message' );
227 $tmp_msg =~ s/\s{2,}//g;
228 $tmp_msg =~ s/[\*\=]//g;
229 $self->error_message( $tmp_msg );
231 die "unparsable response received from gateway (response $result)".
232 ( $DEBUG ? ": $page" : '' );
237 use vars qw(@oidset);
238 @oidset = ( 'A'..'Z', '0'..'9' );
239 sub generate_order_id {
241 #generate an order_id if order_number not passed
242 unless ( exists ($self->{_content}{order_id})
243 && defined($self->{_content}{order_id})
244 && length ($self->{_content}{order_id})
246 $self->{_content}{'order_id'} =
247 join('', map { $oidset[int(rand(scalar(@oidset)))] } (1..23) );
254 #order is important to this processor
269 my( $self, $raw, $prop ) = @_;
273 ($data) = $raw =~ m"<$prop>(.*?)</$prop>"gsi;
274 #$data =~ s/<.*?>/ /gs;
285 Business::OnlinePayment::eSelectPlus - Moneris eSelect Plus backend module for Business::OnlinePayment
289 use Business::OnlinePayment;
292 # One step transaction, the simple case.
295 my $tx = new Business::OnlinePayment("eSelectPlus");
298 login => 'eSelect Store ID,
299 password => 'eSelect API Token',
300 action => 'Normal Authorization',
301 description => 'Business::OnlinePayment test',
303 currency => 'USD', #or CAD for compatibility with previous releases
304 name => 'Tofu Beast',
305 address => '123 Anystreet',
309 phone => '420-867-5309',
310 email => 'tofu.beast@example.com',
311 card_number => '4005550000000019',
312 expiration => '08/06',
313 cvv2 => '1234', #optional
317 if($tx->is_success()) {
318 print "Card processed successfully: ".$tx->authorization."\n";
320 print "Card was rejected: ".$tx->error_message."\n";
322 print "AVS code: ". $tx->avs_code. "\n"; # Y - Address and ZIP match
323 # A - Address matches but not ZIP
324 # Z - ZIP matches but not address
326 # E - AVS error or unsupported
327 # R - Retry (timeout)
328 # (empty) - not verified
330 =head1 SUPPORTED TRANSACTION TYPES
332 =head2 CC, Visa, MasterCard, American Express, Discover
334 Content required: type, login, password, action, amount, card_number, expiration.
341 Net::SSLeay _or_ ( Crypt::SSLeay and LWP )
345 For detailed information see L<Business::OnlinePayment>.
349 =head2 Note for Canadian merchants upgrading to 0.03
351 As of version 0.03, this module now defaults to the US Moneris. Make sure to
352 pass currency=>'CAD' for Canadian transactions.
354 =head2 Note for upgrading to 0.05
356 As of version 0.05, the bank authorization code is discarded (AuthCode),
357 so that authorization() and order_number() can return the 2 fields needed
358 for capture. See also
359 cpansearch.perl.org/src/IVAN/Business-OnlinePayment-3.02/notes_for_module_writers_v3
363 Ivan Kohler <ivan-eselectplus@420.am>
364 Randall Whitman L<whizman.com|http://whizman.com>
368 perl(1). L<Business::OnlinePayment>.