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