File: check.t

package info (click to toggle)
libbusiness-onlinepayment-ippay-perl 0.06-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 176 kB
  • sloc: perl: 644; makefile: 2
file content (100 lines) | stat: -rw-r--r-- 2,644 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl -w

use Test::More skip_all => 'Skip network tests in Debian build';
require "t/lib/test_account.pl";

my($login, $password, %opt) = test_account_or_skip('check');
plan tests => 16;

use_ok 'Business::OnlinePayment';

my %content = (
    type           => 'CHECK',
    login          => $login,
    password       => $password,
    action         => 'Normal Authorization',
    amount         => '49.95',
    customer_id    => 'jsk',
    name           => 'Tofu Beast',
    account_number => '12345',
    routing_code   => '111000025',  # BoA in Texas taken from Wikipedia
    bank_name      => 'First National Test Bank',
    account_type   => 'Checking',
);

my $voidable;

#check test
{
  my $ctx = Business::OnlinePayment->new("IPPay", %opt);
  $ctx->content(%content);
  tx_check(
    $ctx,
    desc          => 'normal ACH transaction',
    is_success    => 1,
    result_code   => '000',
    error_message => 'CHECK ACCEPTED',
    authorization => qr/^000000$/,
    name          => 'Tofu Beast',
  );
  $voidable = $ctx->order_number if $ctx->is_success;
}

#check void test
{
  my $ctx = Business::OnlinePayment->new("IPPay", %opt);
  $ctx->content(%content, action => 'void', order_number => $voidable);
  tx_check(
    $ctx,
    desc          => 'ACH void transaction',
    is_success    => 1,
    result_code   => '000',
    error_message => 'CHECK ACCEPTED',
    authorization => qr/^000000$/,
  );
}

#check credit test
{
  my $ctx = Business::OnlinePayment->new("IPPay", %opt);
  $ctx->content(%content, action => 'credit');
  tx_check(
    $ctx,
    desc          => 'ACH credit transaction',
    is_success    => 1,
    result_code   => '000',
    error_message => 'CHECK ACCEPTED',
    authorization => qr/^000000$/,
  );
}

sub tx_check {
    my $tx = shift;
    my %o  = @_;

    $tx->test_transaction(1);
    $tx->submit;

    is( $tx->is_success,    $o{is_success},    "$o{desc}: " . tx_info($tx) );
    is( $tx->result_code,   $o{result_code},   "result_code(): RESULT" );
    is( $tx->error_message, $o{error_message}, "error_message() / RESPMSG" );
    like( $tx->authorization, $o{authorization}, "authorization() / AUTHCODE" );
    like( $tx->order_number, qr/^\w{18}/, "order_number() / PNREF" );
}

sub tx_info {
    my $tx = shift;

    no warnings 'uninitialized';

    return (
        join( "",
            "is_success(",     $tx->is_success,    ")",
            " order_number(",  $tx->order_number,  ")",
            " error_message(", $tx->error_message, ")",
            " result_code(",   $tx->result_code,   ")",
            " auth_info(",     $tx->authorization, ")",
        )
    );
}