we need B:OP v3, declare so in Makefile.PL
[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        03/25/2006\r
32 #\r
33 # Copyright (C) 2002 Electric Pulp. <info@electricpulp.com>\r
34 # Copyright (C) 2004-2006 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.04';\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         #get from new() args instead# 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     if ( $self->transaction_type =~ /^D[DVCH]$/ ) { #echeck\r
250 \r
251       #check number kludge... "periodic bill payments" don't have check #s!\r
252       #$self->{_content}{ec_serial_number} = 'RECURRIN'\r
253       $self->{_content}{ec_serial_number} = '00000000'\r
254         if ! length($self->{_content}{ec_serial_number})\r
255         && $self->{_content}{ec_payment_type} =~ /^(PPD)?$/i;\r
256 \r
257       ( $self->{_content}{ec_payee} = $self->payee )\r
258         or croak "'payee' option required when instantiating new ".\r
259                  "Business::OnlinePayment::OpenECHO object\n";\r
260     }\r
261 \r
262     $self->{_content}{cnp_recurring} = 'Y'\r
263       if exists($self->{_content}{recurring_billing})\r
264       && $self->{_content}{recurring_billing} =~ /^y/i;\r
265 \r
266     #XXX echeck use customer_org and account_type to generate ec_account_type\r
267 \r
268     #XXX set required fields\r
269     # https://wwws.echo-inc.com/ISPGuide-Fields2.asp\r
270     $self->required_fields();\r
271 \r
272     my( $page, $response, %reply_headers) =\r
273       $self->https_post( $self->get_fields( $self->fields ) );\r
274 \r
275     warn "raw echo response: $page" if $DEBUG;\r
276 \r
277     #XXX check $response and die if not 200?\r
278 \r
279     my $echotype1 = $self->GetEchoReturn($page, 1);\r
280     my $echotype2 = $self->GetEchoReturn($page, 2);\r
281     my $echotype3 = $self->GetEchoReturn($page, 3);\r
282     my $openecho  = $self->GetEchoReturn($page, 'OPEN');\r
283 \r
284     #   server_response\r
285     #   avs_code\r
286     #   order_number\r
287     #   is_success\r
288     #   result_code\r
289     #   authorization\r
290     #md5 cvv2_response cavv_response ...?\r
291 \r
292     # Get all the metadata.\r
293     $self->server_response($page);\r
294     $self->authorization( $self->GetEchoProp($echotype3, 'auth_code') );\r
295     $self->order_number(  $self->GetEchoProp($echotype3, 'order_number') );\r
296 \r
297     #XXX ???\r
298     #$self->reference(     $this->GetEchoProp($echotype3, "echo_reference");\r
299 \r
300     $self->result_code(   $self->GetEchoProp($echotype3, 'status') );\r
301     $self->avs_code(      $self->GetEchoProp($echotype3, 'avs_result') );\r
302 \r
303     #XXX ???\r
304     #$self->security_result( $self->GetEchoProp($echotype3, 'security_result');\r
305     #$self->mac( $self->GetEchoProp($echotype3, 'mac') );\r
306     #$self->decline_code( $self->GetEchoProp($echotype3, 'decline_code') );\r
307 \r
308     if ($self->result_code =~ /^[GR]$/ ) { #success\r
309 \r
310       #XXX special case for AVS-only transactions we don't handle yet\r
311       #if ($self->transaction_type eq "AD") {\r
312       #  if ($self->avs_code =~ /^[XYDM]$/ ) {\r
313       #    $self->is_success(1);\r
314       #  } else {\r
315       #    $self->is_success(0);\r
316       #  }\r
317       #} else { \r
318         $self->is_success(1);\r
319       #}\r
320 \r
321     } else {\r
322       $self->is_success(0);\r
323 \r
324       my $decline_code = $self->GetEchoProp($echotype3, 'decline_code');\r
325       my $error_message = $self->error($decline_code);\r
326       if ( $decline_code =~ /^(00)?30$/ ) {\r
327         $echotype2 =~ s/<br>/\n/ig;\r
328         $echotype2 =~ s'</?(b|pre)>''ig;\r
329         $error_message .= ": $echotype2";\r
330       }\r
331       $self->error_message( $error_message );\r
332 \r
333     }\r
334 \r
335     $self->is_success(0) if $page eq '';\r
336 \r
337 }\r
338 \r
339 \r
340 sub fields {\r
341         my $self = shift;\r
342 \r
343         my @fields = qw(\r
344           order_type\r
345           transaction_type\r
346           merchant_echo_id\r
347           merchant_pin\r
348           isp_echo_id\r
349           isp_pin\r
350           authorization\r
351           billing_ip_address\r
352           billing_prefix\r
353           billing_name\r
354           billing_first_name\r
355           billing_last_name\r
356           billing_company_name\r
357           billing_address1\r
358           billing_address2\r
359           billing_city\r
360           billing_state\r
361           billing_zip\r
362           billing_country\r
363           billing_phone\r
364           billing_fax\r
365           billing_email\r
366           cc_number\r
367           ccexp_month\r
368           ccexp_year\r
369           counter\r
370           debug\r
371         );\r
372 \r
373         if ($self->transaction_type =~ /^D[DCVH]$/) {\r
374           push @fields, qw(\r
375             ec_account\r
376             ec_account_type\r
377             ec_payment_type\r
378             ec_address1\r
379             ec_address2\r
380             ec_bank_name\r
381             ec_business_acct\r
382             ec_city\r
383             ec_email\r
384             ec_first_name\r
385             ec_id_country\r
386             ec_id_exp_mm\r
387             ec_id_exp_dd\r
388             ec_id_exp_yy\r
389             ec_id_number\r
390             ec_id_state\r
391             ec_id_type\r
392             ec_last_name\r
393             ec_merchant_ref\r
394             ec_nbds_code\r
395             ec_other_name\r
396             ec_payee\r
397             ec_rt\r
398             ec_serial_number\r
399             ec_state\r
400             ec_transaction_dt\r
401             ec_zip\r
402           );\r
403         }\r
404 \r
405         push @fields, qw(\r
406           grand_total\r
407           merchant_email\r
408           merchant_trace_nbr\r
409           original_amount\r
410           original_trandate_mm\r
411           original_trandate_dd\r
412           original_trandate_yyyy\r
413           original_reference\r
414           order_number\r
415           shipping_flag\r
416           shipping_prefix\r
417           shipping_name\r
418           shipping_address1\r
419           shipping_address2\r
420           shipping_city\r
421           shipping_state\r
422           shipping_zip\r
423           shipping_comments\r
424           shipping_country\r
425           shipping_phone\r
426           shipping_fax\r
427           shipper\r
428           shipper_tracking_nbr\r
429           track1\r
430           track2\r
431           cnp_security\r
432           cnp_recurring\r
433         );\r
434 \r
435         return @fields;\r
436 }\r
437 \r
438 sub GetEchoProp {\r
439         my( $self, $raw, $prop ) = @_;\r
440         local $^W=0;\r
441 \r
442         my $data;\r
443         ($data) = $raw =~ m"<$prop>(.*?)</$prop>"gsi;\r
444         $data =~ s/<.*?>/ /gs;\r
445         chomp $data;\r
446         return $data;\r
447 }\r
448 \r
449 # Get's a given Echo return type and strips all HTML style tags from it.\r
450 # It also strips any new line characters from the returned string.\r
451 #\r
452 # This function based on Ben Reser's <breser@vecdev.com> Echo::Process\r
453 # module.\r
454 sub GetEchoReturn {\r
455         my( $self, $page, $type ) = @_;\r
456         local $^W=0;\r
457 \r
458         my $data;\r
459         if ($type eq 'OPEN') {\r
460                 ($data) = $page =~ m"<OPENECHO>(.*?)</OPENECHO>"gsi;\r
461         }\r
462         else {\r
463                 ($data) = $page =~ m"<ECHOTYPE$type>(.*?)</ECHOTYPE$type>"gsi;\r
464         }\r
465 #       $data =~ s"<.*?>" "g;\r
466 \r
467         #unless (length($data)) {\r
468         #  warn "$self $page $type";\r
469         #}\r
470 \r
471         chomp $data;\r
472         return $data;\r
473 }\r
474 \r
475 use vars qw(%error);\r
476 %error = (\r
477   "01" => [ "Refer to card issuer", "The merchant must call the issuer before the transaction can be approved." ],\r
478   "02" => [ "Refer to card issuer, special condition", "The merchant must call the issuer before the transaction can be approved." ],\r
479   "03" => [ "Invalid merchant number", "The merchant ID is not valid." ],\r
480   "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
481   "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
482   "06" => [ "Error", "The card issuer returned an error without further explanation." ],\r
483   "07" => [ "Pick-up card, special condition", "The card is listed on the Warning Bulletin.  Merchant may receive reward money by capturing the card." ],\r
484   "08" => [ "Honor with identification", "Honor with identification." ],\r
485   "09" => [ "Request in progress", "Request in progress." ],\r
486   "10" => [ "Approved for partial amount", "Approved for partial amount." ],\r
487   "11" => [ "Approved, VIP", "Approved, VIP program." ],\r
488   "12" => [ "Invalid transaction", "The requested transaction is not supported or is not valid for the card number presented." ],\r
489   "13" => [ "Invalid amount", "The amount exceeds the limits established by the issuer for this type of transaction." ],\r
490   "14" => [ "Invalid card #", "The issuer indicates that this card is not valid." ],\r
491   "15" => [ "No such issuer", "The card issuer number is not valid." ],\r
492   "16" => [ "Approved, update track 3", "Approved, update track 3." ],\r
493   "17" => [ "Customer cancellation", "Customer cancellation." ],\r
494   "18" => [ "Customer dispute", "Customer dispute." ],\r
495   "19" => [ "Re enter transaction", "Customer should resubmit transaction." ],\r
496   "20" => [ "Invalid response", "Invalid response." ],\r
497   "21" => [ "No action taken", "No action taken. The issuer declined with no other explanation." ],\r
498   "22" => [ "Suspected malfunction", "Suspected malfunction." ],\r
499   "23" => [ "Unacceptable transaction fee", "Unacceptable transaction fee." ],\r
500   "24" => [ "File update not supported", "File update not supported." ],\r
501   "25" => [ "Unable to locate record", "Unable to locate record." ],\r
502   "26" => [ "Duplicate record", "Duplicate record." ],\r
503   "27" => [ "File update edit error", "File update edit error." ],\r
504   "28" => [ "File update file locked", "File update file locked." ],\r
505   "30" => [ "Format error, call ECHO", "The host reported that the transaction was not formatted properly." ],\r
506   "31" => [ "Bank not supported", "Bank not supported by switch." ],\r
507   "32" => [ "Completed partially", "Completed partially." ],\r
508   "33" => [ "Expired card, pick-up", "The card is expired.  Merchant may receive reward money by capturing the card." ],\r
509   "34" => [ "Issuer suspects fraud, pick-up card", "The card issuer suspects fraud.  Merchant may receive reward money by capturing the card." ],\r
510   "35" => [ "Contact acquirer, pick-up", "Contact card issuer.  Merchant may receive reward money by capturing the card." ],\r
511   "36" => [ "Restricted card, pick-up", "The card is restricted by the issuer.  Merchant may receive reward money by capturing the card." ],\r
512   "37" => [ "Call ECHO security, pick-up", "Contact ECHO security.  Merchant may receive reward money by capturing the card." ],\r
513   "38" => [ "PIN tries exceeded, pick-up", "PIN attempts exceed issuer limits.  Merchant may receive reward money by capturing the card." ],\r
514   "39" => [ "No credit account", "No credit account." ],\r
515   "40" => [ "Function not supported", "Requested function not supported." ],\r
516   "41" => [ "Lost Card, capture for reward", "The card has been reported lost." ],\r
517   "42" => [ "No universal account", "No universal account." ],\r
518   "43" => [ "Stolen Card, capture for reward", "The card has been reported stolen." ],\r
519   "44" => [ "No investment account", "No investment account." ],\r
520   "51" => [ "Not sufficient funds", "The credit limit for this account has been exceeded." ],\r
521   "54" => [ "Expired card", "The card is expired." ],\r
522   "55" => [ "Incorrect PIN", "The cardholder PIN is incorrect." ],\r
523   "56" => [ "No card record", "No card record." ],\r
524   "57" => [ "Transaction not permitted to cardholder", "The card is not allowed the type of transaction requested." ],\r
525   "58" => [ "Transaction not permitted on terminal", "The Merchant is not allowed this type of transaction." ],\r
526   "59" => [ "Suspected fraud", "Suspected fraud." ],\r
527   "60" => [ "Contact ECHO", "Contact ECHO." ],\r
528   "61" => [ "Exceeds withdrawal limit", "The amount exceeds the allowed daily maximum." ],\r
529   "62" => [ "Restricted card", "The card has been restricted." ],\r
530   "63" => [ "Security violation.", "The card has been restricted." ],\r
531   "64" => [ "Original amount incorrect", "Original amount incorrect." ],\r
532   "65" => [ "Exceeds withdrawal frequency", "The allowable number of daily transactions has been exceeded." ],\r
533   "66" => [ "Call acquirer security, call ECHO", "Call acquirer security, call ECHO." ],\r
534   "68" => [ "Response received too late", "Response received too late." ],\r
535   "75" => [ "PIN tries exceeded", "The allowed number of PIN retries has been exceeded." ],\r
536   "76" => [ "Invalid \"to\" account", "The debit account does not exist." ],\r
537   "77" => [ "Invalid \"from\" account", "The credit account does not exist." ],\r
538   "78" => [ "Invalid account specified (general)", "The associated card number account is invalid or does not exist." ],\r
539   "79" => [ "Already reversed", "Already reversed." ],\r
540   "84" => [ "Invalid authorization life cycle", "The authorization life cycle is invalid." ],\r
541   "86" => [ "Cannot verify PIN", "Cannot verify PIN." ],\r
542   "87" => [ "Network Unavailable", "Network Unavailable." ],\r
543   "89" => [ "Ineligible to receive financial position information", "Ineligible to receive financial position information." ],\r
544   "90" => [ "Cut-off in progress", "Cut-off in progress." ],\r
545   "91" => [ "Issuer or switch inoperative", "The bank is not available to authorize this transaction." ],\r
546   "92" => [ "Routing error", "The transaction cannot be routed to the authorizing agency." ],\r
547   "93" => [ "Violation of law", "Violation of law." ],\r
548   "94" => [ "Duplicate transaction", "Duplicate transaction." ],\r
549   "95" => [ "Reconcile error", "Reconcile error." ],\r
550   "96" => [ "System malfunction", "A system error has occurred." ],\r
551   "98" => [ "Exceeds cash limit", "Exceeds cash limit." ],\r
552   "1000" => [ "Unrecoverable error.", "An unrecoverable error has occurred in the ECHONLINE processing." ],\r
553   "1001" => [ "Account closed", "The merchant account has been closed." ],\r
554   "1002" => [ "System closed", "Services for this system are not available. (Not used by ECHONLINE)" ],\r
555   "1003" => [ "E-Mail Down", "The e-mail function is not available. (Not used by ECHONLINE)" ],\r
556   "1012" => [ "Invalid trans code", "The host computer received an invalid transaction code." ],\r
557   "1013" => [ "Invalid term id", "The ECHO-ID is invalid." ],\r
558   "1015" => [ "Invalid card number", "The credit card number that was sent to the host computer was invalid" ],\r
559   "1016" => [ "Invalid expiry date", "The card has expired or the expiration date was invalid." ],\r
560   "1017" => [ "Invalid amount", "The dollar amount was less than 1.00 or greater than the maximum allowed for this card." ],\r
561   "1019" => [ "Invalid state", "The state code was invalid. (Not used by ECHONLINE)" ],\r
562   "1021" => [ "Invalid service", "The merchant or card holder is not allowed to perform that kind of transaction" ],\r
563   "1024" => [ "Invalid auth code", "The authorization number presented with this transaction is incorrect. (deposit transactions only)" ],\r
564   "1025" => [ "Invalid reference number", "The reference number presented with this transaction is incorrect or is not numeric." ],\r
565   "1029" => [ "Invalid contract number", "The contract number presented with this transaction is incorrect or is not numeric. (Not used by ECHONLINE)" ],\r
566   "1030" => [ "Invalid inventory data", "The inventory data presented with this transaction is not ASCII \"printable\". (Not used by ECHONLINE)" ],\r
567   "1508" => [ " ", "Invalid or missing order_type." ],\r
568   "1509" => [ " ", "The merchant is not approved to submit this order_type." ],\r
569   "1510" => [ " ", "The merchant is not approved to submit this transaction_type." ],\r
570   #"1511" => [ " ", "Duplicate transaction attempt (see counterin Part I of this Specification</EM>)." ],\r
571   "1511" => [ " ", "Duplicate transaction attempt (set counter field?)." ],\r
572   "1599" => [ " ", "An system error occurred while validating the transaction input." ],\r
573   "1801" => [ "Return Code \"A\"", "Address matches; ZIP does not match." ],\r
574   "1802" => [ "Return Code \"W\"", "9-digit ZIP matches; Address does not match." ],\r
575   "1803" => [ "Return Code \"Z\"", "5-digit ZIP matches; Address does not match." ],\r
576   "1804" => [ "Return Codes \"U\"", "Issuer unavailable; cannot verify." ],\r
577   "1805" => [ "Return Code \"R\"", "Retry; system is currently unable to process." ],\r
578   "1806" => [ "Return Code \"S\" or \"G\"", "Issuer does not support AVS." ],\r
579   "1807" => [ "Return Code \"N\"", "Nothing matches." ],\r
580   "1808" => [ "Return Code \"E\"", "Invalid AVS only response." ],\r
581   "1809" => [ "Return Code \"B\"", "Street address match. Postal code not verified because of incompatible formats." ],\r
582   "1810" => [ "Return Code \"C\"", "Street address and Postal code not verified because of incompatible formats." ],\r
583   "1811" => [ "Return Code \"D\"", "Street address match and Postal code match." ],\r
584   "1812" => [ "Return Code \"I\"", "Address information not verified for international transaction." ],\r
585   "1813" => [ "Return Code \"M\"", "Street address match and Postal code match." ],\r
586   "1814" => [ "Return Code \"P\"", "Postal code match. Street address not verified because of incompatible formats." ],\r
587   "1897" => [ "invalid response", "The host returned an invalid response." ],\r
588   "1898" => [ "disconnect", "The host unexpectedly disconnected." ],\r
589   "1899" => [ "timeout", "Timeout waiting for host response." ],\r
590   "2071" => [ "Call VISA", "An authorization number from the VISA Voice Center is required to approve this transaction." ],\r
591   "2072" => [ "Call Master Card", "An authorization number from the Master Card Voice Center is required to approve this transaction." ],\r
592   "2073" => [ "Call Carte Blanche", "An authorization number from the Carte Blanche Voice Center is required to approve this transaction." ],\r
593   "2074" => [ "Call Diners Club", "An authorization number from the Diners' Club Voice Center is required to approve this transaction." ],\r
594   "2075" => [ "Call AMEX", "An authorization number from the American Express Voice Center is required to approve this transaction." ],\r
595   "2076" => [ "Call Discover", "An authorization number from the Discover Voice Center is required to approve this transaction." ],\r
596   "2078" => [ "Call ECHO", "The merchant must call ECHOCustomer Support for approval.or because there is a problem with the merchant's account." ],\r
597   "2079" => [ "Call XpresscheX", "The merchant must call ECHOCustomer Support for approval.or because there is a problem with the merchant's account." ],\r
598   "3001" => [ "No ACK on Resp", "The host did not receive an ACK from the terminal after sending the transaction response." ],\r
599   "3002" => [ "POS NAK'd 3 Times", "The host disconnected after the terminal replied 3 times to the host response with a NAK." ],\r
600   "3003" => [ "Drop on Wait", "The line dropped before the host could send a response to the terminal." ],\r
601   "3005" => [ "Drop on Resp", "The line dropped while the host was sending the response to the terminal." ],\r
602   "3007" => [ "Drop Before EOT", "The host received an ACK from the terminal but the line dropped before the host could send the EOT." ],\r
603   "3011" => [ "No Resp to ENQ", "The line was up and carrier detected, but the terminal did not respond to the ENQ." ],\r
604   "3012" => [ "Drop on Input", "The line disconnected while the host was receiving data from the terminal." ],\r
605   "3013" => [ "FEP NAK'd 3 Times", "The host disconnected after receiving 3 transmissions with incorrect LRC from the terminal." ],\r
606   "3014" => [ "No Resp to ENQ", "The line disconnected during input data wait in Multi-Trans Mode." ],\r
607   "3015" => [ "Drop on Input", "The host encountered a full queue and discarded the input data." ],\r
608 );\r
609 for ( 9000..9999 ) {\r
610   $error{$_} = [ "Host Error", "The host encountered an internal error and was not able to process the transaction." ]; \r
611 }\r
612 sub error {\r
613   my( $self, $num ) = @_;\r
614   $num =~ s/^00(\d\d)$/$1/;\r
615   return $num. ': '. $error{$num}[0]. ': '. $error{$num}[1];\r
616 }\r
617 \r
618 1;\r
619 \r
620 __END__\r
621 \r
622 =head1 NAME\r
623 \r
624 Business::OnlinePayment::OpenECHO - ECHO backend module for Business::OnlinePayment\r
625 \r
626 =head1 SYNOPSIS\r
627 \r
628   use Business::OnlinePayment;\r
629 \r
630   ####\r
631   # One step transaction, the simple case.\r
632   ####\r
633 \r
634   my $tx = new Business::OnlinePayment("OpenECHO");\r
635   $tx->content(\r
636       type           => 'VISA',\r
637       login          => '1234684752',\r
638       password       => '43400210',\r
639       action         => 'Normal Authorization',\r
640       description    => 'Business::OnlinePayment test',\r
641       amount         => '49.95',\r
642       invoice_number => '100100',\r
643       customer_id    => 'jsk',\r
644       first_name     => 'Tofu',\r
645       last_name      => 'Beast',\r
646       address        => '123 Anystreet',\r
647       city           => 'Anywhere',\r
648       state          => 'UT',\r
649       zip            => '84058',\r
650       card_number    => '4005550000000019',\r
651       expiration     => '08/06',\r
652       cvv2           => '1234', #optional\r
653       referer        => 'http://valid.referer.url/',\r
654   );\r
655   $tx->submit();\r
656 \r
657   if($tx->is_success()) {\r
658       print "Card processed successfully: ".$tx->authorization."\n";\r
659   } else {\r
660       print "Card was rejected: ".$tx->error_message."\n";\r
661   }\r
662 \r
663 =head1 SUPPORTED TRANSACTION TYPES\r
664 \r
665 =head2 CC, Visa, MasterCard, American Express, Discover\r
666 \r
667 Content required: type, login, password, action, amount, first_name, last_name, card_number, expiration.\r
668 \r
669 =head2 Check\r
670 \r
671 Content required: type, login, password, action, amount, first_name, last_name, account_number, routing_code, bank_name. (...more)\r
672 \r
673 =head1 PREREQUISITES\r
674 \r
675   URI::Escape\r
676   Tie::IxHash\r
677 \r
678   Net::SSLeay _or_ ( Crypt::SSLeay and LWP )\r
679 \r
680 =head1 DESCRIPTION\r
681 \r
682 For detailed information see L<Business::OnlinePayment>.\r
683 \r
684 =head1 AUTHOR\r
685 \r
686 Original Author\r
687 Michael Lehmkuhl <michael@electricpulp.com>\r
688 \r
689 Special Thanks\r
690 Jim Darden <jdarden@echo-inc.com>\r
691 Dan Browning <db@kavod.com>\r
692 \r
693 Business::OnlinePayment Implementation\r
694 Ivan Kohler <ivan-openecho@420.am>\r
695 \r
696 =head1 SEE ALSO\r
697 \r
698 perl(1). L<Business::OnlinePayment>.\r
699 \r
700 =cut\r
701 \r