1 ## Business::OnlinePayment::Skipjack
3 ## Original Skipjack.pm developed by New York Connect Net (http://nyct.net)
4 ## Michael Bacarella <mbac@nyct.net>
6 ## Modified for GetCareer.com by Slipstream.com
7 ## Troy Davis <troy@slipstream.com>
9 ## 'Adapted' (completely rewritten) for Business::OnlinePayment
10 ## by Fire2Wire Internet Services (http://www.fire2wire.com)
11 ## Mark Wells <mark@pc-intouch.com>
12 ## Kristian Hoffmann <khoff@pc-intouch.com>
13 ## James Switzer <jamess@fire2wire.com>
18 ## Business::OnlinePayment
21 package Business::OnlinePayment::Skipjack;
25 use Business::OnlinePayment 3;
26 use Business::OnlinePayment::HTTPS;
28 use vars qw( @ISA $VERSION $DEBUG );
33 @ISA = qw( Business::OnlinePayment::HTTPS );
36 '-1' => 'Invalid length (-1)',
37 '-35' => 'Invalid credit card number (-35)',
38 '-37' => 'Failed communication (-37)',
39 '-39' => 'Serial number is too short (-39)',
40 '-51' => 'The zip code is invalid',
41 '-52' => 'The shipto zip code is invalid',
42 '-53' => 'Length of expiration date (-53)',
43 '-54' => 'Length of account number date (-54)',
44 '-55' => 'Length of street address (-55)',
45 '-56' => 'Length of shipto street address (-56)',
46 '-57' => 'Length of transaction amount (-57)',
47 '-58' => 'Length of name (-58)',
48 '-59' => 'Length of location (-59)',
49 '-60' => 'Length of state (-60)',
50 '-61' => 'Length of shipto state (-61)',
51 '-62' => 'Length of order string (-62)',
52 '-64' => 'Invalid phone number (-64)',
53 '-65' => 'Empty name (-65)',
54 '-66' => 'Empty email (-66)',
55 '-67' => 'Empty street address (-66)',
56 '-68' => 'Empty city (-68)',
57 '-69' => 'Empty state (-69)',
58 '-70' => 'Empty zip code (-70)',
59 '-71' => 'Empty order number (-71)',
60 '-72' => 'Empty account number (-72)',
61 '-73' => 'Empty expiration month (-73)',
62 '-74' => 'Empty expiration year (-74)',
63 '-75' => 'Empty serial number (-75)',
64 '-76' => 'Empty transaction amount (-76)',
65 '-79' => 'Length of customer name (-79)',
66 '-80' => 'Length of shipto customer name (-80)',
67 '-81' => 'Length of customer location (-81)',
68 '-82' => 'Length of customer state (-82)',
69 '-83' => 'Length of shipto phone (-83)',
70 '-84' => 'Pos Error duplicate ordernumber (-84)',
71 '-91' => 'Pos Error CVV2 (-91)',
72 '-92' => 'Pos Error Approval Code (-92)',
73 '-93' => 'Pos Error Blind Credits Not Allowed (-93)',
74 '-94' => 'Pos Error Blind Credits Failed (-94)',
75 '-95' => 'Pos Error Voice Authorizations Not Allowed (-95)',
79 'X' => 'Exact match, 9 digit zip',
80 'Y' => 'Exact match, 5 digit zip',
81 'A' => 'Address match only',
82 'W' => '9 digit match only',
83 'Z' => '5 digit match only',
84 'N' => 'No address or zip match',
85 'U' => 'Address unavailable',
86 'R' => 'Issuer system unavailable',
87 'E' => 'Not a mail/phone order',
88 'S' => 'Service not supported'
94 address => 'Streetaddress',
98 order_number => 'Ordernumber',
99 card_number => 'Accountnumber',
100 exp_month => 'Month',
102 amount => 'Transactionamount',
103 orderstring => 'Orderstring',
104 phone => 'Shiptophone',
105 login => 'Serialnumber',
108 my %CHANGE_STATUS_FIELDS = (
109 login => 'szSerialNumber',
110 password => 'szDeveloperSerialNumber',
111 order_number => 'szOrderNumber',
112 # => 'szTransactionId',
113 amount => 'szAmount',
116 my @CHANGE_STATUS_RESPONSE = (
130 my @CHANGE_STATUS_RESPONSE_RECORD = (
131 'Serial Number (Record)',
135 'Status Response Message',
140 my %CHANGE_STATUS_ERROR_CODES = (
142 '-1' => 'Invalid Command',
143 '-2' => 'Parameter Missing',
144 '-3' => 'Failed retrieving response',
145 '-4' => 'Invalid Status',
146 '-5' => 'Failed reading security flags',
147 '-6' => 'Developer serial number not found',
148 '-7' => 'Invalid Serial Number',
149 '-8' => 'Expiration year not four characters',
150 '-9' => 'Credit card expired',
151 '-10' => 'Invalid starting date (recurring payment)',
152 '-11' => 'Failed adding recurring payment',
153 '-12' => 'Invalid frequency (recurring payment)',
156 my %GET_STATUS_FIELDS = (
157 login => 'szSerialNumber',
158 password => 'szDeveloperSerialNumber',
159 order_number => 'szOrderNumber',
160 #date => 'szDate', # would probably need some massaging
161 # and parse_SJAPI_TransactionStatusRequest would
162 # need to handle multiple records...
165 my @GET_STATUS_RESPONSE = (
179 my @GET_STATUS_RESPONSE_RECORD = (
180 'Serial Number (Record)',
182 'Transaction Status Code',
183 'Transaction Status Message',
191 my %GET_STATUS_ERROR_CODES = (
193 '-1' => 'Invalid Command',
194 '-2' => 'Parameter Missing',
195 '-3' => 'Failed retrieving response',
196 '-4' => 'Invalid Status',
197 '-5' => 'Failed reading security flags',
198 '-6' => 'Developer serial number not found',
199 '-7' => 'Invalid Serial Number',
200 '-8' => 'Expiration year not four characters',
201 '-9' => 'Credit card expired',
204 my %CUR_STATUS_CODES = (
215 my %PEND_STATUS_CODES = (
217 '1' => 'Pending Credit',
218 '2' => 'Pending Settlement ',
219 '3' => 'Pending Delete',
220 '4' => 'Pending Authorization',
221 '5' => 'Pending Settle Force (for Manual Accts)',
222 '6' => 'Pending Recurring',
225 sub _gen_ordernum { return int(rand(4000000000)); }
232 $self->server('www.skipjackic.com');
243 my %c = $self->content;
244 my (%input, %output);
246 unless ( $c{type} =~ /(cc|visa|mastercard|american express|discover)/i ) {
247 croak 'Business::OnlinePayment::Skipjack does not support "' .
248 $c{type}. '" transactions';
251 # skipjack kicks out "Length of transaction amount (-57)" or "Invalid amount"
252 # if the amount is missing .XX
253 $c{amount} = sprintf('%.2f', $c{amount})
254 if defined($c{amount}) && length($c{amount});
256 if ( lc($c{action}) eq 'normal authorization' ) {
257 $self->{_action} = 'normal authorization';
258 $self->path('/scripts/evolvcc.dll?AuthorizeAPI');
260 $c{expiration} =~ /(\d\d?)\D*(\d\d?)/; # Slightly less crude way to extract the exp date.
261 $c{exp_month} = sprintf('%02d',$1);
262 $c{exp_year} = sprintf('%02d',$2);
264 $c{order_number} = _gen_ordernum unless $c{order_number};
266 $c{orderstring} = '0~'.$c{description}.'~'.$c{amount}.'~1~N~||'
267 unless $c{orderstring};
269 %input = map { ($FIELDS{$_} || $_), $c{$_} } keys(%c);
271 } elsif ( $c{action} =~ /^(credit|void|post authorization)$/i ) {
273 $self->path('/scripts/evolvcc.dll?SJAPI_TransactionChangeStatusRequest');
275 %input = map { ($CHANGE_STATUS_FIELDS{$_} || $_), $c{$_} } keys %c;
277 if ( lc($c{action} ) eq 'credit' ) {
278 $self->{_action} = 'credit';
279 $input{szDesiredStatus} = 'CREDIT';
280 } elsif ( lc($c{action} ) eq 'void' ) {
281 $self->{_action} = 'void';
282 $input{szDesiredStatus} = 'DELETE';
283 } elsif ( lc($c{action} ) eq 'post authorization' ) {
284 $self->{_action} = 'postauth';
285 $input{szDesiredStatus} = 'SETTLE';
287 die "fatal: $c{action} is not credit or void!";
290 } elsif ( lc($c{action}) eq 'status' ) {
292 $self->{_action} = 'status';
293 $self->path('/scripts/evolvcc.dll?SJAPI_TransactionStatusRequest');
294 %input = map { ($GET_STATUS_FIELDS{$_} || $_), $c{$_} } keys(%c);
298 croak 'Business::OnlinePayment::Skipjack does not support "'.
299 $c{action}. '" actions';
303 $self->server('developer.skipjackic.com') # test mode
304 if $self->test_transaction();
306 my( $page, $response ) = $self->https_post( %input );
307 warn "\n$page\n" if $DEBUG;
309 if ( $self->{_action} eq 'normal authorization' ) {
310 %output = parse_Authorize_API($page);
311 } elsif ( $self->{_action} =~ /^(credit|void|postauth)$/ ) {
312 %output = parse_SJAPI_TransactionChangeStatusRequest($page);
313 } elsif ( $self->{_action} eq 'status' ) {
314 %output = parse_SJAPI_TransactionStatusRequest($page);
316 die "fatal: unknown action: ". $self->{_action};
319 $self->{_result} = \%output;
320 $self->authorization($output{'AUTHCODE'});
328 if ( $self->{_action} eq 'normal authorization' ) {
330 return( $self->{_result}->{'szIsApproved'} == 1 );
332 } elsif ( $self->{_action} =~ /^(credit|void|postauth)$/ ) {
334 return( $self->{_result}{'Error Code'} eq '0' # == 0 matches ''
335 && uc($self->{_result}{'Status Response'}) eq 'SUCCESSFUL'
338 } elsif ( $self->{_action} eq 'status' ) {
340 return( $self->{_result}{'Error Code'} eq '0' ); # == 0 matches ''
343 die "fatal: unknown action: ". $self->{_action};
353 if($self->is_success) { return ''; }
355 if ( $self->{_action} eq 'normal authorization' ) {
357 if(($r = $self->{_result}->{'szReturnCode'}) < 0) { return $CC_ERRORS{$r}; }
358 if($r = $self->{_result}->{'szAVSResponseMessage'}) { return $r; }
359 if($r = $self->{_result}->{'szAuthorizationDeclinedMessage'}) { return $r; }
361 } elsif ( $self->{_action} =~ /^(credit|void|postauth)$/ ) {
363 if ( ( $r = $self->{_result}{'Error Code'} ) < 0 ) {
364 return $CHANGE_STATUS_ERROR_CODES{$r};
366 return $self->{_result}{'Status Response Message'};
369 } elsif ( $self->{_action} eq 'status' ) {
371 if ( ( $r = $self->{_result}{'Error Code'} ) < 0 ) {
372 return $CHANGE_STATUS_ERROR_CODES{$r};
374 return $self->{_result}{'Status Response Message'};
378 die "fatal: unknown action: ". $self->{_action};
384 #sub result_code { shift->{_result}->{'ezIsApproved'}; }
385 sub authorization { shift->{_result}{'szAuthorizationResponseCode'}; }
386 sub avs_code { shift->{_result}{'szAVSResponseCode'}; }
387 sub order_number { shift->{_result}{'szOrderNumber'}; }
388 sub cvv2_response { shift->{_result}{'szCVV2ResponseCode'}; }
389 sub cavv_response { shift->{_result}{'szCAVVResponseCode'}; }
394 substr( $self->{_result}{'Transaction Status Code'}, 0, 1 )
401 substr( $self->{_result}{'Transaction Status Code'}, 1, 2 )
405 sub parse_Authorize_API
410 my $csv_keys = new Text::CSV_XS;
411 my $csv_values = new Text::CSV_XS;
413 my ($keystring, $valuestring) = split(/\r\n/, $page);
414 $csv_keys->parse($keystring);
415 $csv_values->parse($valuestring);
416 @output{$csv_keys->fields()} = $csv_values->fields();
422 sub parse_SJAPI_TransactionChangeStatusRequest
426 my $csv = new Text::CSV_XS;
430 my @records = split(/\r\n/, $page);
432 $csv->parse(shift @records)
433 or die "CSV parse failed on " . $csv->error_input;
434 @output{@CHANGE_STATUS_RESPONSE} = $csv->fields();
436 # we only handle a single record reponse, as that's all this module will
437 # currently submit...
438 $csv->parse(shift @records)
439 or die "CSV parse failed on " . $csv->error_input;
440 @output{@CHANGE_STATUS_RESPONSE_RECORD} = $csv->fields();
446 sub parse_SJAPI_TransactionStatusRequest
450 my $csv = new Text::CSV_XS;
454 my @records = split(/\r\n/, $page);
456 #$csv->parse(shift @records)
457 $csv->parse(shift @records)
458 or die "CSV parse failed on " . $csv->error_input;
459 @output{@GET_STATUS_RESPONSE} = $csv->fields();
461 # we only handle a single record reponse, as that's all this module will
462 # currently submit...
463 $csv->parse(shift @records)
464 or die "CSV parse failed on " . $csv->error_input;
465 @output{@GET_STATUS_RESPONSE_RECORD} = $csv->fields();
477 Business::OnlinePayment::Skipjack - Skipjack backend module for Business::OnlinePayment
481 use Business::OnlinePayment;
484 # One step transaction, the simple case.
487 my $tx = new Business::OnlinePayment("Skipjack");
490 login => '000178101827', # "HTML serial number"
491 action => 'Normal Authorization',
492 description => 'Business::OnlinePayment test',
494 invoice_number => '100100',
495 customer_id => 'jsk',
496 first_name => 'Jason',
497 last_name => 'Kohles',
498 address => '123 Anystreet',
502 card_number => '4007000000027',
503 expiration => '09/02',
504 cvv2 => '1234', #optional
505 #referer => 'http://valid.referer.url/',
509 if($tx->is_success()) {
510 print "Card processed successfully: ".$tx->authorization."\n";
512 print "Card was rejected: ".$tx->error_message."\n";
516 # Process a credit...
519 my $tx = new Business::OnlinePayment( "Skipjack" );
523 login => '000178101827', # "HTML serial number"
524 password => '100594217288', # "developer serial number"
525 action => 'Normal Authorization',
526 description => 'Business::OnlinePayment test',
528 invoice_number => '100100',
529 customer_id => 'jsk',
530 first_name => 'Jason',
531 last_name => 'Kohles',
532 address => '123 Anystreet',
536 card_number => '4007000000027',
537 expiration => '09/02',
538 cvv2 => '1234', #optional
539 #referer => 'http://valid.referer.url/',
543 if($tx->is_success()) {
544 print "Card credited successfully: ".$tx->authorization."\n";
546 print "Credit was rejected: ".$tx->error_message."\n";
550 =head1 SUPPORTED TRANSACTION TYPES
552 =head2 CC, Visa, MasterCard, American Express, Discover
554 Content required for Normal Authorization : login, action, amount, card_number,
555 expiration, name, address, city, state, zip, phone, email
557 Content required for Void or Credit: login, password, action, order_number
561 For detailed information see L<Business::OnlinePayment>
565 Net::SSLeay _or_ ( Crypt::SSLeay and LWP )
567 =head1 NOTE ON CREDITS
569 If you want to process credits, you must have your developer serial number
570 applied to your production account. See
571 http://www.skipjack.com/resources/Education/serialnumbers.htm
575 This modules supports a non-standard "status" action that corresponds to
576 Skipjack's TransactionStatusRequest. It should be documented.
580 Inspiried by (but no longer contains) code from:
582 Original Skipjack.pm developed by New York Connect Net (http://nyct.net)
583 Michael Bacarella <mbac@nyct.net>
585 Modified for GetCareer.com by Slipstream.com
586 Troy Davis <troy@slipstream.com>
588 'Adapted' (completely rewritten) for Business::OnlinePayment
589 by Fire2Wire Internet Services (http://www.fire2wire.com)
590 Mark Wells <mark@pc-intouch.com>
591 Kristian Hoffmann <khoff@pc-intouch.com>
592 James Switzer <jamess@fire2wire.com>
594 Boring 0.2 update by Ivan Kohler <ivan-skipjack@420.am>
598 Copyright (c) 2006 Fire2Wire Internet Services (http://www.fire2wire.com)
599 All rights reserved. This program is free software; you can redistribute it
600 and/or modify it under the same terms as Perl itself.
602 Inspiried by (but no longer contains) code from:
604 Original Skipjack.pm developed by New York Connect Net (http://nyct.net)
605 Michael Bacarella <mbac@nyct.net>
607 Modified for GetCareer.com by Slipstream.com
608 Troy Davis <troy@slipstream.com>
612 L<Business::OnlinePayment>