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