0.05
[Business-OnlinePayment-InternetSecure.git] / t / 20emit.t
1 # vim:set syntax=perl encoding=utf-8:
2
3 use Test::More tests => 4 + 3;
4
5 BEGIN { use_ok('Business::OnlinePayment') };
6 BEGIN { use_ok('Business::OnlinePayment::InternetSecure') };
7 BEGIN { use_ok('XML::Simple', qw(xml_in)) };
8 BEGIN { use_ok('Encode') };
9
10 use charnames ':full';  # Why doesn't this work with use_ok?
11
12 use constant TRANSACTIONS => (
13         {
14                 _test           => 0,
15
16                 action          => 'Normal Authorization',
17
18                 type            => 'Visa',
19                 card_number     => '4111 1111 1111 1111',
20                 expiration      => '2004-07',
21                 cvv2            => '000',
22
23                 name            => "Fr\N{LATIN SMALL LETTER E WITH ACUTE}d\N{LATIN SMALL LETTER E WITH ACUTE}ric Bri\N{LATIN SMALL LETTER E WITH GRAVE}re",
24                 company         => '',
25                 address         => '123 Street',
26                 city            => 'Metropolis',
27                 state           => 'ZZ',
28                 zip             => 'A1A 1A1',
29                 country         => 'CA',
30                 phone           => '(555) 555-1212',
31                 email           => 'fbriere@fbriere.net',
32
33                 amount          => undef,
34                 currency        => 'USD',
35                 taxes           => 'HST',
36
37                 description => [
38                                 {
39                                 amount          => 9.99,
40                                 quantity        => 5,
41                                 sku             => 'a:001',
42                                 description     => 'Some product',
43                                 },
44                                 {
45                                 amount          => 5.65,
46                                 description     => 'Shipping',
47                                 taxes           => 'GST PST',
48                                 },
49                                 {
50                                 amount          => 10.00,
51                                 description     => 'Some HST example',
52                                 taxes           => [ 'GST', 'PST' ],
53                                 },
54                                 ],
55         },
56         {
57                 _test           => 1,
58
59                 action          => 'Normal Authorization',
60
61                 card_number     => '5111-1111-1111-1111',
62                 expiration      => '7/2004',
63
64                 name            => "\x{201c}Fr\x{e9}d\x{e9}ric Bri\x{e8}re\x{201d}",
65
66                 amount          => 12.95,
67                 description     => "Box o' goodies",
68                 currency        => 'USD',
69                 taxes           => 'GST',
70         },
71         {
72                 _test           => -1,
73
74                 action          => 'Normal Authorization',
75
76                 card_number     => '5111-1111-1111-1111',
77                 expiration      => '0704',
78
79                 name            => "Fr\x{e9}d\x{e9}ric Bri\x{e8}re",
80
81                 amount          => 13.95,
82         },
83 );
84
85
86 my $txn = new Business::OnlinePayment 'InternetSecure', merchant_id => '0000';
87
88 foreach (TRANSACTIONS) {
89         $txn->test_transaction(delete $_->{_test});
90         $txn->content(%$_);
91
92         my $data = do {
93                 # Work around bug #17687
94                 local $/ = '';
95                 scalar <DATA>;
96         };
97
98         is_deeply(
99                 xml_in($txn->to_xml),
100                 xml_in($data)
101         ); 
102 }
103
104
105 __DATA__
106 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
107 <TranxRequest>
108   <MerchantNumber>0000</MerchantNumber>
109   <xxxCard_Number>4111111111111111</xxxCard_Number>
110   <xxxCCMonth>07</xxxCCMonth>
111   <xxxCCYear>2004</xxxCCYear>
112   <CVV2>1</CVV2>
113   <CVV2Indicator>000</CVV2Indicator>
114   <Products>9.99::5::a 001::Some product::{USD}{HST}|5.65::1::::Shipping::{USD}{GST}{PST}|10.00::1::::Some HST example::{USD}{GST}{PST}</Products>
115   <xxxName>Frédéric Brière</xxxName>
116   <xxxCompany></xxxCompany>
117   <xxxAddress>123 Street</xxxAddress>
118   <xxxCity>Metropolis</xxxCity>
119   <xxxProvince>ZZ</xxxProvince>
120   <xxxPostal>A1A 1A1</xxxPostal>
121   <xxxCountry>CA</xxxCountry>
122   <xxxPhone>(555) 555-1212</xxxPhone>
123   <xxxEmail>fbriere@fbriere.net</xxxEmail>
124   <xxxShippingName></xxxShippingName>
125   <xxxShippingCompany></xxxShippingCompany>
126   <xxxShippingAddress></xxxShippingAddress>
127   <xxxShippingCity></xxxShippingCity>
128   <xxxShippingProvince></xxxShippingProvince>
129   <xxxShippingPostal></xxxShippingPostal>
130   <xxxShippingCountry></xxxShippingCountry>
131   <xxxShippingPhone></xxxShippingPhone>
132   <xxxShippingEmail></xxxShippingEmail>
133 </TranxRequest>
134
135 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
136 <TranxRequest>
137   <MerchantNumber>0000</MerchantNumber>
138   <xxxCard_Number>5111111111111111</xxxCard_Number>
139   <xxxCCMonth>07</xxxCCMonth>
140   <xxxCCYear>2004</xxxCCYear>
141   <CVV2>0</CVV2>
142   <CVV2Indicator></CVV2Indicator>
143   <Products>12.95::1::::Box o' goodies::{USD}{GST}{TEST}</Products>
144   <xxxName>?Frédéric Brière?</xxxName>
145   <xxxCompany></xxxCompany>
146   <xxxAddress></xxxAddress>
147   <xxxCity></xxxCity>
148   <xxxProvince></xxxProvince>
149   <xxxPostal></xxxPostal>
150   <xxxCountry></xxxCountry>
151   <xxxPhone></xxxPhone>
152   <xxxEmail></xxxEmail>
153   <xxxShippingName></xxxShippingName>
154   <xxxShippingCompany></xxxShippingCompany>
155   <xxxShippingAddress></xxxShippingAddress>
156   <xxxShippingCity></xxxShippingCity>
157   <xxxShippingProvince></xxxShippingProvince>
158   <xxxShippingPostal></xxxShippingPostal>
159   <xxxShippingCountry></xxxShippingCountry>
160   <xxxShippingPhone></xxxShippingPhone>
161   <xxxShippingEmail></xxxShippingEmail>
162 </TranxRequest>
163
164 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
165 <TranxRequest>
166   <MerchantNumber>0000</MerchantNumber>
167   <xxxCard_Number>5111111111111111</xxxCard_Number>
168   <xxxCCMonth>07</xxxCCMonth>
169   <xxxCCYear>2004</xxxCCYear>
170   <CVV2>0</CVV2>
171   <CVV2Indicator></CVV2Indicator>
172   <Products>13.95::1::::::{CAD}{TESTD}</Products>
173   <xxxName>Frédéric Brière</xxxName>
174   <xxxCompany></xxxCompany>
175   <xxxAddress></xxxAddress>
176   <xxxCity></xxxCity>
177   <xxxProvince></xxxProvince>
178   <xxxPostal></xxxPostal>
179   <xxxCountry></xxxCountry>
180   <xxxPhone></xxxPhone>
181   <xxxEmail></xxxEmail>
182   <xxxShippingName></xxxShippingName>
183   <xxxShippingCompany></xxxShippingCompany>
184   <xxxShippingAddress></xxxShippingAddress>
185   <xxxShippingCity></xxxShippingCity>
186   <xxxShippingProvince></xxxShippingProvince>
187   <xxxShippingPostal></xxxShippingPostal>
188   <xxxShippingCountry></xxxShippingCountry>
189   <xxxShippingPhone></xxxShippingPhone>
190   <xxxShippingEmail></xxxShippingEmail>
191 </TranxRequest>
192