892f3679e1ae4e23e13bd1e8935d5ef9b887e462
[Business-OnlinePayment-IPPay.git] / t / check.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('check');
7 plan tests => 16;
8
9 use_ok 'Business::OnlinePayment';
10
11 my %content = (
12     type           => 'CHECK',
13     login          => $login,
14     password       => $password,
15     action         => 'Normal Authorization',
16     amount         => '49.95',
17     customer_id    => 'jsk',
18     name           => 'Tofu Beast',
19     account_number => '12345',
20     routing_code   => '111000025',  # BoA in Texas taken from Wikipedia
21     bank_name      => 'First National Test Bank',
22     account_type   => 'Business Checking',
23 );
24
25 my $voidable;
26
27 #check test
28 {
29   my $ctx = Business::OnlinePayment->new("IPPay", %opt);
30   $ctx->content(%content);
31   tx_check(
32     $ctx,
33     desc          => 'normal ACH transaction',
34     is_success    => 1,
35     result_code   => '000',
36     error_message => 'CHECK ACCEPTED',
37     authorization => qr/^000000$/,
38     name          => 'Tofu Beast',
39   );
40   $voidable = $ctx->order_number if $ctx->is_success;
41 }
42
43 #check void test
44 {
45   my $ctx = Business::OnlinePayment->new("IPPay", %opt);
46   $ctx->content(%content, action => 'void', order_number => $voidable);
47   tx_check(
48     $ctx,
49     desc          => 'ACH void transaction',
50     is_success    => 1,
51     result_code   => '000',
52     error_message => 'CHECK ACCEPTED',
53     authorization => qr/^000000$/,
54   );
55 }
56
57 #check credit test
58 {
59   my $ctx = Business::OnlinePayment->new("IPPay", %opt);
60   $ctx->content(%content, action => 'credit');
61   tx_check(
62     $ctx,
63     desc          => 'ACH credit transaction',
64     is_success    => 1,
65     result_code   => '000',
66     error_message => 'CHECK ACCEPTED',
67     authorization => qr/^000000$/,
68   );
69 }
70
71 sub tx_check {
72     my $tx = shift;
73     my %o  = @_;
74
75     $tx->test_transaction(1);
76     $tx->submit;
77
78     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
79     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
80     is( $tx->error_message, $o{error_message}, "error_message() / RESPMSG" );
81     like( $tx->authorization, $o{authorization}, "authorization() / AUTHCODE" );
82     like( $tx->order_number, qr/^\w{18}/, "order_number() / PNREF" );
83 }
84
85 sub tx_info {
86     my $tx = shift;
87
88     no warnings 'uninitialized';
89
90     return (
91         join( "",
92             "is_success(",     $tx->is_success,    ")",
93             " order_number(",  $tx->order_number,  ")",
94             " error_message(", $tx->error_message, ")",
95             " result_code(",   $tx->result_code,   ")",
96             " auth_info(",     $tx->authorization, ")",
97         )
98     );
99 }
100