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