Added vim syntax=perl modelines
[Business-OnlinePayment-InternetSecure.git] / t / 30parse.t
1 # vim:set syntax=perl:
2
3 use constant FIELDS => qw(
4                         result_code authorization error_message
5                         receipt_number sales_number
6                         date
7                         card_type
8                         avs_response cvv2_response
9                         total_amount
10                         );
11
12 use constant RESULTS => (
13                                 {
14                                         is_success      => 1,
15                                         result_code     => '2000',
16                                         authorization   => 'T00000',
17                                         error_message   => 'Test Approved',
18                                         receipt_number  => '1096019995.5012',
19                                         sales_number    => 0,
20                                         date            => '2003/12/17 09:59:58',
21                                         card_type       => undef,
22                                         avs_response    => undef,
23                                         cvv2_response   => undef,
24                                         total_amount    => 3.88,
25                                         uuid            => 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
26                                         guid            => 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
27                                 },
28                                 {
29                                         is_success      => 0,
30                                         result_code     => '98e05',
31                                         authorization   => undef,
32                                         error_message   => 'Real error message',
33                                         receipt_number  => '1096021915.5853',
34                                         sales_number    => 729,
35                                         date            => '2003/12/17 10:31:58',
36                                         card_type       => 'Visa',
37                                         avs_response    => undef,
38                                         cvv2_response   => undef,
39                                         total_amount    => 3.88,
40                                         uuid            => undef,
41                                         guid            => undef,
42                                 },
43                         );
44
45
46 use Test::More tests => 1 + scalar(RESULTS) * (1 + 1 + scalar(FIELDS));
47
48 BEGIN { use_ok('Business::OnlinePayment') };
49
50
51
52 my $txn = new Business::OnlinePayment 'InternetSecure', merchant_id => '0000';
53
54 $/ = '';
55 foreach my $results (RESULTS) {
56         my $xml = <DATA>;
57         $txn->parse_response($xml);
58
59         is($txn->server_response, $xml, 'server_response');
60
61         if ($results->{is_success}) {
62                 ok($txn->is_success, 'expecting success');
63         } else {
64                 ok(!$txn->is_success, 'expecting failure');
65         }
66
67         foreach (FIELDS) {
68                 no strict 'refs';
69                 is($txn->$_, $results->{$_}, $_);
70         }
71 }
72
73
74 __DATA__
75 <?xml version="1.0" encoding="UTF-8"?>
76 <TranxResponse>
77   <MerchantNumber>4994</MerchantNumber>
78   <ReceiptNumber>1096019995.5012</ReceiptNumber>
79   <SalesOrderNumber>0</SalesOrderNumber>
80   <xxxName>John Smith</xxxName>
81   <Date>2003/12/17 09:59:58</Date>
82   <CardType>Test Card Number</CardType>
83   <Page>2000</Page>
84   <ApprovalCode>T00000</ApprovalCode>
85   <Verbiage>Test Approved</Verbiage>
86   <TotalAmount>3.88</TotalAmount>
87   <Products>
88     <product>
89       <code>001</code>
90       <description>Test Product 1</description>
91       <quantity>1</quantity>
92       <price>3.10</price>
93       <subtotal>3.10</subtotal>
94       <flags>
95         <flag>{USD}</flag>
96         <flag>{GST}</flag>
97         <flag>{TEST}</flag>
98       </flags>
99     </product>
100     <product>
101       <code>010</code>
102       <description>Test Product 2</description>
103       <quantity>1</quantity>
104       <price>0.20</price>
105       <subtotal>0.20</subtotal>
106       <flags>
107         <flag>{GST}</flag>
108         <flag>{TEST}</flag>
109       </flags>
110     </product>
111     <product>
112       <code>020</code>
113       <description>Test Product 3</description>
114       <quantity>1</quantity>
115       <price>0.33</price>
116       <subtotal>0.33</subtotal>
117       <flags>
118         <flag>{GST}</flag>
119         <flag>{TEST}</flag>
120       </flags>
121     </product>
122     <product>
123       <code>GST</code>
124       <description>Canadian GST Charged</description>
125       <quantity>1</quantity>
126       <price>0.25</price>
127       <subtotal>0.25</subtotal>
128       <flags>
129         <flag>{TAX}</flag>
130         <flag>{CALCULATED}</flag>
131       </flags>
132     </product>
133   </Products>
134   <DoubleColonProducts>3.10::1::001::Test Product 1::{USD}{GST}{TEST}|0.20::1::010::Test Product 2::{GST}{TEST}|0.33::1::020::Test Product 3::{GST}{TEST}|0.25::1::GST::Canadian GST Charged::{TAX}{CALCULATED}</DoubleColonProducts>
135   <AVSResponseCode />
136   <CVV2ResponseCode />
137   <GUID>f81d4fae-7dec-11d0-a765-00a0c91e6bf6</GUID>
138 </TranxResponse>
139
140 <?xml version="1.0" encoding="UTF-8"?>
141 <TranxResponse>
142   <MerchantNumber>4994</MerchantNumber>
143   <ReceiptNumber>1096021915.5853</ReceiptNumber>
144   <SalesOrderNumber>729</SalesOrderNumber>
145   <xxxName>John Smith</xxxName>
146   <Date>2003/12/17 10:31:58</Date>
147   <CardType>VI</CardType>
148   <Page>98e05</Page>
149   <ApprovalCode />
150   <Verbiage>Incorrect Card Number - Please Retry</Verbiage>
151   <Error>Real error message</Error>
152   <TotalAmount>3.88</TotalAmount>
153   <Products>
154     <product>
155       <code>001</code>
156       <description>Test Product 1</description>
157       <quantity>1</quantity>
158       <price>3.10</price>
159       <subtotal>3.10</subtotal>
160       <flags>
161         <flag>{USD}</flag>
162         <flag>{GST}</flag>
163       </flags>
164     </product>
165     <product>
166       <code>010</code>
167       <description>Test Product 2</description>
168       <quantity>1</quantity>
169       <price>0.20</price>
170       <subtotal>0.20</subtotal>
171       <flags>
172         <flag>{GST}</flag>
173       </flags>
174     </product>
175     <product>
176       <code>020</code>
177       <description>Test Product 3</description>
178       <quantity>1</quantity>
179       <price>0.33</price>
180       <subtotal>0.33</subtotal>
181       <flags>
182         <flag>{GST}</flag>
183       </flags>
184     </product>
185     <product>
186       <code>GST</code>
187       <description>Canadian GST Charged</description>
188       <quantity>1</quantity>
189       <price>0.25</price>
190       <subtotal>0.25</subtotal>
191       <flags>
192         <flag>{TAX}</flag>
193         <flag>{CALCULATED}</flag>
194       </flags>
195     </product>
196   </Products>
197   <DoubleColonProducts>3.10::1::001::Test Product 1::{USD}{GST}|0.20::1::010::Test Product 2::{GST}|0.33::1::020::Test Product 3::{GST}|0.25::1::GST::Canadian GST Charged::{TAX}{CALCULATED}</DoubleColonProducts>
198   <AVSResponseCode />
199   <CVV2ResponseCode />
200 </TranxResponse>
201