add recurring_billing handling
[Business-OnlinePayment-PlugnPay.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) PNP_ACCOUNT and PNP_PASSWORD";
13
14 plan(
15       (   $ENV{"PNP_ACCOUNT"}
16        && $ENV{"PNP_PASSWORD"} )
17     ? ( tests => 30 )
18     : ( skip_all => $runinfo )
19 );
20
21 my %opts = (
22     "debug"                      => 0,
23 );
24
25 my %content = (
26     login          => $ENV{"PNP_ACCOUNT"},
27     password       => $ENV{"PNP_PASSWORD"},
28     action         => "Normal Authorization",
29     type           => "VISA",
30     description    => "Business::OnlinePayment::PlugnPay test",
31     card_number    => "4111111111111111",
32     expiration     => "12/" . strftime( "%y", localtime ),
33     amount         => "0.01",
34     name           => "cardtest",
35     cvv2           => "123",
36     invoice_number => "Test1",
37     email          => 'plugnpay@weasellips.com',
38     address        => "123 Anystreet",
39     city           => "Anywhere",
40     state          => "GA",
41     zip            => "30004",
42     country        => "US",
43     ship_first_name=> "Tofu",
44     ship_last_name => "Beast",
45     ship_address   => "456 Anystreet",
46     ship_city      => "Somewhere",
47     ship_state     => "CA",
48     ship_zip       => "90004",
49     ship_country   => "US",
50 );
51
52 {    # valid card number test
53     my $tx = new Business::OnlinePayment( "PlugnPay", %opts );
54     $tx->content(%content);
55     tx_check(
56         $tx,
57         desc          => "valid card_number",
58         is_success    => 1,
59         result_code   => "00",
60         authorization => "TSTAUT",
61         avs_code      => "U",
62         cvv2_response => "M",
63         order_number  => qr/^([0-9]{19})$/,
64     );
65 }
66
67 {    # invalid card number test
68
69     my $tx = new Business::OnlinePayment( "PlugnPay", %opts );
70     $tx->content( %content, card_number => "4111111111111112" );
71     tx_check(
72         $tx,
73         desc          => "invalid card_number",
74         is_success    => 0,
75         result_code   => "P66",
76         authorization => "",
77         avs_code      => undef,
78         cvv2_response => undef,
79         order_number  => qr/^([0-9]{19})$/,
80     );
81 }
82
83 {    # dubious faked bad card test
84
85     my $tx = new Business::OnlinePayment( "PlugnPay", %opts );
86     $tx->content( %content, amount => "1000.01" );
87     tx_check(
88         $tx,
89         desc          => "faked bad card",
90         is_success    => 0,
91         result_code   => "P30",
92         authorization => "",
93         avs_code      => undef,
94         cvv2_response => undef,
95         order_number  => qr/^([0-9]{19})$/,
96     );
97 }
98
99 {    # dubious faked problem test
100
101     my $tx = new Business::OnlinePayment( "PlugnPay", %opts );
102     $tx->content( %content, amount => "2000.01" );
103     tx_check(
104         $tx,
105         desc          => "faked problem",
106         is_success    => 0,
107         result_code   => "P35",
108         authorization => "",
109         avs_code      => undef,
110         cvv2_response => undef,
111         order_number  => qr/^([0-9]{19})$/,
112     );
113 }
114
115
116 SKIP: {    # refund test
117
118     skip "credit/refund tests broken", 6;
119
120     my $tx = new Business::OnlinePayment( "PlugnPay", %opts );
121     $tx->content( %content, 'action' => "Credit",
122                 );
123     tx_check(
124         $tx,
125         desc          => "refund/credit",
126         is_success    => 0,    # :\
127         result_code   => undef,
128         authorization => undef,
129         avs_code      => undef,
130         cvv2_response => undef,
131         order_number  => qr/^([0-9]{19})$/,
132     );
133 }
134
135 sub tx_check {
136     my $tx = shift;
137     my %o  = @_;
138
139     $tx->submit;
140
141     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
142     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
143     is( $tx->authorization, $o{authorization}, "authorization() / AUTHCODE" );
144     is( $tx->avs_code,  $o{avs_code},  "avs_code() / AVSADDR and AVSZIP" );
145     is( $tx->cvv2_response, $o{cvv2_response}, "cvv2_response() / CVV2MATCH" );
146     like( $tx->order_number, $o{order_number}, "order_number() / PNREF" );
147 }
148
149 sub tx_info {
150     my $tx = shift;
151
152     no warnings 'uninitialized';
153
154     return (
155         join( "",
156             "is_success(",     $tx->is_success,    ")",
157             " order_number(",  $tx->order_number,  ")",
158             " result_code(",   $tx->result_code,   ")",
159             " auth_info(",     $tx->authorization, ")",
160             " avs_code(",      $tx->avs_code,      ")",
161             " cvv2_response(", $tx->cvv2_response, ")",
162         )
163     );
164 }