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