1 package Business::OnlinePayment::eSelectPlus;
\r
6 use Business::OnlinePayment 3;
\r
7 use Business::OnlinePayment::HTTPS;
\r
8 use vars qw($VERSION $DEBUG @ISA);
\r
10 @ISA = qw(Business::OnlinePayment::HTTPS);
\r
17 $self->server('esqa.moneris.com');
\r
19 $self->path('/gateway2/servlet/MpgRequest');
\r
21 $self->build_subs(qw( order_number ));
\r
22 # avs_code order_type md5 cvv2_response cavv_response
\r
28 #$self->map_fields();
\r
29 $self->remap_fields(
\r
31 # => 'transaction_type',
\r
32 #login => 'store_id',
\r
33 #password => 'api_token',
\r
48 card_number => 'pan',
\r
52 'amount' => 'amount',
\r
55 order_number => 'order_id',
\r
56 authorization => 'txn_number'
\r
61 my $action = $self->{_content}{'action'};
\r
62 if ( $self->{_content}{'action'} =~ /^\s*normal\s*authorization\s*$/i ) {
\r
63 $action = 'purchase';
\r
64 } elsif ( $self->{_content}{'action'} =~ /^\s*authorization\s*only\s*$/i ) {
\r
65 $action = 'preauth';
\r
66 } elsif ( $self->{_content}{'action'} =~ /^\s*post\s*authorization\s*$/i ) {
\r
67 $action = 'completion';
\r
68 } elsif ( $self->{_content}{'action'} =~ /^\s*void\s*$/i ) {
\r
70 } elsif ( $self->{_content}{'action'} =~ /^\s*credit\s*$/i ) {
\r
71 if ( $self->{_content}{'authorization'} ) {
\r
74 $action = 'ind_refund';
\r
78 if ( $action =~ /^(purchase|preauth|ind_refund)$/ ) {
\r
80 $self->required_fields(
\r
81 qw( login password amount card_number expiration )
\r
84 #cardexpiremonth & cardexpireyear
\r
85 $self->{_content}{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/
\r
86 or croak "unparsable expiration ". $self->{_content}{expiration};
\r
87 my( $month, $year ) = ( $1, $2 );
\r
88 $month = '0'. $month if $month =~ /^\d$/;
\r
89 $self->{_content}{expdate} = $year.$month;
\r
91 $self->generate_order_id;
\r
93 $self->{_content}{amount} = sprintf('%.2f', $self->{_content}{amount} );
\r
95 } elsif ( $action eq 'completion' || $action eq 'void' ) {
\r
97 $self->required_fields( qw( login password order_number authorization ) );
\r
99 } elsif ( $action eq 'refund' ) {
\r
101 $self->required_fields(
\r
102 qw( login passowrd order_number authorization )
\r
107 $self->{_content}{'crypt_type'} ||= 7;
\r
109 #no, values aren't escaped for XML. their "mpgClasses.pl" example doesn't
\r
110 #appear to do so, i dunno
\r
111 tie my %fields, 'Tie::IxHash', $self->get_fields( $self->fields );
\r
113 '<?xml version="1.0"?>'.
\r
115 '<store_id>'. $self->{_content}{'login'}. '</store_id>'.
\r
116 '<api_token>'. $self->{_content}{'password'}. '</api_token>'.
\r
118 join('', map "<$_>$fields{$_}</$_>", keys %fields ).
\r
122 warn $post_data if $DEBUG > 1;
\r
124 my( $page, $response, @reply_headers) = $self->https_post( $post_data );
\r
126 #my %reply_headers = @reply_headers;
\r
127 #warn join('', map { " $_ => $reply_headers{$_}\n" } keys %reply_headers )
\r
130 #XXX check $response and die if not 200?
\r
136 #md5 cvv2_response cavv_response ...?
\r
138 $self->server_response($page);
\r
140 my $result = $self->GetXMLProp($page, 'ResponseCode');
\r
142 die "gateway error: ". $self->GetXMLProp( $page, 'Message' )
\r
143 if $result =~ /^null$/i;
\r
145 if ( $result =~ /^\d+$/ && $result < 50 ) {
\r
146 $self->is_success(1);
\r
147 $self->result_code( $self->GetXMLProp( $page, 'ISO' ) );
\r
148 $self->authorization( $self->GetXMLProp( $page, 'Txn_number' ) );
\r
149 $self->order_number( $self->GetXMLProp( $page, 'order_id') );
\r
150 } elsif ( $result =~ /^\d+$/ ) {
\r
151 $self->is_success(0);
\r
152 $self->error_message( $self->GetXMLProp( $page, 'Message' ) );
\r
154 die "unparsable response received from gateway (response $result)".
\r
155 ( $DEBUG ? ": $page" : '' );
\r
160 use vars qw(@oidset);
\r
161 @oidset = ( 'A'..'Z', '0'..'9' );
\r
162 sub generate_order_id {
\r
164 #generate an order_id if order_number not passed
\r
165 unless ( exists ($self->{_content}{order_id})
\r
166 && defined($self->{_content}{order_id})
\r
167 && length ($self->{_content}{order_id})
\r
169 $self->{_content}{'order_id'} =
\r
170 join('', map { $oidset[int(rand(scalar(@oidset)))] } (1..23) );
\r
177 #order is important to this processor
\r
192 my( $self, $raw, $prop ) = @_;
\r
196 ($data) = $raw =~ m"<$prop>(.*?)</$prop>"gsi;
\r
197 #$data =~ s/<.*?>/ /gs;
\r
208 Business::OnlinePayment::eSelectPlus - Moneris eSelect Plus backend module for Business::OnlinePayment
\r
212 use Business::OnlinePayment;
\r
215 # One step transaction, the simple case.
\r
218 my $tx = new Business::OnlinePayment("eSelectPlus");
\r
221 login => 'eSelect Store ID,
\r
222 password => 'eSelect API Token',
\r
223 action => 'Normal Authorization',
\r
224 description => 'Business::OnlinePayment test',
\r
226 name => 'Tofu Beast',
\r
227 address => '123 Anystreet',
\r
228 city => 'Anywhere',
\r
231 phone => '420-867-5309',
\r
232 email => 'tofu.beast@example.com',
\r
233 card_number => '4005550000000019',
\r
234 expiration => '08/06',
\r
235 cvv2 => '1234', #optional
\r
239 if($tx->is_success()) {
\r
240 print "Card processed successfully: ".$tx->authorization."\n";
\r
242 print "Card was rejected: ".$tx->error_message."\n";
\r
245 =head1 SUPPORTED TRANSACTION TYPES
\r
247 =head2 CC, Visa, MasterCard, American Express, Discover
\r
249 Content required: type, login, password, action, amount, card_number, expiration.
\r
251 =head1 PREREQUISITES
\r
256 Net::SSLeay _or_ ( Crypt::SSLeay and LWP )
\r
260 For detailed information see L<Business::OnlinePayment>.
\r
266 Ivan Kohler <ivan-eselectplus@420.am>
\r
270 perl(1). L<Business::OnlinePayment>.
\r