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->required_fields( qw( login password order_number authorization ) );
130 } elsif ( $action eq 'refund' ) {
132 $self->required_fields(
133 qw( login password order_number authorization )
138 # E-Commerce Indicator (see eSelectPlus docs)
139 $self->{_content}{'crypt_type'} ||= 7;
141 $action = "us_$action"
142 unless defined( $self->{_content}{'currency'} )
143 && $self->{_content}{'currency'} eq 'CAD';
145 #no, values aren't escaped for XML. their "mpgClasses.pl" example doesn't
146 #appear to do so, i dunno
147 tie my %fields, 'Tie::IxHash', $self->get_fields( $self->fields );
149 '<?xml version="1.0"?>'.
151 '<store_id>'. $self->{_content}{'login'}. '</store_id>'.
152 '<api_token>'. $self->{_content}{'password'}. '</api_token>'.
154 join('', map "<$_>$fields{$_}</$_>", keys %fields ).
158 warn "POSTING: ".$post_data if $DEBUG > 1;
160 my( $page, $response, @reply_headers) = $self->https_post( $post_data );
162 #my %reply_headers = @reply_headers;
163 #warn join('', map { " $_ => $reply_headers{$_}\n" } keys %reply_headers )
166 if ($response !~ /^200/) {
168 $response =~ s/[\r\n]+/ /g; # ensure single line
169 $self->is_success(0);
170 my $diag_message = $response || "connection error";
175 # avs_code - eSELECTplus_Perl_IG.pdf Appendix F
176 my %avsTable = ('A' => 'A',
193 my $AvsResultCode = $self->GetXMLProp($page, 'AvsResultCode');
194 $self->avs_code( defined($AvsResultCode) && exists $avsTable{$AvsResultCode}
195 ? $avsTable{$AvsResultCode}
199 #md5 cvv2_response cavv_response ...?
201 $self->server_response($page);
203 my $result = $self->GetXMLProp($page, 'ResponseCode');
205 die "gateway error: ". $self->GetXMLProp( $page, 'Message' )
206 if $result =~ /^null$/i;
208 # New unique reference created by the gateway
209 $self->order_number($self->GetXMLProp($page, 'ReferenceNum'));
210 # Original order_id supplied to the gateway
211 #$self->order_number($self->GetXMLProp($page, 'ReceiptId'));
213 # We (Whizman & DonorWare) do not have enough info about "ISO"
214 # response codes to make use of them.
215 # There may be good reasons why the ISO codes could be preferable,
216 # but we would need more information. For now, the ResponseCode.
217 # $self->result_code( $self->GetXMLProp( $page, 'ISO' ) );
218 $self->result_code( $result );
220 if ( $result =~ /^\d+$/ && $result < 50 ) {
221 $self->is_success(1);
222 $self->authorization($self->GetXMLProp($page, 'AuthCode'));
223 } elsif ( $result =~ /^\d+$/ ) {
224 $self->is_success(0);
225 my $tmp_msg = $self->GetXMLProp( $page, 'Message' );
226 $tmp_msg =~ s/\s{2,}//g;
227 $tmp_msg =~ s/[\*\=]//g;
228 $self->error_message( $tmp_msg );
230 die "unparsable response received from gateway (response $result)".
231 ( $DEBUG ? ": $page" : '' );
236 use vars qw(@oidset);
237 @oidset = ( 'A'..'Z', '0'..'9' );
238 sub generate_order_id {
240 #generate an order_id if order_number not passed
241 unless ( exists ($self->{_content}{order_id})
242 && defined($self->{_content}{order_id})
243 && length ($self->{_content}{order_id})
245 $self->{_content}{'order_id'} =
246 join('', map { $oidset[int(rand(scalar(@oidset)))] } (1..23) );
253 #order is important to this processor
268 my( $self, $raw, $prop ) = @_;
272 ($data) = $raw =~ m"<$prop>(.*?)</$prop>"gsi;
273 #$data =~ s/<.*?>/ /gs;
284 Business::OnlinePayment::eSelectPlus - Moneris eSelect Plus backend module for Business::OnlinePayment
288 use Business::OnlinePayment;
291 # One step transaction, the simple case.
294 my $tx = new Business::OnlinePayment("eSelectPlus");
297 login => 'eSelect Store ID,
298 password => 'eSelect API Token',
299 action => 'Normal Authorization',
300 description => 'Business::OnlinePayment test',
302 currency => 'USD', #or CAD for compatibility with previous releases
303 name => 'Tofu Beast',
304 address => '123 Anystreet',
308 phone => '420-867-5309',
309 email => 'tofu.beast@example.com',
310 card_number => '4005550000000019',
311 expiration => '08/06',
312 cvv2 => '1234', #optional
316 if($tx->is_success()) {
317 print "Card processed successfully: ".$tx->authorization."\n";
319 print "Card was rejected: ".$tx->error_message."\n";
321 print "AVS code: ". $tx->avs_code. "\n"; # Y - Address and ZIP match
322 # A - Address matches but not ZIP
323 # Z - ZIP matches but not address
325 # E - AVS error or unsupported
326 # R - Retry (timeout)
327 # (empty) - not verified
329 =head1 SUPPORTED TRANSACTION TYPES
331 =head2 CC, Visa, MasterCard, American Express, Discover
333 Content required: type, login, password, action, amount, card_number, expiration.
340 Net::SSLeay _or_ ( Crypt::SSLeay and LWP )
344 For detailed information see L<Business::OnlinePayment>.
346 =head1 Note for Canadian merchants upgrading to 0.03
348 As of version 0.03, this module now defaults to the US Moneris. Make sure to
349 pass currency=>'CAD' for Canadian transactions.
353 Ivan Kohler <ivan-eselectplus@420.am>
354 Randall Whitman <www.whizman.com>
358 perl(1). L<Business::OnlinePayment>.