don't die when we do not know how to perform the transaction
[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 => 56 )
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", 21;
79
80     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
81
82     $tx->content( %content, "address" => "500 Any street" );
83     tx_check(
84         $tx,
85         desc          => "AVSADDR=N,AVSZIP=Y",
86         is_success    => 1,
87         result_code   => "000",
88         authorization => "999999",
89         avs_code      => "Z",
90         cvv2_response => "M",
91     );
92
93     $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
94     $tx->content( %content, "zip" => "99999" );
95     tx_check(
96         $tx,
97         desc          => "AVSADDR=Y,AVSZIP=N",
98         is_success    => 1,
99         result_code   => "000",
100         authorization => "999999",
101         avs_code      => "A",
102         cvv2_response => "M",
103     );
104
105     $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
106     $tx->content( %content, "address" => "500 Any street", "zip" => "99999" );
107     tx_check(
108         $tx,
109         desc          => "AVSADDR=N,AVSZIP=N",
110         is_success    => 1,
111         result_code   => "000",
112         authorization => "999999",
113         avs_code      => "N",
114         cvv2_response => "M",
115     );
116 }
117
118 SKIP: {    # cvv2_response() / CVV2MATCH
119
120     skip "CVV2 tests broken", 7;
121
122     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
123
124     $tx->content( %content, "cvv2" => "301" );
125     tx_check(
126         $tx,
127         desc          => "wrong cvv2",
128         is_success    => 1,
129         result_code   => "000",
130         authorization => "999999",
131         avs_code      => "Y",
132         cvv2_response => "N",
133     );
134
135 }
136
137 SKIP: {    # refund test
138
139     #skip "credit/refund tests broken", 7;
140
141     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
142     $tx->content( %content, 'action' => "Credit",
143                             'card_number' => "4444333322221111",
144                 );
145     tx_check(
146         $tx,
147         desc          => "refund/credit",
148         is_success    => 1,
149         result_code   => "000",
150         authorization => '',
151         avs_code      => '',
152         cvv2_response => '',
153     );
154 }
155
156 SKIP: {    # void test
157
158     #skip "void tests broken", 7;
159
160     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
161     $tx->content( %content, 'action' => "Void",
162                             'order_number' => "12345678901234",
163                 );
164     tx_check(
165         $tx,
166         desc          => "void",
167         is_success    => 1,
168         result_code   => "000",
169         authorization => '',
170         avs_code      => '',
171         cvv2_response => '',
172     );
173 }
174
175 sub tx_check {
176     my $tx = shift;
177     my %o  = @_;
178
179     $tx->test_transaction(1);
180     $tx->submit;
181
182     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
183     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
184     is( $tx->authorization, $o{authorization}, "authorization() / AUTHCODE" );
185     is( $tx->avs_code,  $o{avs_code},  "avs_code() / AVSADDR and AVSZIP" );
186     is( $tx->cvv2_response, $o{cvv2_response}, "cvv2_response() / CVV2MATCH" );
187     is( scalar(@{$tx->junk}), 0, "junk() / JUNK " );
188     like( $tx->order_number, qr/^(\d{14}|)$/, "order_number() / PNREF" );
189 }
190
191 sub tx_info {
192     my $tx = shift;
193
194     no warnings 'uninitialized';
195
196     return (
197         join( "",
198             "is_success(",     $tx->is_success,    ")",
199             " order_number(",  $tx->order_number,  ")",
200             " result_code(",   $tx->result_code,   ")",
201             " auth_info(",     $tx->authorization, ")",
202             " avs_code(",      $tx->avs_code,      ")",
203             " cvv2_response(", $tx->cvv2_response, ")",
204             $tx->junk ? " junk(". join('|', @{$tx->junk}). ")" : '',
205         )
206     );
207 }