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