don't die when we do not know how to perform the transaction
[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, ELINK_ACH_PASSWORD"
13   . " ELINK_ROUTING_CODE, ELINK_BANK_ACCOUNT, ELINK_ACH_NAME"
14   . " ELINK_ACH_ADDRESS, ELINK_ACH_CITY, ELINK_ACH_STATE"
15   . " ELINK_ACH_ZIP, ELINK_ACH_PHONE";
16
17 plan(
18       ( $ENV{"ELINK_ACH_ACCOUNT"} && $ENV{"ELINK_ACH_PASSWORD"} &&
19         $ENV{"ELINK_ROUTING_CODE"} && $ENV{"ELINK_BANK_ACCOUNT"} &&
20         $ENV{"ELINK_ACH_NAME"} && $ENV{"ELINK_ACH_ADDRESS"} &&
21         $ENV{"ELINK_ACH_CITY"} && $ENV{"ELINK_ACH_STATE"} &&
22         $ENV{"ELINK_ACH_ZIP"} && $ENV{"ELINK_ACH_PHONE"} 
23       )
24     ? ( tests => 12 )
25     : ( skip_all => $runinfo )
26 );
27
28 my %opts = (
29     "debug"    => 0,
30     "merchantcustservnum" => "8005551212",
31 );
32
33 my %content = (
34     login          => $ENV{"ELINK_ACH_ACCOUNT"},
35     password       => $ENV{"ELINK_ACH_PASSWORD"},
36     action         => "Normal Authorization",
37     type           => "CHECK",
38     description    => "Business::OnlinePayment::TransFirsteLink live test",
39     routing_code   => $ENV{"ELINK_ROUTING_CODE"},
40     account_number => $ENV{"ELINK_BANK_ACCOUNT"},
41     check_number   => "99",
42     amount         => "1.01",
43     invoice_number => "LiveTest",
44     customer_id    => "LiveTestCust",
45     account_name   => $ENV{"ELINK_ACH_NAME"},
46     address        => $ENV{"ELINK_ACH_ADDRESS"},
47     city           => $ENV{"ELINK_ACH_CITY"},
48     state          => $ENV{"ELINK_ACH_STATE"},
49     zip            => $ENV{"ELINK_ACH_ZIP"},
50     phone          => $ENV{"ELINK_ACH_PHONE"},
51 );
52
53 {    # valid account test
54     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
55     $tx->content(%content);
56     tx_check(
57         $tx,
58         desc          => "valid account",
59         is_success    => 1,
60         result_code   => "P00",
61     );
62 }
63
64 {    # invalid account test
65
66     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
67     $tx->content( %content, routing_code   => "052000113",
68                             account_number => "000000000001",
69                 );
70
71     tx_check(
72         $tx,
73         desc          => "invalid account",
74         is_success    => 0,
75         result_code   => 'D10',
76     );
77 }
78
79 {    # credit/refund test
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    => 1,
88         result_code   => "ACCEPTED",
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 }