fe04da28f9346a979b8b833e360f342c7a2ff31a
[Business-OnlinePayment-TransFirsteLink.git] / t / credit_card.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use POSIX qw(strftime);
6 use Test::More;
7
8 use Business::OnlinePayment;
9
10 my $runinfo =
11     "to test set environment variables:"
12   . " (required) ELINK_ACCOUNT and ELINK_PASSWORD";
13
14 plan(
15       ( $ENV{"ELINK_ACCOUNT"} && $ENV{"ELINK_PASSWORD"} )
16     ? ( tests => 70 )
17     : ( skip_all => $runinfo )
18 );
19
20 my %opts = (
21     "debug"    => 0,
22     "merchantcustservnum" => "8005551212",
23 );
24
25 my %content = (
26     login          => $ENV{"ELINK_ACCOUNT"},
27     password       => $ENV{"ELINK_PASSWORD"},
28     action         => "Normal Authorization",
29     type           => "VISA",
30     description    => "Business::OnlinePayment::TransFirsteLink test",
31     card_number    => "4111111111111111",
32     cvv2           => "123",
33     expiration     => "12/" . strftime( "%y", localtime ),
34     amount         => "0.01",
35     invoice_number => "Test1",
36     first_name     => "Tofu",
37     last_name      => "Beast",
38     email          => 'transfirst@weasellips.com',
39     address        => "123 Anystreet",
40     city           => "Anywhere",
41     state          => "GA",
42     zip            => "30004",
43     country        => "US",
44 );
45
46 {    # valid card number test
47     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
48     $tx->content(%content);
49     tx_check(
50         $tx,
51         desc          => "valid card_number",
52         is_success    => 1,
53         result_code   => "000",
54         authorization => "999999",
55         avs_code      => "9",      # useless
56         cvv2_response => "99",     # doubly useless - docs say 1 char
57     );
58 }
59
60 {    # invalid card number test
61
62     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
63     $tx->content( %content, card_number => "4111111111111112" );
64     tx_check(
65         $tx,
66         desc          => "invalid card_number",
67         is_success    => 0,
68         result_code   => 214,
69         authorization => '',
70         avs_code      => '',
71         cvv2_response => '',
72     );
73 }
74
75
76 SKIP: {    # avs_code() / AVSZIP and AVSADDR tests
77
78     skip "AVS tests broken", 28;
79
80     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
81
82     # IF first 3 chars of STREET <= 334 and >= 666 THEN AVSADDR == "N"
83     $tx->content( %content, "address" => "500 Any street" );
84     tx_check(
85         $tx,
86         desc          => "AVSADDR=N,AVSZIP=Y",
87         is_success    => 0,
88         result_code   => 126,
89         authorization => "010101",
90         avs_code      => "Z",
91         cvv2_response => "Y",
92     );
93
94     # IF first 3 chars of STREET >= 667 THEN AVSADDR == "X" (and AVSZIP="X")
95     $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
96     $tx->content( %content, "address" => "700 Any street" );
97     tx_check(
98         $tx,
99         desc          => "AVSADDR=X,AVSZIP=X",
100         is_success    => 1,
101         result_code   => 0,
102         authorization => "010101",
103         avs_code      => "",
104         cvv2_response => "Y",
105     );
106
107 #    # IF ZIP <= 50001 and >= 99999 THEN AVSZIP == "N"
108     $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
109     $tx->content( %content, "zip" => "99999" );
110     tx_check(
111         $tx,
112         desc          => "AVSADDR=Y,AVSZIP=N",
113         is_success    => 0,
114         result_code   => 126,
115         authorization => "010101",
116         avs_code      => "A",
117         cvv2_response => "Y",
118     );
119
120     # Both AVSADDR and AVSZIP == "N"
121     $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
122     $tx->content( %content, "address" => "500 Any street", "zip" => "99999" );
123     tx_check(
124         $tx,
125         desc          => "AVSADDR=N,AVSZIP=N",
126         is_success    => 0,
127         result_code   => 126,
128         authorization => "010101",
129         avs_code      => "N",
130         cvv2_response => "Y",
131     );
132 }
133
134 SKIP: {    # cvv2_response() / CVV2MATCH
135
136     skip "CVV2 tests broken", 14;
137
138     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
139
140     # IF CVV2 >= 301 and <= 600 THEN CVV2MATCH == "N"
141     $tx->content( %content, "cvv2" => "301" );
142     tx_check(
143         $tx,
144         desc          => "cvv2(301)",
145         is_success    => 0,
146         result_code   => 126,
147         authorization => "010101",
148         avs_code      => "Y",
149         cvv2_response => "N",
150     );
151
152     # IF CVV2 >= 601 THEN CVV2MATCH == "X"
153     $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
154     $tx->content( %content, "cvv2" => "601" );
155     tx_check(
156         $tx,
157         desc          => "cvv2(601)",
158         is_success    => 0,
159         result_code   => 126,
160         authorization => "010101",
161         avs_code      => "Y",
162         cvv2_response => "X",
163     );
164 }
165
166 SKIP: {    # refund test
167
168     skip "credit/refund tests broken", 7;
169
170     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
171     $tx->content( %content, 'action' => "Credit",
172                             'card_number' => "4444333322221111",
173                 );
174     tx_check(
175         $tx,
176         desc          => "refund/credit",
177         is_success    => 0,
178         result_code   => "000",
179         authorization => '',
180         avs_code      => '',
181         cvv2_response => '',
182     );
183 }
184
185 SKIP: {    # void test
186
187     skip "void tests broken", 7;
188
189     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
190     $tx->content( %content, 'action' => "Void",
191                             'order_number' => "12345678901234",
192                 );
193     tx_check(
194         $tx,
195         desc          => "void",
196         is_success    => 0,
197         result_code   => "000",
198         authorization => '',
199         avs_code      => '',
200         cvv2_response => '',
201     );
202 }
203
204 sub tx_check {
205     my $tx = shift;
206     my %o  = @_;
207
208     $tx->test_transaction(1);
209     $tx->submit;
210
211     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
212     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
213     is( $tx->authorization, $o{authorization}, "authorization() / AUTHCODE" );
214     is( $tx->avs_code,  $o{avs_code},  "avs_code() / AVSADDR and AVSZIP" );
215     is( $tx->cvv2_response, $o{cvv2_response}, "cvv2_response() / CVV2MATCH" );
216     is( scalar(@{$tx->junk}), 0, "junk() / JUNK " );
217     like( $tx->order_number, qr/^(\d{14}|)$/, "order_number() / PNREF" );
218 }
219
220 sub tx_info {
221     my $tx = shift;
222
223     no warnings 'uninitialized';
224
225     return (
226         join( "",
227             "is_success(",     $tx->is_success,    ")",
228             " order_number(",  $tx->order_number,  ")",
229             " result_code(",   $tx->result_code,   ")",
230             " auth_info(",     $tx->authorization, ")",
231             " avs_code(",      $tx->avs_code,      ")",
232             " cvv2_response(", $tx->cvv2_response, ")",
233             $tx->junk ? " junk(". join('|', @{$tx->junk}). ")" : '',
234         )
235     );
236 }