863c8e1cad9c965a643ee8310890db8cbdc6e280
[Business-OnlinePayment-Bambora.git] / t / 032-payments-card-pre-authorization-complete-void.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5
6 use lib 't';
7 use TestFixtures;
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', 56
15     unless $merchant_id && $api_key;
16
17   my %content = (
18     common_content(),
19
20     login => $merchant_id,
21     password => $api_key,
22
23     action => 'Authorization Only',
24   );
25
26   #
27   # Process a pre-auth
28   #
29
30   my ( $tr, $response ) = make_api_request( \%content );
31
32   inspect_response(
33     $response,
34     {
35       amount => '9.99',
36       approved => 1,
37       auth_code => 'TEST',
38       message => 'Approved',
39       message_id => 1,
40       payment_method => 'CC',
41       type => 'PA',
42     },
43     [qw/
44       card
45       created
46       order_number
47       risk_score
48       id
49      /],
50   );
51
52   inspect_transaction(
53     $tr,
54     {
55       is_success => 1,
56     },
57     [qw/
58       message_id
59       authorization
60       order_number
61       txn_date
62       avs_code
63     /],
64   );
65
66   #
67   # Process a post-auth
68   #
69
70   my %content_pa = (
71     %content,
72     action => 'Post Authorization',
73     order_number => $tr->order_number,
74     amount => '8.99', # $1 Less than pre-auth
75   );
76
77   my ( $tr_pa, $response_pa ) = make_api_request( \%content_pa );
78
79   inspect_response(
80     $response_pa,
81     {
82       amount => '8.99',
83       approved => '1',
84       message => 'Approved',
85       message_id => '1',
86       type => 'PAC',
87     },
88     [qw/
89       authorizing_merchant_id
90       card
91       created
92       order_number
93       id
94     /],
95   );
96
97   inspect_transaction(
98     $tr_pa,
99     {
100       is_success => 1,
101     },
102     [qw/
103       message_id
104       authorization
105       order_number
106       txn_date
107       avs_code
108     /],
109   );
110
111   #
112   # Void Transaction
113   #
114
115   my %content_void = (
116     action => 'Void',
117     login => $content{login},
118     password => $content{password},
119
120     order_number => $tr_pa->order_number,
121     amount => '8.99',
122   );
123
124   my ( $tr_void, $response_void ) = make_api_request( \%content_void );
125
126   inspect_response(
127     $response_void,
128     {
129       amount => '8.99',
130       approved => '1',
131       message => 'Approved',
132       message_id => '1',
133       type => 'R',
134     },
135     [qw/
136       authorizing_merchant_id
137       card
138       created
139       order_number
140       id
141     /],
142   );
143
144   inspect_transaction(
145     $tr_void,
146     { is_success => 1 },
147     [],
148   );
149
150 }
151
152 done_testing;