Adding post-auth, void
[Business-OnlinePayment-Bambora.git] / t / 022-payments-card-pre-authorization.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5
6 use lib 't';
7 require 'TestFixtures.pm';
8 use Business::OnlinePayment;
9
10 my $merchant_id = $ENV{BAMBORA_MERCHANT_ID};
11 my $api_key     = $ENV{BAMBORA_API_KEY};
12
13 SKIP: {
14   skip 'Missing env vars BAMBORA_MERCHANT_ID and BAMBORA_API_KEY', 3
15     unless $merchant_id && $api_key;
16
17   my %content = (
18     login          => $merchant_id,
19     password       => $api_key,
20     action         => 'Authorization Only',
21     amount         => '9.99',
22
23     owner          => 'Freeside Internet Services',
24     name           => 'Mitch Jackson',
25     address        => '1407 Graymalkin Lane',
26     city           => 'Vancouver',
27     state          => 'BC',
28     zip            => '111 111',
29     country        => 'CA',
30
31     invoice_number => time(),
32     card_number    => '4030000010001234',
33     cvv2           => '123',
34     expiration     => '1122',
35     phone          => '251-300-1300',
36     email          => 'mitch@freeside.biz',
37   );
38
39   my $tr;
40   ok( $tr = Business::OnlinePayment->new('Bambora'), 'Instantiatiate $tr' );
41   ok( $tr->content( %content ), 'Set transaction content onto $tr' );
42   {
43     local $@;
44     eval { $tr->submit };
45     ok( !$@, "Submit pre-auth (expect approve)" );
46   }
47
48   my $response;
49   my %expect = (
50     amount => '9.99',
51     approved => 1,
52     auth_code => 'TEST',
53     message => 'Approved',
54     message_id => 1,
55     payment_method => 'CC',
56     type => 'PA',
57   );
58   my @expect = qw(
59     card
60     created
61     order_number
62     risk_score
63   );
64
65   ok( $response = $tr->response_decoded, 'response_decoded' );
66
67   for my $k ( keys %expect ) {
68     ok(
69       $response->{$k} eq $expect{$k},
70       sprintf '$tr->%s == %s', $k, $expect{$k}
71     );
72   }
73
74   for my $k ( @expect ) {
75     ok(
76       defined $response->{$k},
77       sprintf '$r->%s (%s)',
78         $k, $response->{$k}
79     );
80   }
81
82   %content = (
83     %content,
84     action => 'post authorization',
85     order_number => $tr->order_number,
86   );
87
88   my $tr_pa;
89   ok( $tr_pa = Business::OnlinePayment->new('Bambora'), 'Instantiate $tr_pa' );
90   ok( $tr->content( %content ), 'Set transaction content onto $tr_pa' );
91   {
92     local $@;
93     eval { $tr_pa->submit };
94     ok( !$@, "Submit post-auth" );
95     warn "Error: $@" if $@;
96   }
97
98   my $response_pa;
99   
100
101   ok( $response_pa = $tr_pa->response_decoded, 'response_decoded' );
102
103     # for my $attr (qw/
104     #   message_id
105     #   authorization
106     #   order_number
107     #   txn_date
108     #   avs_code
109     #   is_success
110     # /) {
111     #   ok(
112     #     defined $tr->$attr(),
113     #     sprintf '%s $tr->%s() = %s',
114     #       $name,
115     #       $attr,
116     #       $tr->$attr()
117     #   );
118     # }
119
120 }
121
122 done_testing;