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