s/JetPay/ippay/ per new spec
[Business-OnlinePayment-IPPay.git] / t / card.t
1 #!/usr/bin/perl -w
2
3 use Test::More;
4 require "t/lib/test_account.pl";
5
6 my($login, $password, %opt) = test_account_or_skip('card');
7 plan tests => 50;
8   
9 use_ok 'Business::OnlinePayment';
10
11 my %content = (
12     type           => 'VISA',
13     login          => $login,
14     password       => $password,
15     action         => 'Normal Authorization',
16     description    => 'Business::OnlinePayment visa test',
17 #    card_number    => '4007000000027',
18     card_number    => '4111111111111111',
19     cvv2           => '123',
20     expiration     => expiration_date(),
21     amount         => '49.95',
22     name           => 'Tofu Beast',
23     email          => 'ippay@weasellips.com',
24     address        => '123 Anystreet',
25     city           => 'Anywhere',
26     state          => 'UT',
27     zip            => '84058',
28     country        => 'US',      # will be forced to USA
29     customer_id    => 'tfb',
30 );
31
32 my $voidable;
33 my $voidable_auth;
34 my $voidable_amount = 0;
35
36 # valid card number test
37 {
38   my $tx = Business::OnlinePayment->new("IPPay", %opt);
39   $tx->content(%content);
40   tx_check(
41     $tx,
42     desc          => "valid card_number",
43     is_success    => 1,
44     result_code   => '000',
45     error_message => 'APPROVED',
46     authorization => qr/TEST\d{2}/,
47 #    avs_code      => 'U',          # so rather pointless :\
48     avs_code      => 'Y',          # so very pointless :\
49     cvv2_response => 'P',          # ...
50   );
51   $voidable = $tx->order_number if $tx->is_success;
52   $voidable_auth = $tx->authorization if $tx->is_success;
53   $voidable_amount = $content{amount} if $tx->is_success;
54 }
55
56 # invalid card number test
57 {
58   my $tx = Business::OnlinePayment->new("IPPay", %opt);
59   $tx->content(%content, card_number => "4111111111111112" );
60   tx_check(
61     $tx,
62     desc          => "invalid card_number",
63     is_success    => 0,
64     result_code   => '900', #'912' with old jetpay gw
65     error_message => 'Invalid card number.  ', #'INVALID CARD NUMBER' w/old gw
66     authorization => qr/^$/,
67     avs_code      => '',           # so rather pointless :\
68     cvv2_response => '',           # ...
69   );
70 }
71
72 # authorization only test
73 {
74   my $tx = Business::OnlinePayment->new("IPPay", %opt);
75   $tx->content(%content, action => 'authorization only',  amount => '3.00' );
76   tx_check(
77     $tx,
78     desc          => "authorization only",
79     is_success    => 1,
80     result_code   => '000',
81     error_message => 'APPROVED',
82     authorization => qr/TEST\d{2}/,
83 #    avs_code      => 'U',          # so rather pointless :\
84     avs_code      => 'Y',          # so very pointless :\
85     cvv2_response => 'P',          # ...
86   );
87   $postable = $tx->order_number if $tx->is_success;
88   $postable_auth = $tx->authorization if $tx->is_success;
89   $postable_amount = $content{amount} if $tx->is_success;
90 }
91
92 # authorization void test
93 SKIP: {
94   #XXX void is returning "The transaction type is not a valid transaction type."
95   # with current IPPay.  did something change about the API, is this broken?
96   skip 'Reverse Authorization not currently working (against test account?)', 7;
97
98   my $tx = Business::OnlinePayment->new("IPPay", %opt);
99   $tx->content(%content, action => 'authorization only',  amount => '3.00' );
100   $tx->test_transaction(1);
101   $tx->submit;
102
103   if ($tx->is_success) {
104     my $void_tx = Business::OnlinePayment->new("IPPay", %opt );
105
106     $tx->content(%content, action       => 'reverse authorization',
107                            order_number => $tx->order_number );
108     tx_check(
109       $tx,
110       desc          => "reverse authorization",
111       is_success    => 1,
112       result_code   => '000',
113       error_message => 'APPROVED',
114       authorization => qr/TEST\d{2}/,
115       avs_code      => '',          # so rather pointless :\
116       cvv2_response => '',          # ...
117     );
118   }
119   else {
120     
121   }
122 }
123
124 # post authorization test
125 SKIP: {
126   my $tx = new Business::OnlinePayment( "IPPay", %opt );
127   $tx->content( %content, 'action'       => "post authorization", 
128                           'amount'       => $postable_amount,    # not required
129                           'order_number' => $postable,
130               );
131   tx_check(
132     $tx,
133     desc          => "post authorization",
134     is_success    => 1,
135     result_code   => '000',
136     error_message => 'APPROVED',
137     authorization => qr/^$postable_auth$/,
138     avs_code      => '',
139     cvv2_response => '',
140     );
141 }
142
143 # void test
144 SKIP: {
145   my $tx = new Business::OnlinePayment( "IPPay", %opt );
146   $tx->content( %content, 'action' => "Void",
147                           'order_number' => $voidable,
148                           'authorization' => $voidable_auth,
149               );
150   tx_check(
151     $tx,
152     desc          => "void",
153     is_success    => 1,
154     result_code   => '000',
155     error_message => 'VOID PROCESSED',
156     authorization => qr/^$voidable_auth$/,
157     avs_code      => '',
158     cvv2_response => '',
159     );
160 }
161
162 # credit test
163 SKIP: {
164   my $tx = new Business::OnlinePayment( "IPPay", %opt );
165   $tx->content( %content, 'action' => "credit");
166   tx_check(
167     $tx,
168     desc          => "credit",
169     is_success    => 1,
170     result_code   => '000',
171     error_message => 'RETURN ACCEPTED',
172     authorization => qr/\d{6}/,
173     avs_code      => '',
174     cvv2_response => '',
175     );
176 }
177
178
179 sub tx_check {
180     my $tx = shift;
181     my %o  = @_;
182
183     $tx->test_transaction(1);
184     $tx->submit;
185
186     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
187     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
188     is( $tx->error_message, $o{error_message}, "error_message() / RESPMSG" );
189     like( $tx->authorization, $o{authorization}, "authorization() / AUTHCODE" );
190     is( $tx->avs_code,  $o{avs_code},  "avs_code() / AVSADDR and AVSZIP" );
191     is( $tx->cvv2_response, $o{cvv2_response}, "cvv2_response() / CVV2MATCH" );
192     like( $tx->order_number, qr/^\w{18}/, "order_number() / PNREF" );
193 }
194
195 sub tx_info {
196     my $tx = shift;
197
198     no warnings 'uninitialized';
199
200     return (
201         join( "",
202             "is_success(",     $tx->is_success,    ")",
203             " order_number(",  $tx->order_number,  ")",
204             " error_message(", $tx->error_message, ")",
205             " result_code(",   $tx->result_code,   ")",
206             " auth_info(",     $tx->authorization, ")",
207             " avs_code(",      $tx->avs_code,      ")",
208             " cvv2_response(", $tx->cvv2_response, ")",
209         )
210     );
211 }
212