summaryrefslogtreecommitdiff
path: root/t/02-ach.t
blob: 4ff80ffec9f9aa54fc906939a3347eb396ab8ce7 (plain)
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
use Test::More tests => 3;

use Business::OnlinePayment;

my %defaults = (
  name       => 'Joe Tester',
  address    => '888',
  city       => 'Nowhere',
  state      => 'CA',
  zip        => '77777',
  phone      => '510-555-0021',
  email      => 'joe@example.com',
  description => 'Business::OnlinePayment::NMI Test',

  action     => 'Normal Authorization',
  account_number => '222223333344', # meaningless
  routing_code => '411151111',
  amount     => '13.00',
  );

# SALE
my %content = %defaults;
my $ordernum = ok_test(\%content, 'echeck sale');

#VOID
%content = (
  action => 'Void',
  order_number => $ordernum,
);
ok_test(\%content, 'echeck void');

#FAILURE
%content = %defaults;
$content{amount} = '0.10'; # amounts < 1.00 are declined on the demo account
$content{fail} = 1;
ok_test(\%content, 'echeck decline');

sub ok_test {
  my ($content, $label) = @_;
  my $fail = delete $content{fail} or 0;
  my $trans = new Business::OnlinePayment('NMI');
  $trans->content(
    login    => 'demo',
    password => 'password',
    type     => 'echeck',
    %$content
  );
  $trans->submit;
  diag($trans->error_message) if (!$fail and $trans->error_message);
  if($fail) {
    ok(!$trans->is_success, $label)
  }
  else {
    ok($trans->is_success, $label);
  }
  return $trans->order_number;
}

1;