s/JetPay/ippay/ per new spec
[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 => 11;
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 #VOIDACH transactions are no longer supported.  Please contact support@ippay.com for questions.
44 ##check void test
45 #{
46 #  my $ctx = Business::OnlinePayment->new("IPPay", %opt);
47 #  $ctx->content(%content, action => 'void', order_number => $voidable);
48 #  tx_check(
49 #    $ctx,
50 #    desc          => 'ACH void transaction',
51 #    is_success    => 1,
52 #    result_code   => '000',
53 #    error_message => 'CHECK ACCEPTED',
54 #    authorization => qr/^000000$/,
55 #  );
56 #}
57
58 #check credit test
59 {
60   my $ctx = Business::OnlinePayment->new("IPPay", %opt);
61   $ctx->content(%content, action => 'credit');
62   tx_check(
63     $ctx,
64     desc          => 'ACH credit transaction',
65     is_success    => 1,
66     result_code   => '000',
67     error_message => 'CHECK ACCEPTED',
68     authorization => qr/^000000$/,
69   );
70 }
71
72 sub tx_check {
73     my $tx = shift;
74     my %o  = @_;
75
76     $tx->test_transaction(1);
77     $tx->submit;
78
79     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
80     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
81     is( $tx->error_message, $o{error_message}, "error_message() / RESPMSG" );
82     like( $tx->authorization, $o{authorization}, "authorization() / AUTHCODE" );
83     like( $tx->order_number, qr/^\w{18}/, "order_number() / PNREF" );
84 }
85
86 sub tx_info {
87     my $tx = shift;
88
89     no warnings 'uninitialized';
90
91     return (
92         join( "",
93             "is_success(",     $tx->is_success,    ")",
94             " order_number(",  $tx->order_number,  ")",
95             " error_message(", $tx->error_message, ")",
96             " result_code(",   $tx->result_code,   ")",
97             " auth_info(",     $tx->authorization, ")",
98         )
99     );
100 }
101