google4r-checkout 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/charge_amount_notification_test.rb
4
+ # Author: Dan Dukeson <dandukeson AT gmail.com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+ require 'rexml/document'
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class ChargeAmountNotification
35
+ class Google4R::Checkout::ChargeAmountNotificationTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @frontend.tax_table_factory = TestTaxTableFactory.new
41
+
42
+ @example_xml = %q{
43
+ <?xml version="1.0" encoding="UTF-8"?>
44
+ <charge-amount-notification xmlns="http://checkout.google.com/schema/2" serial-number="e91f167e-4f98-4b29-b793-80aaa6a61c911">
45
+ <timestamp>2007-05-06T18:41:21.000Z</timestamp>
46
+ <google-order-number>722226456784742</google-order-number>
47
+ <latest-charge-amount currency="GBP">1.23</latest-charge-amount>
48
+ <total-charge-amount currency="GBP">9.99</total-charge-amount>
49
+ </charge-amount-notification>
50
+ }
51
+ end
52
+
53
+ def test_create_from_element_works_correctly
54
+ root = REXML::Document.new(@example_xml).root
55
+
56
+ notification = ChargeAmountNotification.create_from_element(root, @frontend)
57
+
58
+ assert_equal 'e91f167e-4f98-4b29-b793-80aaa6a61c911', notification.serial_number
59
+ assert_equal '722226456784742', notification.google_order_number
60
+ assert_equal Time.parse('2007-05-06T18:41:21.000Z'), notification.timestamp
61
+ assert_equal(Money.new(999, 'GBP'), notification.total_charge_amount)
62
+ assert_equal(Money.new(123, 'GBP'), notification.latest_charge_amount)
63
+ end
64
+ end
@@ -0,0 +1,77 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/charge_order_command_test.rb
4
+ # Author: Dan Dukeson <dandukeson at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the ChargeOrderCommand class.
35
+ class Google4R::Checkout::ChargeOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_charge_order_command
41
+ @command.google_order_number = '1234-5678-ABCD-1234'
42
+ @command.amount = Money.new(1000, 'GBP')
43
+
44
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
45
+ <charge-order xmlns='http://checkout.google.com/schema/2' google-order-number='1234-5678-ABCD-1234'>
46
+ <amount currency='GBP'>10.00</amount>
47
+ </charge-order>}
48
+
49
+ @sample_no_amount=%Q{<?xml version='1.0' encoding='UTF-8'?>
50
+ <charge-order xmlns='http://checkout.google.com/schema/2' google-order-number='1234-5678-ABCD-1234'/>}
51
+ end
52
+
53
+ def test_behaves_correctly
54
+ [ :google_order_number, :amount ].each do |symbol|
55
+ assert_respond_to @command, symbol
56
+ end
57
+ end
58
+
59
+ def test_xml_with_amount
60
+ @command.amount = nil
61
+ assert_strings_equal(@sample_no_amount, @command.to_xml)
62
+ end
63
+
64
+ def test_accessors
65
+ assert_equal('1234-5678-ABCD-1234', @command.google_order_number)
66
+ assert_equal(Money.new(1000, 'GBP'), @command.amount)
67
+ end
68
+
69
+ def test_xml_generation
70
+ assert_strings_equal(@sample_xml, @command.to_xml)
71
+ end
72
+
73
+ def test_to_xml_does_not_raise_exception
74
+ assert_nothing_raised { @command.to_xml }
75
+ end
76
+
77
+ end
@@ -0,0 +1,195 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/chargeback_amount_notification_test.rb
4
+ # Author: Tony Chan <api.htchan AT gmail.com>
5
+ # Copyright: (c) 2007 by Tony Chan
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+ require 'rexml/document'
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class ChargebackAmountNotification
35
+ class Google4R::Checkout::ChargebackAmountNotificationTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @frontend.tax_table_factory = TestTaxTableFactory.new
41
+
42
+ @example_xml = %q{
43
+ <?xml version="1.0" encoding="UTF-8"?>
44
+ <chargeback-amount-notification xmlns="http://checkout.google.com/schema/2"
45
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
46
+ <google-order-number>841171949013218</google-order-number>
47
+ <latest-chargeback-amount currency="GBP">226.06</latest-chargeback-amount>
48
+ <total-chargeback-amount currency="GBP">226.06</total-chargeback-amount>
49
+ <timestamp>2006-03-18T20:25:31</timestamp>
50
+ </chargeback-amount-notification>
51
+ }
52
+ end
53
+
54
+ def test_create_from_element_works_correctly
55
+ root = REXML::Document.new(@example_xml).root
56
+
57
+ notification = ChargebackAmountNotification.create_from_element(root, @frontend)
58
+
59
+ assert_equal 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614', notification.serial_number
60
+ assert_equal '841171949013218', notification.google_order_number
61
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
62
+ assert_equal(Money.new(22606, 'GBP'), notification.total_chargeback_amount)
63
+ assert_equal(Money.new(22606, 'GBP'), notification.latest_chargeback_amount)
64
+ end
65
+ end
66
+ #--
67
+ # Project: google_checkout4r
68
+ # File: test/unit/chargeback_amount_notification_test.rb
69
+ # Author: Tony Chan <api.htchan AT gmail.com>
70
+ # Copyright: (c) 2007 by Tony Chan
71
+ # License: MIT License as follows:
72
+ #
73
+ # Permission is hereby granted, free of charge, to any person obtaining
74
+ # a copy of this software and associated documentation files (the
75
+ # "Software"), to deal in the Software without restriction, including
76
+ # without limitation the rights to use, copy, modify, merge, publish,
77
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
78
+ # persons to whom the Software is furnished to do so, subject to the
79
+ # following conditions:
80
+ #
81
+ # The above copyright notice and this permission notice shall be included
82
+ # in all copies or substantial portions of the Software.
83
+ #
84
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
85
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
87
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
88
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
90
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
91
+ #++
92
+
93
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
94
+
95
+ require 'google4r/checkout'
96
+ require 'rexml/document'
97
+ require 'test/frontend_configuration'
98
+
99
+ # Test for the class ChargebackAmountNotification
100
+ class Google4R::Checkout::ChargebackAmountNotificationTest < Test::Unit::TestCase
101
+ include Google4R::Checkout
102
+
103
+ def setup
104
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
105
+ @frontend.tax_table_factory = TestTaxTableFactory.new
106
+
107
+ @example_xml = %q{
108
+ <?xml version="1.0" encoding="UTF-8"?>
109
+ <chargeback-amount-notification xmlns="http://checkout.google.com/schema/2"
110
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
111
+ <google-order-number>841171949013218</google-order-number>
112
+ <latest-chargeback-amount currency="GBP">226.06</latest-chargeback-amount>
113
+ <total-chargeback-amount currency="GBP">226.06</total-chargeback-amount>
114
+ <timestamp>2006-03-18T20:25:31</timestamp>
115
+ </chargeback-amount-notification>
116
+ }
117
+ end
118
+
119
+ def test_create_from_element_works_correctly
120
+ root = REXML::Document.new(@example_xml).root
121
+
122
+ notification = ChargebackAmountNotification.create_from_element(root, @frontend)
123
+
124
+ assert_equal 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614', notification.serial_number
125
+ assert_equal '841171949013218', notification.google_order_number
126
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
127
+ assert_equal(Money.new(22606, 'GBP'), notification.total_chargeback_amount)
128
+ assert_equal(Money.new(22606, 'GBP'), notification.latest_chargeback_amount)
129
+ end
130
+ end
131
+ #--
132
+ # Project: google_checkout4r
133
+ # File: test/unit/chargeback_amount_notification_test.rb
134
+ # Author: Tony Chan <api.htchan AT gmail.com>
135
+ # Copyright: (c) 2007 by Tony Chan
136
+ # License: MIT License as follows:
137
+ #
138
+ # Permission is hereby granted, free of charge, to any person obtaining
139
+ # a copy of this software and associated documentation files (the
140
+ # "Software"), to deal in the Software without restriction, including
141
+ # without limitation the rights to use, copy, modify, merge, publish,
142
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
143
+ # persons to whom the Software is furnished to do so, subject to the
144
+ # following conditions:
145
+ #
146
+ # The above copyright notice and this permission notice shall be included
147
+ # in all copies or substantial portions of the Software.
148
+ #
149
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
150
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
151
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
152
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
153
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
154
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
155
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
156
+ #++
157
+
158
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
159
+
160
+ require 'google4r/checkout'
161
+ require 'rexml/document'
162
+ require 'test/frontend_configuration'
163
+
164
+ # Test for the class ChargebackAmountNotification
165
+ class Google4R::Checkout::ChargebackAmountNotificationTest < Test::Unit::TestCase
166
+ include Google4R::Checkout
167
+
168
+ def setup
169
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
170
+ @frontend.tax_table_factory = TestTaxTableFactory.new
171
+
172
+ @example_xml = %q{
173
+ <?xml version="1.0" encoding="UTF-8"?>
174
+ <chargeback-amount-notification xmlns="http://checkout.google.com/schema/2"
175
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
176
+ <google-order-number>841171949013218</google-order-number>
177
+ <latest-chargeback-amount currency="GBP">226.06</latest-chargeback-amount>
178
+ <total-chargeback-amount currency="GBP">226.06</total-chargeback-amount>
179
+ <timestamp>2006-03-18T20:25:31</timestamp>
180
+ </chargeback-amount-notification>
181
+ }
182
+ end
183
+
184
+ def test_create_from_element_works_correctly
185
+ root = REXML::Document.new(@example_xml).root
186
+
187
+ notification = ChargebackAmountNotification.create_from_element(root, @frontend)
188
+
189
+ assert_equal 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614', notification.serial_number
190
+ assert_equal '841171949013218', notification.google_order_number
191
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
192
+ assert_equal(Money.new(22606, 'GBP'), notification.total_chargeback_amount)
193
+ assert_equal(Money.new(22606, 'GBP'), notification.latest_chargeback_amount)
194
+ end
195
+ end
@@ -32,7 +32,9 @@ require 'google4r/checkout'
32
32
  require 'test/frontend_configuration'
33
33
 
34
34
  require 'tempfile'
35
- require 'open3'
35
+
36
+ require 'open3' rescue require 'win32/open3'
37
+
36
38
  require 'rexml/document'
37
39
 
38
40
  # Test for the class UsZipArea.
@@ -68,6 +70,11 @@ class Google4R::Checkout::CheckoutCommandXmlGeneratorTest < Test::Unit::TestCase
68
70
  rule.shipping_taxed=true
69
71
  rule.rate=0.03
70
72
  end
73
+ table.create_rule do |rule|
74
+ rule.area=Google4R::Checkout::PostalArea.new('GB')
75
+ rule.shipping_taxed=false
76
+ rule.rate=0.07
77
+ end
71
78
  table.create_rule do |rule|
72
79
  rule.area=Google4R::Checkout::WorldArea.new
73
80
  rule.shipping_taxed=true
@@ -164,7 +171,7 @@ class Google4R::Checkout::CheckoutCommandXmlGeneratorTest < Test::Unit::TestCase
164
171
  [ FRONTEND_CONFIGURATION[:merchant_id], FRONTEND_CONFIGURATION[:merchant_key],
165
172
  FRONTEND_CONFIGURATION[:merchant_id] ]
166
173
 
167
- stdin, stdout, stderr = Open3.popen3("curl", "-d", "@#{tmpfile.path}", url)
174
+ stdin, stdout, stderr = Open3.popen3("curl -d @#{tmpfile.path} #{url}")
168
175
  outstr = stdout.read
169
176
  errstr = stderr.read
170
177
 
@@ -183,8 +190,9 @@ class Google4R::Checkout::CheckoutCommandXmlGeneratorTest < Test::Unit::TestCase
183
190
  tmpfile.flush
184
191
 
185
192
  #puts "---\n#{xml_str}\n---"
186
-
187
- stdin, stdout, stderr = Open3.popen3("xmllint", "--schema", schema_path, tmpfile.path)
193
+
194
+ stdin, stdout, stderr = Open3.popen3("xmllint --schema #{schema_path} #{tmpfile.path}")
195
+
188
196
  outstr = stdout.read
189
197
  errstr = stderr.read
190
198
  if errstr !~ /validates$/ then
@@ -0,0 +1,70 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/deliver_order_command_test.rb
4
+ # Author: Dan Dukeson <dandukeson at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the DeliverOrderCommand class.
35
+ class Google4R::Checkout::DeliverOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_deliver_order_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+
45
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
46
+ <deliver-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
47
+ <send-email>true</send-email>
48
+ </deliver-order>}
49
+ end
50
+
51
+ def test_behaves_correctly
52
+ [ :google_order_number, :send_email ].each do |symbol|
53
+ assert_respond_to @command, symbol
54
+ end
55
+ end
56
+
57
+ def test_xml_send_email
58
+ assert_strings_equal(@sample_xml, @command.to_xml)
59
+ end
60
+
61
+ def test_accessors
62
+ assert_equal('841171949013218', @command.google_order_number)
63
+ assert @command.send_email
64
+ end
65
+
66
+ def test_to_xml_does_not_raise_exception
67
+ assert_nothing_raised { @command.to_xml }
68
+ end
69
+
70
+ end