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