62baea7646c06a358d07410c0718d0aa62b4b185
[Business-OnlinePayment-InternetSecure.git] / t / 20emit.t
1 # vim:set syntax=perl:
2
3 use Test::More tests => 4 + 2;
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                 exp_date        => '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        => 'CAD',
35                 taxes           => 'GST PST',
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                                 },
48                                 {
49                                 amount          => 10.00,
50                                 description     => 'Some HST example',
51                                 taxes           => 'HST',
52                                 },
53                                 ],
54         },
55         {
56                 _test           => 1,
57
58                 action          => 'Normal Authorization',
59
60                 type            => 'MasterCard',
61                 card_number     => '5111-1111-1111-1111',
62                 exp_date        => '7/2004',
63
64                 name            => "Fr\x{e9}d\x{e9}ric Bri\x{e8}re",
65
66                 amount          => 12.95,
67                 currency        => 'USD',
68                 taxes           => '',
69                 description     => "Box o' goodies",
70         },
71 );
72
73
74 my $txn = new Business::OnlinePayment 'InternetSecure', merchant_id => '0000';
75
76 foreach (TRANSACTIONS) {
77         $txn->test_transaction(delete $_->{_test});
78         $txn->content(%$_);
79
80         my $data = do {
81                 # Work around bug #17687
82                 local $/ = '';
83                 scalar <DATA>;
84         };
85
86         is_deeply(
87                 xml_in($txn->to_xml),
88                 xml_in($data)
89         ); 
90 }
91
92
93 __DATA__
94 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
95 <TranxRequest>
96   <MerchantNumber>0000</MerchantNumber>
97   <xxxCard_Number>4111111111111111</xxxCard_Number>
98   <xxxCCMonth>07</xxxCCMonth>
99   <xxxCCYear>2004</xxxCCYear>
100   <CVV2>1</CVV2>
101   <CVV2Indicator>000</CVV2Indicator>
102   <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>
103   <xxxName>Frédéric Brière</xxxName>
104   <xxxCompany></xxxCompany>
105   <xxxAddress>123 Street</xxxAddress>
106   <xxxCity>Metropolis</xxxCity>
107   <xxxProvince>ZZ</xxxProvince>
108   <xxxPostal>A1A 1A1</xxxPostal>
109   <xxxCountry>CA</xxxCountry>
110   <xxxPhone>(555) 555-1212</xxxPhone>
111   <xxxEmail>fbriere@fbriere.net</xxxEmail>
112   <xxxShippingName></xxxShippingName>
113   <xxxShippingCompany></xxxShippingCompany>
114   <xxxShippingAddress></xxxShippingAddress>
115   <xxxShippingCity></xxxShippingCity>
116   <xxxShippingProvince></xxxShippingProvince>
117   <xxxShippingPostal></xxxShippingPostal>
118   <xxxShippingCountry></xxxShippingCountry>
119   <xxxShippingPhone></xxxShippingPhone>
120   <xxxShippingEmail></xxxShippingEmail>
121 </TranxRequest>
122
123 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
124 <TranxRequest>
125   <MerchantNumber>0000</MerchantNumber>
126   <xxxCard_Number>5111111111111111</xxxCard_Number>
127   <xxxCCMonth>07</xxxCCMonth>
128   <xxxCCYear>2004</xxxCCYear>
129   <CVV2>0</CVV2>
130   <CVV2Indicator></CVV2Indicator>
131   <Products>12.95::1::::Box o' goodies::{USD}{TEST}</Products>
132   <xxxName>Frédéric Brière</xxxName>
133   <xxxCompany></xxxCompany>
134   <xxxAddress></xxxAddress>
135   <xxxCity></xxxCity>
136   <xxxProvince></xxxProvince>
137   <xxxPostal></xxxPostal>
138   <xxxCountry></xxxCountry>
139   <xxxPhone></xxxPhone>
140   <xxxEmail></xxxEmail>
141   <xxxShippingName></xxxShippingName>
142   <xxxShippingCompany></xxxShippingCompany>
143   <xxxShippingAddress></xxxShippingAddress>
144   <xxxShippingCity></xxxShippingCity>
145   <xxxShippingProvince></xxxShippingProvince>
146   <xxxShippingPostal></xxxShippingPostal>
147   <xxxShippingCountry></xxxShippingCountry>
148   <xxxShippingPhone></xxxShippingPhone>
149   <xxxShippingEmail></xxxShippingEmail>
150 </TranxRequest>
151