s/CHECK/ECHECK/, DOH
[Business-OnlinePayment-OpenECHO.git] / OpenECHO.pm
1 ##############################################################################\r
2 # Business::OnlinePayment::OpenECHO\r
3 #\r
4 # Credit card transactions via SSL to\r
5 # Electronic Clearing House (ECHO) Systems\r
6 #\r
7 # Refer to ECHO's documentation for more info\r
8 # http://www.openecho.com/echo_gateway_guide.html\r
9 #\r
10 # AUTHOR\r
11 # Michael Lehmkuhl <michael@electricpulp.com>\r
12 #\r
13 # SPECIAL THANKS\r
14 # Jim Darden <jdarden@echo-inc.com>\r
15 # Dan Browning <db@kavod.com>\r
16 #\r
17 # BUSINESS::ONLINEPAYMENT IMPLEMENTATION\r
18 # Ivan Kohler <ivan-openecho@420.am>\r
19 #\r
20 # VERSION HISTORY\r
21 # + v1.2        08/17/2002 Corrected problem with certain string comparisons.\r
22 # + v1.3        08/23/2002 Converted Interchange GlobalSub to Vend::Payment module.\r
23 # + v1.3.1      11/12/2002 Updated the OpenECHO_example.perl test script.\r
24 # + v1.4        11/18/2002 Corrected a problem with Submit method when using LWP.\r
25 # + v1.5        03/29/2003 Updated for additional status and avs_result codes.\r
26 # + v1.6        08/26/2003 Cleaned up code (salim qadeer sqadeer@echo-inc.com)\r
27 # + v1.6.2      09/23/2003 Added DH transaction type (salim qadeer sqadeer@echo-inc.com)\r
28 # --------\r
29 # + v0.1        08/26/2004 Business::OnlinePayment implementation\r
30 # + v0.2        09/13/2004\r
31 # + v0.3        unreleased\r
32 #\r
33 # Copyright (C) 2002 Electric Pulp. <info@electricpulp.com>\r
34 # Copyright (C) 2004 Ivan Kohler\r
35 #\r
36 # This program is free software; you can redistribute it and/or modify\r
37 # it under the terms of the GNU General Public License as published by\r
38 # the Free Software Foundation; either version 2 of the License, or\r
39 # (at your option) any later version.\r
40 #\r
41 # This program is distributed in the hope that it will be useful,\r
42 # but WITHOUT ANY WARRANTY; without even the implied warranty of\r
43 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
44 # GNU General Public License for more details.\r
45 #\r
46 # You should have received a copy of the GNU General Public\r
47 # License along with this program; if not, write to the Free\r
48 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,\r
49 # MA  02111-1307  USA.\r
50 #\r
51 ################################################################################\r
52 \r
53 package Business::OnlinePayment::OpenECHO;\r
54 \r
55 use strict;\r
56 use Carp;\r
57 use Business::OnlinePayment 3;\r
58 use Business::OnlinePayment::HTTPS;\r
59 use vars qw($VERSION @ISA $DEBUG);\r
60 \r
61 @ISA = qw(Business::OnlinePayment::HTTPS);\r
62 $VERSION = '0.03';\r
63 $DEBUG = 0;\r
64 \r
65 sub set_defaults {\r
66         my $self = shift;\r
67 \r
68         $self->server('wwws.echo-inc.com');\r
69         $self->port('443');\r
70         $self->path('/scripts/INR200.EXE');\r
71 \r
72         $self->build_subs(qw(\r
73           order_number avs_code\r
74                          ));\r
75         # order_type\r
76         # md5 cvv2_response cavv_response\r
77 \r
78 }\r
79 \r
80 #map_fileds originally from AuthorizeNet.pm\r
81 \r
82 sub map_fields {\r
83     my($self) = @_;\r
84 \r
85     ##AD (Address Verification)  - 0.18 cents\r
86     #AS (Authorization) - 0.18 cents\r
87     #AV (Authorization with Address Verification) - 0.18 cents\r
88     #CR (Credit) - 0.18 cents + 0.12 cents (discount fee returned to merchant)\r
89     #DS (Deposit) - 0.18 cents + 0.12 cents\r
90     #ES (Authorization and Deposit) - 0.18 cents + 0.12 cents + an extra 0.17%\r
91     #EV (Authorization and Deposit with Address Verification) - 0.18 cents + 0.12 cents\r
92     ##CK (System check) - 0.18 cents\r
93     #DV (Electronic Check Verification) - check your contract\r
94     #DD (Electronic Check Debit with Verification) - check your contract\r
95     #DH (Electronic Check Debit ACH Only) - check your contract\r
96     #DC (Electronic Check Credit) - check your contract\r
97 \r
98     my %content = $self->content();\r
99 \r
100     if ( lc($content{'action'}) eq 'void' ) {\r
101       $self->is_success(0);\r
102       $self->error_message( 'OpenECHO gateway does not support voids; '.\r
103                             'try action => "Credit" '\r
104                           );\r
105       return;\r
106     }\r
107 \r
108     my $avs = $self->require_avs;\r
109     $avs = 1 unless defined($avs) && length($avs); #default AVS on unless explicitly turned off\r
110 \r
111     my %map;\r
112     if (\r
113       $content{'type'} =~ /^(cc|visa|mastercard|american express|discover)$/i\r
114     ) {\r
115       if ( $avs ) {\r
116         %map = ( 'normal authorization' => 'EV',\r
117                  'authorization only'   => 'AV',\r
118                  'credit'               => 'CR',\r
119                  'post authorization'   => 'DS',\r
120                  #'void'                 => 'VOID',\r
121                );\r
122       } else {\r
123         %map = ( 'normal authorization' => 'ES',\r
124                  'authorization only'   => 'AS',\r
125                  'credit'               => 'CR',\r
126                  'post authorization'   => 'DS',\r
127                  #'void'                 => 'VOID',\r
128                );\r
129       }\r
130     } elsif ( $content{'type'} =~ /^e?check$/i ) {\r
131       %map = ( 'normal authorization' => 'DD',\r
132                'authorization only'   => 'DV',\r
133                'credit'               => 'DC',\r
134                'post authorization'   => 'DH',\r
135                #'void'                 => 'VOID',\r
136              );\r
137     } else {\r
138       croak 'Unknown type: '. $content{'type'};\r
139     }\r
140 \r
141     $content{'type'} = $map{lc($content{'action'})}\r
142       or croak 'Unknown action: '. $content{'action'};\r
143 \r
144     $self->transaction_type($content{'type'});\r
145 \r
146     # stuff it back into %content\r
147     $self->content(%content);\r
148 \r
149 }\r
150 \r
151 sub submit {\r
152     my($self) = @_;\r
153 \r
154     $self->map_fields();\r
155     $self->remap_fields(\r
156         #                => 'order_type',\r
157         type             => 'transaction_type',\r
158         #action          =>\r
159         login            => 'merchant_echo_id',\r
160         password         => 'merchant_pin',\r
161         #                => 'isp_echo_id',\r
162         #                => 'isp_pin',\r
163         #transaction_key =>\r
164         authorization    => 'authorization', # auth_code => 'authorization',\r
165         customer_ip      => 'billing_ip_address',\r
166         #                   'billing_prefix',\r
167         name             => 'billing_name',\r
168         first_name       => 'billing_first_name',\r
169         last_name        => 'billing_last_name',\r
170         company          => 'billing_company_name',\r
171         address          => 'billing_address_1',\r
172         #                => 'billing_address_2',\r
173         city             => 'billing_city',\r
174         state            => 'billing_state',\r
175         zip              => 'billing_zip',\r
176         country          => 'billing_country',\r
177         phone            => 'billing_phone',\r
178         fax              => 'billing_fax',\r
179         email            => 'billing_email',\r
180         card_number      => 'cc_number',\r
181         #                => 'ccexp_month',\r
182         #                => 'ccexp_year',\r
183         #                => 'counter',\r
184         #                => 'debug',\r
185 \r
186         #XXX#            => 'ec_*',\r
187 \r
188         'amount'         => 'grand_total',\r
189         #                => 'merchant_email',\r
190         #invoice_number  =>\r
191         customer_id      => 'merchant_trace_nbr',\r
192         #                => 'original_amount',\r
193         #                => 'original_trandate_mm',\r
194         #                => 'original_trandate_dd',\r
195         #                => 'original_trandate_yyyy',\r
196         #                => 'original_reference',\r
197         order_number     => 'order_number',\r
198         #                => 'shipping_flag',\r
199 \r
200         #description       =>\r
201         #currency          =>\r
202 \r
203         #ship_last_name    =>\r
204         #ship_first_name   =>\r
205         #ship_company      =>\r
206         #ship_address      =>\r
207         #ship_city         =>\r
208         #ship_state        =>\r
209         #ship_zip          =>\r
210         #ship_country      =>\r
211 \r
212         #expiration        =>\r
213         cvv2              => 'cnp_security',\r
214 \r
215         #check_type        =>\r
216         #account_name      => 'ec_last_name' & 'ec_first_name',\r
217         account_number    => 'ec_account',\r
218         #account_type      =>\r
219         bank_name         => 'ec_bank_name',\r
220         routing_code      => 'ec_rt',\r
221         #customer_org      =>\r
222         #customer_ssn      =>\r
223         license_num       => 'ec_id_number',\r
224         license_state     => 'ec_id_state',\r
225         #license_dob       =>\r
226         payee             => 'ec_payee',\r
227         check_number      => 'ec_serial_number',\r
228 \r
229         #recurring_billing => 'cnp_recurring',\r
230     );\r
231 \r
232     #XXX hosted order_type?\r
233     $self->{_content}{order_type} = 'S';\r
234 \r
235     #XXX counter field shouldn't be just a random integer (but it does need a\r
236     #default this way i guess...\r
237     $self->{_content}{counter} = int(rand(2**31));\r
238     \r
239     if ( $self->transaction_type =~ /^[EA][VS]$/ ) {\r
240       #ccexp_month & ccexp_year\r
241       $self->{_content}{'expiration'} =~ /^(\d+)\D+\d*(\d{2})$/\r
242         or croak "unparsable expiration ". $self->{_content}{expiration};\r
243       my( $month, $year ) = ( $1, $2 );\r
244       $month = '0'. $month if $month =~ /^\d$/;\r
245       $self->{_content}{ccexp_month} = $month;\r
246       $self->{_content}{ccexp_year} = $year;\r
247     }\r
248 \r
249     $self->{_content}{cnp_recurring} = 'Y'\r
250       if exists($self->{_content}{recurring_billing})\r
251       && $self->{_content}{recurring_billing} =~ /^y/i;\r
252 \r
253     #XXX echeck use customer_org and account_type to generate ec_account_type\r
254 \r
255     #XXX set required fields\r
256     # https://wwws.echo-inc.com/ISPGuide-Fields2.asp\r
257     $self->required_fields();\r
258 \r
259     my( $page, $response, %reply_headers) =\r
260       $self->https_post( $self->get_fields( $self->fields ) );\r
261 \r
262     warn "raw echo response: $page" if $DEBUG;\r
263 \r
264     #XXX check $response and die if not 200?\r
265 \r
266     my $echotype1 = $self->GetEchoReturn($page, 1);\r
267     my $echotype2 = $self->GetEchoReturn($page, 2);\r
268     my $echotype3 = $self->GetEchoReturn($page, 3);\r
269     my $openecho  = $self->GetEchoReturn($page, 'OPEN');\r
270 \r
271     #   server_response\r
272     #   avs_code\r
273     #   order_number\r
274     #   is_success\r
275     #   result_code\r
276     #   authorization\r
277     #md5 cvv2_response cavv_response ...?\r
278 \r
279     # Get all the metadata.\r
280     $self->server_response($page);\r
281     $self->authorization( $self->GetEchoProp($echotype3, 'auth_code') );\r
282     $self->order_number(  $self->GetEchoProp($echotype3, 'order_number') );\r
283 \r
284     #XXX ???\r
285     #$self->reference(     $this->GetEchoProp($echotype3, "echo_reference");\r
286 \r
287     $self->result_code(   $self->GetEchoProp($echotype3, 'status') );\r
288     $self->avs_code(      $self->GetEchoProp($echotype3, 'avs_result') );\r
289 \r
290     #XXX ???\r
291     #$self->security_result( $self->GetEchoProp($echotype3, 'security_result');\r
292     #$self->mac( $self->GetEchoProp($echotype3, 'mac') );\r
293     #$self->decline_code( $self->GetEchoProp($echotype3, 'decline_code') );\r
294 \r
295     if ($self->result_code =~ /^[GR]$/ ) { #success\r
296 \r
297       #XXX special case for AVS-only transactions we don't handle yet\r
298       #if ($self->transaction_type eq "AD") {\r
299       #  if ($self->avs_code =~ /^[XYDM]$/ ) {\r
300       #    $self->is_success(1);\r
301       #  } else {\r
302       #    $self->is_success(0);\r
303       #  }\r
304       #} else { \r
305         $self->is_success(1);\r
306       #}\r
307 \r
308     } else {\r
309       $self->is_success(0);\r
310 \r
311       my $decline_code = $self->GetEchoProp($echotype3, 'decline_code');\r
312       my $error_message = $self->error($decline_code);\r
313       if ( $decline_code =~ /^(00)?30$/ ) {\r
314         $echotype2 =~ s/<br>/\n/ig;\r
315         $echotype2 =~ s'</?(b|pre)>''ig;\r
316         $error_message .= ": $echotype2";\r
317       }\r
318       $self->error_message( $error_message );\r
319 \r
320     }\r
321 \r
322     $self->is_success(0) if $page eq '';\r
323 \r
324 }\r
325 \r
326 \r
327 sub fields {\r
328         my $self = shift;\r
329 \r
330         my @fields = qw(\r
331           order_type\r
332           transaction_type\r
333           merchant_echo_id\r
334           merchant_pin\r
335           isp_echo_id\r
336           isp_pin\r
337           authorization\r
338           billing_ip_address\r
339           billing_prefix\r
340           billing_name\r
341           billing_first_name\r
342           billing_last_name\r
343           billing_company_name\r
344           billing_address1\r
345           billing_address2\r
346           billing_city\r
347           billing_state\r
348           billing_zip\r
349           billing_country\r
350           billing_phone\r
351           billing_fax\r
352           billing_email\r
353           cc_number\r
354           ccexp_month\r
355           ccexp_year\r
356           counter\r
357           debug\r
358         );\r
359 \r
360         if ($self->transaction_type =~ /^D[DCVH]$/) {\r
361           push @fields, qw(\r
362             ec_account\r
363             ec_account_type\r
364             ec_payment_type\r
365             ec_address1\r
366             ec_address2\r
367             ec_bank_name\r
368             ec_business_acct\r
369             ec_city\r
370             ec_email\r
371             ec_first_name\r
372             ec_id_country\r
373             ec_id_exp_mm\r
374             ec_id_exp_dd\r
375             ec_id_exp_yy\r
376             ec_id_number\r
377             ec_id_state\r
378             ec_id_type\r
379             ec_last_name\r
380             ec_merchant_ref\r
381             ec_nbds_code\r
382             ec_other_name\r
383             ec_payee\r
384             ec_rt\r
385             ec_serial_number\r
386             ec_state\r
387             ec_transaction_dt\r
388             ec_zip\r
389           );\r
390         }\r
391 \r
392         push @fields, qw(\r
393           grand_total\r
394           merchant_email\r
395           merchant_trace_nbr\r
396           original_amount\r
397           original_trandate_mm\r
398           original_trandate_dd\r
399           original_trandate_yyyy\r
400           original_reference\r
401           order_number\r
402           shipping_flag\r
403           shipping_prefix\r
404           shipping_name\r
405           shipping_address1\r
406           shipping_address2\r
407           shipping_city\r
408           shipping_state\r
409           shipping_zip\r
410           shipping_comments\r
411           shipping_country\r
412           shipping_phone\r
413           shipping_fax\r
414           shipper\r
415           shipper_tracking_nbr\r
416           track1\r
417           track2\r
418           cnp_security\r
419           cnp_recurring\r
420         );\r
421 \r
422         return @fields;\r
423 }\r
424 \r
425 sub GetEchoProp {\r
426         my( $self, $raw, $prop ) = @_;\r
427         local $^W=0;\r
428 \r
429         my $data;\r
430         ($data) = $raw =~ m"<$prop>(.*?)</$prop>"gsi;\r
431         $data =~ s/<.*?>/ /gs;\r
432         chomp $data;\r
433         return $data;\r
434 }\r
435 \r
436 # Get's a given Echo return type and strips all HTML style tags from it.\r
437 # It also strips any new line characters from the returned string.\r
438 #\r
439 # This function based on Ben Reser's <breser@vecdev.com> Echo::Process\r
440 # module.\r
441 sub GetEchoReturn {\r
442         my( $self, $page, $type ) = @_;\r
443         local $^W=0;\r
444 \r
445         my $data;\r
446         if ($type eq 'OPEN') {\r
447                 ($data) = $page =~ m"<OPENECHO>(.*?)</OPENECHO>"gsi;\r
448         }\r
449         else {\r
450                 ($data) = $page =~ m"<ECHOTYPE$type>(.*?)</ECHOTYPE$type>"gsi;\r
451         }\r
452 #       $data =~ s"<.*?>" "g;\r
453 \r
454         #unless (length($data)) {\r
455         #  warn "$self $page $type";\r
456         #}\r
457 \r
458         chomp $data;\r
459         return $data;\r
460 }\r
461 \r
462 use vars qw(%error);\r
463 %error = (\r
464   "01" => [ "Refer to card issuer", "The merchant must call the issuer before the transaction can be approved." ],\r
465   "02" => [ "Refer to card issuer, special condition", "The merchant must call the issuer before the transaction can be approved." ],\r
466   "03" => [ "Invalid merchant number", "The merchant ID is not valid." ],\r
467   "04" => [ "Pick-up card. Capture for reward", "The card is listed on the Warning Bulletin.  Merchant may receive reward money by capturing the card." ],\r
468   "05" => [ "Do not honor. The transaction was declined by the issuer without definition or reason", "The transaction was declined without explanation by the card issuer." ],\r
469   "06" => [ "Error", "The card issuer returned an error without further explanation." ],\r
470   "07" => [ "Pick-up card, special condition", "The card is listed on the Warning Bulletin.  Merchant may receive reward money by capturing the card." ],\r
471   "08" => [ "Honor with identification", "Honor with identification." ],\r
472   "09" => [ "Request in progress", "Request in progress." ],\r
473   "10" => [ "Approved for partial amount", "Approved for partial amount." ],\r
474   "11" => [ "Approved, VIP", "Approved, VIP program." ],\r
475   "12" => [ "Invalid transaction", "The requested transaction is not supported or is not valid for the card number presented." ],\r
476   "13" => [ "Invalid amount", "The amount exceeds the limits established by the issuer for this type of transaction." ],\r
477   "14" => [ "Invalid card #", "The issuer indicates that this card is not valid." ],\r
478   "15" => [ "No such issuer", "The card issuer number is not valid." ],\r
479   "16" => [ "Approved, update track 3", "Approved, update track 3." ],\r
480   "17" => [ "Customer cancellation", "Customer cancellation." ],\r
481   "18" => [ "Customer dispute", "Customer dispute." ],\r
482   "19" => [ "Re enter transaction", "Customer should resubmit transaction." ],\r
483   "20" => [ "Invalid response", "Invalid response." ],\r
484   "21" => [ "No action taken", "No action taken. The issuer declined with no other explanation." ],\r
485   "22" => [ "Suspected malfunction", "Suspected malfunction." ],\r
486   "23" => [ "Unacceptable transaction fee", "Unacceptable transaction fee." ],\r
487   "24" => [ "File update not supported", "File update not supported." ],\r
488   "25" => [ "Unable to locate record", "Unable to locate record." ],\r
489   "26" => [ "Duplicate record", "Duplicate record." ],\r
490   "27" => [ "File update edit error", "File update edit error." ],\r
491   "28" => [ "File update file locked", "File update file locked." ],\r
492   "30" => [ "Format error, call ECHO", "The host reported that the transaction was not formatted properly." ],\r
493   "31" => [ "Bank not supported", "Bank not supported by switch." ],\r
494   "32" => [ "Completed partially", "Completed partially." ],\r
495   "33" => [ "Expired card, pick-up", "The card is expired.  Merchant may receive reward money by capturing the card." ],\r
496   "34" => [ "Issuer suspects fraud, pick-up card", "The card issuer suspects fraud.  Merchant may receive reward money by capturing the card." ],\r
497   "35" => [ "Contact acquirer, pick-up", "Contact card issuer.  Merchant may receive reward money by capturing the card." ],\r
498   "36" => [ "Restricted card, pick-up", "The card is restricted by the issuer.  Merchant may receive reward money by capturing the card." ],\r
499   "37" => [ "Call ECHO security, pick-up", "Contact ECHO security.  Merchant may receive reward money by capturing the card." ],\r
500   "38" => [ "PIN tries exceeded, pick-up", "PIN attempts exceed issuer limits.  Merchant may receive reward money by capturing the card." ],\r
501   "39" => [ "No credit account", "No credit account." ],\r
502   "40" => [ "Function not supported", "Requested function not supported." ],\r
503   "41" => [ "Lost Card, capture for reward", "The card has been reported lost." ],\r
504   "42" => [ "No universal account", "No universal account." ],\r
505   "43" => [ "Stolen Card, capture for reward", "The card has been reported stolen." ],\r
506   "44" => [ "No investment account", "No investment account." ],\r
507   "51" => [ "Not sufficient funds", "The credit limit for this account has been exceeded." ],\r
508   "54" => [ "Expired card", "The card is expired." ],\r
509   "55" => [ "Incorrect PIN", "The cardholder PIN is incorrect." ],\r
510   "56" => [ "No card record", "No card record." ],\r
511   "57" => [ "Transaction not permitted to cardholder", "The card is not allowed the type of transaction requested." ],\r
512   "58" => [ "Transaction not permitted on terminal", "The Merchant is not allowed this type of transaction." ],\r
513   "59" => [ "Suspected fraud", "Suspected fraud." ],\r
514   "60" => [ "Contact ECHO", "Contact ECHO." ],\r
515   "61" => [ "Exceeds withdrawal limit", "The amount exceeds the allowed daily maximum." ],\r
516   "62" => [ "Restricted card", "The card has been restricted." ],\r
517   "63" => [ "Security violation.", "The card has been restricted." ],\r
518   "64" => [ "Original amount incorrect", "Original amount incorrect." ],\r
519   "65" => [ "Exceeds withdrawal frequency", "The allowable number of daily transactions has been exceeded." ],\r
520   "66" => [ "Call acquirer security, call ECHO", "Call acquirer security, call ECHO." ],\r
521   "68" => [ "Response received too late", "Response received too late." ],\r
522   "75" => [ "PIN tries exceeded", "The allowed number of PIN retries has been exceeded." ],\r
523   "76" => [ "Invalid \"to\" account", "The debit account does not exist." ],\r
524   "77" => [ "Invalid \"from\" account", "The credit account does not exist." ],\r
525   "78" => [ "Invalid account specified (general)", "The associated card number account is invalid or does not exist." ],\r
526   "79" => [ "Already reversed", "Already reversed." ],\r
527   "84" => [ "Invalid authorization life cycle", "The authorization life cycle is invalid." ],\r
528   "86" => [ "Cannot verify PIN", "Cannot verify PIN." ],\r
529   "87" => [ "Network Unavailable", "Network Unavailable." ],\r
530   "89" => [ "Ineligible to receive financial position information", "Ineligible to receive financial position information." ],\r
531   "90" => [ "Cut-off in progress", "Cut-off in progress." ],\r
532   "91" => [ "Issuer or switch inoperative", "The bank is not available to authorize this transaction." ],\r
533   "92" => [ "Routing error", "The transaction cannot be routed to the authorizing agency." ],\r
534   "93" => [ "Violation of law", "Violation of law." ],\r
535   "94" => [ "Duplicate transaction", "Duplicate transaction." ],\r
536   "95" => [ "Reconcile error", "Reconcile error." ],\r
537   "96" => [ "System malfunction", "A system error has occurred." ],\r
538   "98" => [ "Exceeds cash limit", "Exceeds cash limit." ],\r
539   "1000" => [ "Unrecoverable error.", "An unrecoverable error has occurred in the ECHONLINE processing." ],\r
540   "1001" => [ "Account closed", "The merchant account has been closed." ],\r
541   "1002" => [ "System closed", "Services for this system are not available. (Not used by ECHONLINE)" ],\r
542   "1003" => [ "E-Mail Down", "The e-mail function is not available. (Not used by ECHONLINE)" ],\r
543   "1012" => [ "Invalid trans code", "The host computer received an invalid transaction code." ],\r
544   "1013" => [ "Invalid term id", "The ECHO-ID is invalid." ],\r
545   "1015" => [ "Invalid card number", "The credit card number that was sent to the host computer was invalid" ],\r
546   "1016" => [ "Invalid expiry date", "The card has expired or the expiration date was invalid." ],\r
547   "1017" => [ "Invalid amount", "The dollar amount was less than 1.00 or greater than the maximum allowed for this card." ],\r
548   "1019" => [ "Invalid state", "The state code was invalid. (Not used by ECHONLINE)" ],\r
549   "1021" => [ "Invalid service", "The merchant or card holder is not allowed to perform that kind of transaction" ],\r
550   "1024" => [ "Invalid auth code", "The authorization number presented with this transaction is incorrect. (deposit transactions only)" ],\r
551   "1025" => [ "Invalid reference number", "The reference number presented with this transaction is incorrect or is not numeric." ],\r
552   "1029" => [ "Invalid contract number", "The contract number presented with this transaction is incorrect or is not numeric. (Not used by ECHONLINE)" ],\r
553   "1030" => [ "Invalid inventory data", "The inventory data presented with this transaction is not ASCII \"printable\". (Not used by ECHONLINE)" ],\r
554   "1508" => [ " ", "Invalid or missing order_type." ],\r
555   "1509" => [ " ", "The merchant is not approved to submit this order_type." ],\r
556   "1510" => [ " ", "The merchant is not approved to submit this transaction_type." ],\r
557   #"1511" => [ " ", "Duplicate transaction attempt (see counterin Part I of this Specification</EM>)." ],\r
558   "1511" => [ " ", "Duplicate transaction attempt (set counter field?)." ],\r
559   "1599" => [ " ", "An system error occurred while validating the transaction input." ],\r
560   "1801" => [ "Return Code \"A\"", "Address matches; ZIP does not match." ],\r
561   "1802" => [ "Return Code \"W\"", "9-digit ZIP matches; Address does not match." ],\r
562   "1803" => [ "Return Code \"Z\"", "5-digit ZIP matches; Address does not match." ],\r
563   "1804" => [ "Return Codes \"U\"", "Issuer unavailable; cannot verify." ],\r
564   "1805" => [ "Return Code \"R\"", "Retry; system is currently unable to process." ],\r
565   "1806" => [ "Return Code \"S\" or \"G\"", "Issuer does not support AVS." ],\r
566   "1807" => [ "Return Code \"N\"", "Nothing matches." ],\r
567   "1808" => [ "Return Code \"E\"", "Invalid AVS only response." ],\r
568   "1809" => [ "Return Code \"B\"", "Street address match. Postal code not verified because of incompatible formats." ],\r
569   "1810" => [ "Return Code \"C\"", "Street address and Postal code not verified because of incompatible formats." ],\r
570   "1811" => [ "Return Code \"D\"", "Street address match and Postal code match." ],\r
571   "1812" => [ "Return Code \"I\"", "Address information not verified for international transaction." ],\r
572   "1813" => [ "Return Code \"M\"", "Street address match and Postal code match." ],\r
573   "1814" => [ "Return Code \"P\"", "Postal code match. Street address not verified because of incompatible formats." ],\r
574   "1897" => [ "invalid response", "The host returned an invalid response." ],\r
575   "1898" => [ "disconnect", "The host unexpectedly disconnected." ],\r
576   "1899" => [ "timeout", "Timeout waiting for host response." ],\r
577   "2071" => [ "Call VISA", "An authorization number from the VISA Voice Center is required to approve this transaction." ],\r
578   "2072" => [ "Call Master Card", "An authorization number from the Master Card Voice Center is required to approve this transaction." ],\r
579   "2073" => [ "Call Carte Blanche", "An authorization number from the Carte Blanche Voice Center is required to approve this transaction." ],\r
580   "2074" => [ "Call Diners Club", "An authorization number from the Diners' Club Voice Center is required to approve this transaction." ],\r
581   "2075" => [ "Call AMEX", "An authorization number from the American Express Voice Center is required to approve this transaction." ],\r
582   "2076" => [ "Call Discover", "An authorization number from the Discover Voice Center is required to approve this transaction." ],\r
583   "2078" => [ "Call ECHO", "The merchant must call ECHOCustomer Support for approval.or because there is a problem with the merchant's account." ],\r
584   "2079" => [ "Call XpresscheX", "The merchant must call ECHOCustomer Support for approval.or because there is a problem with the merchant's account." ],\r
585   "3001" => [ "No ACK on Resp", "The host did not receive an ACK from the terminal after sending the transaction response." ],\r
586   "3002" => [ "POS NAK'd 3 Times", "The host disconnected after the terminal replied 3 times to the host response with a NAK." ],\r
587   "3003" => [ "Drop on Wait", "The line dropped before the host could send a response to the terminal." ],\r
588   "3005" => [ "Drop on Resp", "The line dropped while the host was sending the response to the terminal." ],\r
589   "3007" => [ "Drop Before EOT", "The host received an ACK from the terminal but the line dropped before the host could send the EOT." ],\r
590   "3011" => [ "No Resp to ENQ", "The line was up and carrier detected, but the terminal did not respond to the ENQ." ],\r
591   "3012" => [ "Drop on Input", "The line disconnected while the host was receiving data from the terminal." ],\r
592   "3013" => [ "FEP NAK'd 3 Times", "The host disconnected after receiving 3 transmissions with incorrect LRC from the terminal." ],\r
593   "3014" => [ "No Resp to ENQ", "The line disconnected during input data wait in Multi-Trans Mode." ],\r
594   "3015" => [ "Drop on Input", "The host encountered a full queue and discarded the input data." ],\r
595 );\r
596 for ( 9000..9999 ) {\r
597   $error{$_} = [ "Host Error", "The host encountered an internal error and was not able to process the transaction." ]; \r
598 }\r
599 sub error {\r
600   my( $self, $num ) = @_;\r
601   $num =~ s/^00(\d\d)$/$1/;\r
602   return $num. ': '. $error{$num}[0]. ': '. $error{$num}[1];\r
603 }\r
604 \r
605 1;\r
606 \r
607 __END__\r
608 \r
609 =head1 NAME\r
610 \r
611 Business::OnlinePayment::OpenECHO - ECHO backend module for Business::OnlinePayment\r
612 \r
613 =head1 SYNOPSIS\r
614 \r
615   use Business::OnlinePayment;\r
616 \r
617   ####\r
618   # One step transaction, the simple case.\r
619   ####\r
620 \r
621   my $tx = new Business::OnlinePayment("OpenECHO");\r
622   $tx->content(\r
623       type           => 'VISA',\r
624       login          => '1234684752',\r
625       password       => '43400210',\r
626       action         => 'Normal Authorization',\r
627       description    => 'Business::OnlinePayment test',\r
628       amount         => '49.95',\r
629       invoice_number => '100100',\r
630       customer_id    => 'jsk',\r
631       first_name     => 'Tofu',\r
632       last_name      => 'Beast',\r
633       address        => '123 Anystreet',\r
634       city           => 'Anywhere',\r
635       state          => 'UT',\r
636       zip            => '84058',\r
637       card_number    => '4005550000000019',\r
638       expiration     => '08/06',\r
639       cvv2           => '1234', #optional\r
640       referer        => 'http://valid.referer.url/',\r
641   );\r
642   $tx->submit();\r
643 \r
644   if($tx->is_success()) {\r
645       print "Card processed successfully: ".$tx->authorization."\n";\r
646   } else {\r
647       print "Card was rejected: ".$tx->error_message."\n";\r
648   }\r
649 \r
650 =head1 SUPPORTED TRANSACTION TYPES\r
651 \r
652 =head2 CC, Visa, MasterCard, American Express, Discover\r
653 \r
654 Content required: type, login, password, action, amount, first_name, last_name, card_number, expiration.\r
655 \r
656 =head2 Check\r
657 \r
658 Not yet implemented...\r
659 #Content required: type, login, password, action, amount, first_name, last_name, account_number, routing_code, bank_name.\r
660 \r
661 =head1 PREREQUISITES\r
662 \r
663   URI::Escape\r
664   Tie::IxHash\r
665 \r
666   Net::SSLeay _or_ ( Crypt::SSLeay and LWP )\r
667 \r
668 =head1 DESCRIPTION\r
669 \r
670 For detailed information see L<Business::OnlinePayment>.\r
671 \r
672 =head1 AUTHOR\r
673 \r
674 Original Author\r
675 Michael Lehmkuhl <michael@electricpulp.com>\r
676 \r
677 Special Thanks\r
678 Jim Darden <jdarden@echo-inc.com>\r
679 Dan Browning <db@kavod.com>\r
680 \r
681 Business::OnlinePayment Implementation\r
682 Ivan Kohler <ivan-openecho@420.am>\r
683 \r
684 =head1 SEE ALSO\r
685 \r
686 perl(1). L<Business::OnlinePayment>.\r
687 \r
688 =cut\r
689 \r