Initial import
[Business-OnlinePayment-TransFirsteLink.git] / t / echeck.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) ELINK_ACH_ACCOUNT and ELINK_ACH_PASSWORD";
13
14 plan(
15       ( $ENV{"ELINK_ACH_ACCOUNT"} && $ENV{"ELINK_ACH_PASSWORD"} )
16     ? ( tests => 12 )
17     : ( skip_all => $runinfo )
18 );
19
20 my %opts = (
21     "debug"    => 0,
22     "merchantcustservnum" => "8005551212",
23 );
24
25 my %content = (
26     login          => $ENV{"ELINK_ACH_ACCOUNT"},
27     password       => $ENV{"ELINK_ACH_PASSWORD"},
28     action         => "Normal Authorization",
29     type           => "CHECK",
30     description    => "Business::OnlinePayment::TransFirsteLink test",
31     routing_code   => "052000113",
32     account_number => "000000000001",
33     check_number   => "100",
34     cvv2           => "123",
35     expiration     => "12/" . strftime( "%y", localtime ),
36     amount         => "0.01",
37     invoice_number => "1999",
38     account_name   => "Tofu Beast",
39     customer_id    => "TB01",
40     email          => 'transfirst@weasellips.com',
41     address        => "123 Anystreet",
42     city           => "Anywhere",
43     state          => "GA",
44     zip            => "30004",
45     country        => "US",
46     phone          => "4045551212",
47 );
48
49 {    # valid account test
50     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
51     $tx->content(%content);
52     tx_check(
53         $tx,
54         desc          => "valid account",
55         is_success    => 1,
56         result_code   => "P00",
57     );
58 }
59
60 SKIP: {    # invalid account test
61
62     skip "invalid account tests broken", 4;
63
64     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
65     $tx->content( %content, routing_code   => "052000113",
66                             account_number => "000000000001",
67                 );
68
69     tx_check(
70         $tx,
71         desc          => "invalid account",
72         is_success    => 0,
73         result_code   => 214,
74     );
75 }
76
77 SKIP: {    # credit/refund test
78
79     skip "credit/refund tests broken", 4;
80
81     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
82     $tx->content( %content, action => "Credit");
83
84     tx_check(
85         $tx,
86         desc          => "credit/refund",
87         is_success    => 0,
88         result_code   => "P00",
89     );
90 }
91
92 sub tx_check {
93     my $tx = shift;
94     my %o  = @_;
95
96     $tx->test_transaction(1);
97     $tx->submit;
98
99     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
100     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
101     is( scalar(@{$tx->junk}), 0, "junk() / JUNK " );
102     like( $tx->order_number, qr/^(\d{9}|)$/, "order_number() / PNREF" );
103 }
104
105 sub tx_info {
106     my $tx = shift;
107
108     no warnings 'uninitialized';
109
110     return (
111         join( "",
112             "is_success(",     $tx->is_success,    ")",
113             " order_number(",  $tx->order_number,  ")",
114             " result_code(",   $tx->result_code,   ")",
115             $tx->junk ? " junk(". join('|', @{$tx->junk}). ")" : '',
116         )
117     );
118 }