/
ICS.pm
484 lines (411 loc) · 13.8 KB
/
ICS.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# Vend::Payment::ICS - Interchange Cybersource ICS Support
#
# Copyright (C) 2005 End Point Corporation
#
# Written by Sonny Cook <sonny@endpoint.com>
# based on code by Mike Heins <mike@perusion.com>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301 USA.
package Vend::Payment::ICS;
=head1 Interchange ICS Support
Vend::Payment::ICS $Revision: 1.2 $
=head1 SYNOPSIS
=head1 PREREQUISITES
ICS Library
ICS.pm
=head1 DESCRIPTION
In interchange.cfg:
Require module Vend::Payment::ICS
In catalog.cfg:
Variable MV_PAYMENT_MODE ICS
Route ICS server_host ics2test.ic3.com
Route ICS server_port 80
Route ICS path /path/to/lib/CyberSource/SDK
Route ICS merchant_id your_merchant_id
Route ICS apps ics_auth,ics_auth_reversal,ics_bill,ics_credit
Route ICS timeout 20
Route ICS merchant_descriptor "test merchant"
Route ICS merchant_descriptor_contact "phone number"
You must first install CyberSource's ICS.pm and put your "keys" directory in the
location pointed to by the "path" parameter. Obviously you must have a merchant
account set up.
=head1 AUTHOR
Sonny Cook <sonny@endpoint.com>
=cut
package Vend::Payment;
use strict;
# Requires CyberSource ICS perl SDK
use ICS qw(ics_send ics_print);
sub ICS {
#::logDebug("ICS called--in the begining");
my ($opt) = @_;
$opt->{order_number} ||= $opt->{order_id};
#::logDebug("ICS opt hash: %s", ::uneval($opt));
my %type_map = qw(
sale auth_bill
auth auth
authorize auth
void auth_reversal
settle bill
credit credit
mauthcapture auth_bill
mauthonly auth
mauthdelay auth
mauthreturn credit
S auth_bill
C credit
D bill
V auth_reversal
A auth
);
my %inv_trans_map = qw(
auth A
auth_bill S
credit C
auth_reversal V
bill D
);
my %app_map = (
auth => [qw/ ics_dav ics_export ics_score ics_auth /],
auth_bill => [qw/ ics_dav ics_export ics_score ics_auth ics_bill/],
auth_reversal => [qw/ ics_auth_reversal /],
bill => [qw/ ics_bill /],
credit => [qw/ ics_credit /],
);
my $transtype = $opt->{transaction} || charge_param('transaction') ||
$opt->{cyber_mode} || charge_param('cyber_mode') || 'auth';
#::logDebug("tansaction type: $transtype");
$transtype = $type_map{$transtype}
or return (
MStatus => 'failure-hard',
MErrMsg => errmsg('Unrecognized transaction: %s', $transtype),
);
# get list of applications to use
my @apps;
for (@{$app_map{$transtype}}) {
my $a = $_;
push @apps, grep lc $a eq lc $_, split /[,| ]\s*/, $opt->{apps};
}
#::logDebug ("Applications: " . uneval \@apps);
# ics_auth_required
my %required_map = (
all => [ qw(
merchant_id
merchant_ref_number
ics_applications
server_host
server_port
) ],
ics_auth => [ qw(
bill_address1
bill_city
bill_country
bill_state
bill_zip
currency
customer_cc_expmo
customer_cc_expyr
customer_cc_number
customer_email
customer_firstname
customer_lastname
merchant_ref_number
ship_to_address1
ship_to_city
ship_to_country
ship_to_state
ship_to_zip
) ],
ics_auth_reversal => [ qw(
auth_request_id
currency
merchant_ref_number
) ],
ics_bill => [ qw(
auth_request_id
) ],
ics_credit => [ qw(
bill_address1
bill_city
bill_country
bill_state
bill_zip
currency
customer_cc_expmo
customer_cc_expyr
customer_cc_number
customer_email
customer_firstname
customer_lastname
merchant_ref_number
) ],
ics_dav => [],
ics_export => [],
ics_score => [],
);
my %exempt_map = (
billing_intl => [ qw(
bill_address1
bill_city
bill_country
bill_state
bill_zip
) ],
shipping_intl => [ qw(
ship_to_address1
ship_to_city
ship_to_country
ship_to_state
ship_to_zip
) ],
);
# These fields are not necessarily optional on our end,
# they are just optional on the ICS end.
my %optional_map = (
all => [ qw( timeout ) ],
ics_auth => [ qw(
bill_address2
ship_to_address2
customer_cc_cv_number
ignore_avs
ignore_bad_cv
merchant_descriptor
merchant_descriptor_contact
) ],
ics_auth_reversal => [],
ics_bill => [ qw(
merchant_descriptor
merchant_descriptor_contact
) ],
ics_credit => [ qw(
merchant_descriptor
merchant_descriptor_contact
) ],
ics_dav => [],
ics_export => [],
ics_score => [],
);
my %default_map = qw(
timeout 10
ignore_avs yes
ignore_bad_cv yes
currency usd
);
my %actual_map = qw(
bill_address1 b_address1
bill_address2 b_address2
bill_city b_city
bill_country b_country
bill_state b_state
bill_zip b_zip
customer_cc_expmo mv_credit_card_exp_month
customer_cc_expyr mv_credit_card_exp_year
customer_cc_number mv_credit_card_number
customer_cc_cv_number mv_credit_card_cvv2
customer_email email
customer_firstname b_fname
customer_lastname b_lname
ship_to_address1 address1
ship_to_address2 address2
ship_to_city city
ship_to_country country
ship_to_state state
ship_to_zip zip
);
my %opt_map = qw (
merchant_ref_number order_number
auth_request_id origid
);
my %vital_error_map = (
'01' => "Authorization has been declined.",
'02' => "Authorization has been declined.",
'03' => "We are experiencing system difficulties. Please try again later.",
'04' => "Authorization has been declined.",
'05' => "Authorization has been declined.",
'07' => "Authorization has been declined.",
'12' => "We are experiencing system difficulties. Please try again later.",
'13' => "Invalid amount.",
'14' => "Invalid card number.",
'15' => "Invalid Card Number.",
'19' => "Authorization has been declined.",
'39' => "Invalid card number.",
'41' => "Authorization has been declined.",
'43' => "Authorization has been declined.",
'51' => "Insufficient funds.",
'52' => "Invalid card number.",
'53' => "Invalid card number.",
'54' => "Card is expired.",
'55' => "Incorrect PIN.",
'57' => "Authorization has been declined.",
'58' => "Authorization has been declined.",
'61' => "Amount exceeds withdrawal limit.",
'62' => "Authorization has been declined.",
'63' => "Authorization has been declined.",
'65' => "Activity limit exceeded.",
'75' => "PIN tries exceeded.",
'78' => "Invalid card number.",
'79' => "We had difficulty processing your transaction. Please call customer service to complete order.",
'80' => "Invalid expiration date.",
'82' => "Cashback limit exceeded.",
'83' => "Can not verify PIN.",
'86' => "Can not verify PIN.",
'92' => "We had difficulty processing your transaction. Please call customer service to complete order.",
'93' => "Authorization has been declined.",
'EA' => "We had difficulty processing your transaction. Please call customer service to complete order.",
'EB' => "We had difficulty processing your transaction. Please call customer service to complete order.",
'EC' => "We had difficulty processing your transaction. Please call customer service to complete order.",
'N3' => "Cashback service not available.",
'N4' => "Amount exceeds issuer withdrawal limit.",
'N7' => "Invalid Card Security Code.",
);
# Special Cases
$required_map{ics_bill} = [] if $transtype eq 'auth_bill';
my %actual = $opt->{actual} ? %{$opt->{actual}} : map_actual();
my @required_keys = (@{$required_map{all}}, @{$optional_map{all}});
push @required_keys, @{$required_map{$_}} for @apps;
my @optional_keys;
push @optional_keys, @{$optional_map{$_}} for @apps;
# Build Request
my @request_keys = (@required_keys, @optional_keys);
my %request = map { $_ => $actual{$actual_map{$_}} }
grep defined $actual{$actual_map{$_}}, @request_keys;
$request{$_} = $opt->{$_} for grep defined $opt->{$_}, @request_keys;
$request{$_} = $opt->{$opt_map{$_}} for grep defined $opt->{$opt_map{$_}}, @request_keys;
# Uses the {currency} -> MV_PAYMENT_CURRENCY options if set
$request{currency} = charge_param('currency')
|| ($Vend::Cfg->{Locale} && $Vend::Cfg->{Locale}{currency_code})
|| 'usd';
# Add defaults
$request{$_} ||= $default_map{$_} for grep defined $default_map{$_}, @request_keys;
# Set Applications Field
$request{ics_applications} = join ',', @apps;
# build exempt keys hash
my %exempt_keys;
for (keys %exempt_map) {
## these keys apply only if we are shipping outside the
## US or CA
next if $_ eq 'billing_intl'
and (
lc $request{bill_country} eq 'us'
or lc $request{bill_country} eq 'ca'
);
next if $_ eq 'shipping_intl'
and (
lc $request{ship_to_country} eq 'us'
or lc $request{ship_to_country} eq 'ca'
);
$exempt_keys{$_}++ for @{$exempt_map{$_}};
}
# make sure that we have ALL required fields filled
# exempt fields can be present, but are not required
for (@required_keys) {
if (! defined $request{$_} && ! $exempt_keys{$_}) {
return (
MStatus => 'failure-hard',
MErrMsg => errmsg("Missing value for >$_< field"),
);
}
}
# Set ENV for ICSPATH; this is the path to the SSL certs
$ENV{ICSPATH} = $opt->{path};
# Build Offers
$request{offer0} = "offerid:0^amount:" . $opt->{total_cost};
#::logDebug("ICS Sending Request...\n" . uneval \%request);
my %resp = ics_send(%request);
#::logDebug("ICS Response: " . uneval \%resp);
# Handle failure
my $status = $resp{ics_rcode} == 1 ? 'success' : 'failed';
if ($status eq 'failed') {
my $code = $resp{auth_auth_response};
my $msg = $vital_error_map{$code} || $resp{ics_rmsg};
$msg = "($code) " . $msg if $code;
return (
MStatus => 'failure-hard',
MErrMsg => errmsg($msg),
);
}
my ($avs_addr, $avs_zip) = handle_avs($resp{auth_auth_avs});
my $cv = handle_cv($resp{auth_cv_result});
my %result = (
MStatus => $status,
'order-id' => $resp{request_id},
transtype => $inv_trans_map{$transtype},
ORIGID => $resp{request_id},
PNREF => $resp{request_id},
AVSADDR => $avs_addr,
AVSZIP => $avs_zip,
CVV2MATCH => $cv,
);
return %result;
}
# Results of address verification.
# This field will contain one of the following values:
# A: Street number matches, but 5-digit ZIP code and 9-digit ZIP code do not match.
# B: Street address match for non-U.S. AVS transaction. Postal code not verified.
# C: Street address and postal code not verified for non-U.S. AVS transaction.
# D: Street address and postal code match for non-U.S. AVS transaction.
# E: AVS data is invalid.
# G: Non-U.S. card issuing bank does not support AVS.
# I: Address information not verified for non-U.S. AVS transaction.
# M: Street address and postal code match for non-U.S. AVS transaction.
# N: Street number, 5-digit ZIP code, and 9-digit ZIP code do not match.
# P: Postal code match for non-U.S. AVS transaction. Street address not verified.
# R: System unavailable.
# S: Issuing bank does not support AVS.
# U: Address information unavailable. Returned if non-U.S. AVS is not available or if the AVS in a U.S. bank is not functioning properly.
# W: Street number does not match, but 5-digit ZIP code and 9-digit ZIP code match.
# X: Exact match. Street number, 5-digit ZIP code, and 9-digit ZIP code match.
# Y: Both street number and 5-digit ZIP code match.
# Z: 5-digit ZIP code matches.
# 1: CyberSource does not support AVS for this processor or card type.
# 2: The processor returned an unrecognized value for the AVS response.
sub handle_avs {
my $c = shift;
# returns (address, zip)
# D,M,X,Y
return ('Y', 'Y') if $c eq 'D' || $c eq 'M' || $c eq 'X' || $c eq 'Y';
# A
return ('Y', 'N') if $c eq 'A';
# W
return ('N', 'Y') if $c eq 'W';
# P,Z
return ('', 'Y') if $c eq 'P' || $c eq 'Z';
# B
return ('Y', '') if $c eq 'B';
# N
return ('N', 'N') if $c eq 'N';
# C,E,G,I,R,S,U,1,2
return ('', '');
}
# Result of processing the card verification number.
# This field will contain one of the following values:
# M: Card verification number matched.
# N: Card verification number not matched.
# P: Card verification number not processed.
# S: Card verification number is on the card but was not included in the request.
# U: Card verification is not supported by the issuing bank.
# X: Card verification is not supported by the card association.
# <space>: Deprecated. Ignore this value.
# 1: CyberSource does not support card verification for this processor or card type.
# 2: The processor returned an unrecognized value for the card verification response.
# 3: The processor did not return a card verification result code.
sub handle_cv {
my $c = shift;
return 'Y' if $c eq 'M';
return 'N' if $c eq 'N';
return '';
}
package Vend::Payment::ICS;
1;