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