initial checkin
[Business-OnlinePayment-ElavonVirtualMerchant.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) ELAVON_ACCOUNT, ELAVON_USERID, and ELAVON_PASSWORD"
13   . " (optional) DEBUG, ELAVON_SERVER, and ELAVON_PATH";
14
15 plan(
16       (   $ENV{"ELAVON_ACCOUNT"}
17        && $ENV{"ELAVON_USERID"}
18        && $ENV{"ELAVON_PASSWORD"} )
19     ? ( tests => 42 )
20     : ( skip_all => $runinfo )
21 );
22
23 my %opts = (
24     "debug"                      => $ENV{"DEBUG"} || 0,
25     "default_ssl_user_id"        => $ENV{"ELAVON_USERID"},
26     "default_ssl_salestax"       => "0.00",
27     "default_ssl_customer_code"  => "TESTCUSTOMER",
28 );
29
30 my %content = (
31     login          => $ENV{"ELAVON_ACCOUNT"},
32     password       => $ENV{"ELAVON_PASSWORD"},
33     action         => "Normal Authorization",
34     type           => "VISA",
35     description    => "Business::OnlinePayment::ElavonVirtualMerchant test",
36     card_number    => "4111111111111111",
37     cvv2           => "123",
38     expiration     => "12/" . strftime( "%y", localtime ),
39     amount         => "0.01",
40     invoice_number => "Test1",
41     first_name     => "Tofu",
42     last_name      => "Beast",
43     email          => 'nobody@example.com',
44     address        => "123 Anystreet",
45     city           => "Anywhere",
46     state          => "GA",
47     zip            => "30004",
48     country        => "US",
49 );
50
51 {    # valid card number test
52     my $tx = new Business::OnlinePayment( "ElavonVirtualMerchant", %opts );
53     $tx->content(%content);
54     tx_check(
55         $tx,
56         desc          => "valid card_number",
57         is_success    => 1,
58         result_code   => "0",
59         authorization => "123456",
60         avs_code      => "X",
61         cvv2_response => "P",
62         order_number  => "00000000-0000-0000-0000-00000000000",
63     );
64 }
65
66 {    # invalid card number test
67
68     my $tx = new Business::OnlinePayment( "ElavonVirtualMerchant", %opts );
69     $tx->content( %content, card_number => "4111111111111112" );
70     tx_check(
71         $tx,
72         desc          => "invalid card_number",
73         is_success    => 0,
74         result_code   => 5000,
75         authorization => undef,
76         avs_code      => undef,
77         cvv2_response => undef,
78         order_number  => undef,
79     );
80 }
81
82
83 SKIP: {    # avs_code() / AVSZIP and AVSADDR tests
84
85     skip "AVS tests broken", 18;
86
87     my $tx = new Business::OnlinePayment( "ElavonVirtualMerchant", %opts );
88
89     $tx->content( %content, "address" => "500 Any street" );
90     tx_check(
91         $tx,
92         desc          => "AVSADDR=N,AVSZIP=Y",
93         is_success    => 1,
94         result_code   => "0",
95         authorization => "123456",
96         avs_code      => "Z",
97         cvv2_response => "P",
98         order_number  => "00000000-0000-0000-0000-00000000000",
99     );
100
101     $tx = new Business::OnlinePayment( "ElavonVirtualMerchant", %opts );
102     $tx->content( %content, "zip" => "99999" );
103     tx_check(
104         $tx,
105         desc          => "AVSADDR=Y,AVSZIP=N",
106         is_success    => 1,
107         result_code   => "0",
108         authorization => "123456",
109         avs_code      => "A",
110         cvv2_response => "P",
111         order_number  => "00000000-0000-0000-0000-00000000000",
112     );
113
114     $tx = new Business::OnlinePayment( "ElavonVirtualMerchant", %opts );
115     $tx->content( %content, "address" => "500 Any street", "zip" => "99999" );
116     tx_check(
117         $tx,
118         desc          => "AVSADDR=N,AVSZIP=N",
119         is_success    => 1,
120         result_code   => "0",
121         authorization => "123456",
122         avs_code      => "N",
123         cvv2_response => "P",
124         order_number  => "00000000-0000-0000-0000-00000000000",
125     );
126 }
127
128 SKIP: {    # cvv2_response() / CVV2MATCH
129
130     skip "CVV2 tests broken", 6;
131
132     my $tx = new Business::OnlinePayment( "ElavonVirtualMerchant", %opts );
133
134     $tx->content( %content, "cvv2" => "301" );
135     tx_check(
136         $tx,
137         desc          => "wrong cvv2",
138         is_success    => 1,
139         result_code   => "0",
140         authorization => "123456",
141         avs_code      => "X",
142         cvv2_response => "N",
143         order_number  => "00000000-0000-0000-0000-00000000000",
144     );
145
146 }
147
148 SKIP: {    # refund test
149
150     skip "credit/refund tests broken", 6;
151
152     my $tx = new Business::OnlinePayment( "ElavonVirtualMerchant", %opts );
153     $tx->content( %content, 'action' => "Credit",
154                             'card_number' => "4444333322221111",
155                 );
156     tx_check(
157         $tx,
158         desc          => "refund/credit",
159         is_success    => 1,
160         result_code   => "0",
161         authorization => undef,
162         avs_code      => undef,
163         cvv2_response => undef,
164         order_number  => "00000000-0000-0000-0000-00000000000",
165     );
166 }
167
168 sub tx_check {
169     my $tx = shift;
170     my %o  = @_;
171
172     $tx->test_transaction(1);
173     $tx->server($ENV{"ELAVON_SERVER"}) if defined($ENV{"ELAVON_SERVER"});
174     $tx->path($ENV{"ELAVON_PATH"}) if defined($ENV{"ELAVON_PATH"});
175     $tx->submit;
176
177     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
178     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
179     is( $tx->authorization, $o{authorization}, "authorization() / AUTHCODE" );
180     is( $tx->avs_code,  $o{avs_code},  "avs_code() / AVSADDR and AVSZIP" );
181     is( $tx->cvv2_response, $o{cvv2_response}, "cvv2_response() / CVV2MATCH" );
182     is( $tx->order_number, $o{order_number}, "order_number() / PNREF" );
183 }
184
185 sub tx_info {
186     my $tx = shift;
187
188     no warnings 'uninitialized';
189
190     return (
191         join( "",
192             "is_success(",     $tx->is_success,    ")",
193             " order_number(",  $tx->order_number,  ")",
194             " result_code(",   $tx->result_code,   ")",
195             " auth_info(",     $tx->authorization, ")",
196             " avs_code(",      $tx->avs_code,      ")",
197             " cvv2_response(", $tx->cvv2_response, ")",
198         )
199     );
200 }