don't die when we do not know how to perform the transaction
[Business-OnlinePayment-TransFirsteLink.git] / t / live_check.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, ELINK_DO_LIVE";
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         $ENV{"ELINK_DO_LIVE"}
24       )
25     ? ( tests => 12 )
26     : ( skip_all => $runinfo )
27 );
28
29 my %opts = (
30     "debug"    => 0,
31     "merchantcustservnum" => "8005551212",
32 );
33
34 my %content = (
35     login          => $ENV{"ELINK_ACH_ACCOUNT"},
36     password       => $ENV{"ELINK_ACH_PASSWORD"},
37     action         => "Normal Authorization",
38     type           => "CHECK",
39     description    => "Business::OnlinePayment::TransFirsteLink live test",
40     routing_code   => $ENV{"ELINK_ROUTING_CODE"},
41     account_number => $ENV{"ELINK_BANK_ACCOUNT"},
42     check_number   => "99",
43     amount         => "1.01",
44     invoice_number => "LiveTest",
45     customer_id    => "LiveTestCust",
46     account_name   => $ENV{"ELINK_ACH_NAME"},
47     address        => $ENV{"ELINK_ACH_ADDRESS"},
48     city           => $ENV{"ELINK_ACH_CITY"},
49     state          => $ENV{"ELINK_ACH_STATE"},
50     zip            => $ENV{"ELINK_ACH_ZIP"},
51     phone          => $ENV{"ELINK_ACH_PHONE"},
52 );
53
54 {    # valid account test
55     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
56     $tx->content(%content);
57     tx_check(
58         $tx,
59         desc          => "valid account",
60         is_success    => 1,
61         result_code   => "P00",
62     );
63 }
64
65 SKIP: {    # invalid account test
66
67     skip "invalid account tests broken", 4;
68
69     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
70     $tx->content( %content, routing_code   => "052000113",
71                             account_number => "000000000001",
72                 );
73
74     tx_check(
75         $tx,
76         desc          => "invalid account",
77         is_success    => 0,
78         result_code   => 214,
79     );
80 }
81
82 {    # credit/refund test
83
84     my $tx = new Business::OnlinePayment( "TransFirsteLink", %opts );
85     $tx->content( %content, action => "Credit");
86
87     tx_check(
88         $tx,
89         desc          => "credit/refund",
90         is_success    => 1,
91         result_code   => "ACCEPTED",
92     );
93 }
94
95 sub tx_check {
96     my $tx = shift;
97     my %o  = @_;
98
99     $tx->submit;
100
101     is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
102     is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
103     is( scalar(@{$tx->junk}), 0, "junk() / JUNK " );
104     like( $tx->order_number, qr/^(\d{9}|)$/, "order_number() / PNREF" );
105 }
106
107 sub tx_info {
108     my $tx = shift;
109
110     no warnings 'uninitialized';
111
112     return (
113         join( "",
114             "is_success(",     $tx->is_success,    ")",
115             " order_number(",  $tx->order_number,  ")",
116             " result_code(",   $tx->result_code,   ")",
117             $tx->junk ? " junk(". join('|', @{$tx->junk}). ")" : '',
118         )
119     );
120 }