nbudin-google4r-checkout 1.0.6

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.
Files changed (79) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGES +83 -0
  3. data/LICENSE +22 -0
  4. data/README +58 -0
  5. data/Rakefile +80 -0
  6. data/VERSION +1 -0
  7. data/lib/google4r/checkout/commands.rb +515 -0
  8. data/lib/google4r/checkout/frontend.rb +204 -0
  9. data/lib/google4r/checkout/merchant_calculation.rb +321 -0
  10. data/lib/google4r/checkout/notifications.rb +708 -0
  11. data/lib/google4r/checkout/shared.rb +1249 -0
  12. data/lib/google4r/checkout/utils.rb +94 -0
  13. data/lib/google4r/checkout/xml_generation.rb +920 -0
  14. data/lib/google4r/checkout.rb +34 -0
  15. data/test/frontend_configuration.rb +13 -0
  16. data/test/integration/checkout_command_test.rb +246 -0
  17. data/test/test_helper.rb +115 -0
  18. data/test/unit/add_merchant_order_number_command_test.rb +70 -0
  19. data/test/unit/add_tracking_data_command_test.rb +75 -0
  20. data/test/unit/address_test.rb +131 -0
  21. data/test/unit/anonymous_address_test.rb +75 -0
  22. data/test/unit/archive_order_command_test.rb +66 -0
  23. data/test/unit/area_test.rb +44 -0
  24. data/test/unit/authorization_amount_notification_test.rb +69 -0
  25. data/test/unit/authorize_order_command_test.rb +66 -0
  26. data/test/unit/backorder_items_command_test.rb +83 -0
  27. data/test/unit/callback_handler_test.rb +83 -0
  28. data/test/unit/cancel_items_command_test.rb +89 -0
  29. data/test/unit/cancel_order_command_test.rb +83 -0
  30. data/test/unit/carrier_calculated_shipping_test.rb +57 -0
  31. data/test/unit/charge_amount_notification_test.rb +64 -0
  32. data/test/unit/charge_order_command_test.rb +77 -0
  33. data/test/unit/chargeback_amount_notification_test.rb +65 -0
  34. data/test/unit/checkout_command_test.rb +125 -0
  35. data/test/unit/checkout_command_xml_generator_test.rb +218 -0
  36. data/test/unit/command_test.rb +116 -0
  37. data/test/unit/deliver_order_command_test.rb +70 -0
  38. data/test/unit/delivery_method_test.rb +42 -0
  39. data/test/unit/digital_content_test.rb +105 -0
  40. data/test/unit/flat_rate_shipping_test.rb +132 -0
  41. data/test/unit/frontend_test.rb +136 -0
  42. data/test/unit/item_info_test.rb +69 -0
  43. data/test/unit/item_test.rb +171 -0
  44. data/test/unit/marketing_preferences_test.rb +65 -0
  45. data/test/unit/merchant_calculated_shipping_test.rb +172 -0
  46. data/test/unit/merchant_calculation_callback_test.rb +137 -0
  47. data/test/unit/merchant_calculation_result_test.rb +78 -0
  48. data/test/unit/merchant_calculation_results_test.rb +178 -0
  49. data/test/unit/merchant_code_result_test.rb +51 -0
  50. data/test/unit/merchant_code_test.rb +122 -0
  51. data/test/unit/new_order_notification_test.rb +115 -0
  52. data/test/unit/notification_acknowledgement_test.rb +67 -0
  53. data/test/unit/notification_handler_test.rb +113 -0
  54. data/test/unit/order_adjustment_test.rb +119 -0
  55. data/test/unit/order_state_change_notification_test.rb +158 -0
  56. data/test/unit/pickup_shipping_test.rb +70 -0
  57. data/test/unit/postal_area_test.rb +71 -0
  58. data/test/unit/private_data_parser_test.rb +68 -0
  59. data/test/unit/refund_amount_notification_test.rb +65 -0
  60. data/test/unit/refund_order_command_test.rb +86 -0
  61. data/test/unit/reset_items_shipping_information_command_test.rb +83 -0
  62. data/test/unit/return_items_command_test.rb +83 -0
  63. data/test/unit/risk_information_notification_test.rb +98 -0
  64. data/test/unit/send_buyer_message_command_test.rb +73 -0
  65. data/test/unit/ship_items_command_test.rb +101 -0
  66. data/test/unit/shipping_adjustment_test.rb +100 -0
  67. data/test/unit/shopping_cart_test.rb +146 -0
  68. data/test/unit/tax_rule_test.rb +70 -0
  69. data/test/unit/tax_table_test.rb +82 -0
  70. data/test/unit/tracking_data_test.rb +54 -0
  71. data/test/unit/unarchive_order_command_test.rb +66 -0
  72. data/test/unit/us_country_area_test.rb +76 -0
  73. data/test/unit/us_state_area_test.rb +70 -0
  74. data/test/unit/us_zip_area_test.rb +66 -0
  75. data/test/unit/world_area_test.rb +48 -0
  76. data/test/xml/apiv2.xsd +997 -0
  77. data/test/xml/test_check_persisting_works_expected.xml +213 -0
  78. data/var/cacert.pem +7815 -0
  79. metadata +200 -0
@@ -0,0 +1,34 @@
1
+ #--
2
+ # Project: google4r
3
+ # File: lib/google4r/checkout.rb
4
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Copyright: (c) 2007 by Manuel Holtgrewe
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
+ # Require all the files that provide the code for the Google Checkout wrapper.
28
+
29
+ require 'google4r/checkout/shared'
30
+ require 'google4r/checkout/commands'
31
+ require 'google4r/checkout/notifications'
32
+ require 'google4r/checkout/xml_generation'
33
+ require 'google4r/checkout/frontend'
34
+ require 'google4r/checkout/merchant_calculation'
@@ -0,0 +1,13 @@
1
+ # Uncomment the following line if you are using Google Checkout in Great Britain
2
+ # and adjust it if you want to test google4r-checkout against any other (future)
3
+ # Google Checkout service.
4
+
5
+ # Money.default_currency = 'GBP'
6
+
7
+ # The test configuration for the Google4R::Checkout::Frontend class.
8
+ FRONTEND_CONFIGURATION =
9
+ {
10
+ :merchant_id => '',
11
+ :merchant_key => '',
12
+ :use_sandbox => true
13
+ }
@@ -0,0 +1,246 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/checkout/integration/checkout_command.rb
4
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Copyright: (c) 2007 by Manuel Holtgrewe
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
+ # Integration tests for the CheckoutCommand class.
35
+ #
36
+ # Tests the CheckoutCommand class against the Google Checkout Web Service.
37
+ class Google4R::Checkout::CheckoutCommandIntegrationTest < Test::Unit::TestCase
38
+ include Google4R::Checkout
39
+
40
+ def setup
41
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
42
+ @frontend.tax_table_factory = TestTaxTableFactory.new
43
+ @command = @frontend.create_checkout_command
44
+ end
45
+
46
+ def test_sending_to_google_works_with_valid_request
47
+ setup_command(@command)
48
+ result = @command.send_to_google_checkout
49
+ assert_kind_of CheckoutRedirectResponse, result
50
+ end
51
+
52
+ def test_sending_to_google_works_with_merchant_calculated_shipping
53
+ setup_command(@command, MerchantCalculatedShipping)
54
+ result = @command.send_to_google_checkout
55
+ assert_kind_of CheckoutRedirectResponse, result
56
+ end
57
+
58
+ def test_sending_to_google_works_with_carrier_calculated_shipping
59
+ setup_command(@command, CarrierCalculatedShipping)
60
+
61
+ # Uncomment to see the shopping cart xml
62
+ #puts @command.to_xml
63
+
64
+ result = @command.send_to_google_checkout
65
+
66
+ # Uncomment to see the result xml
67
+ #puts result
68
+
69
+ assert_kind_of CheckoutRedirectResponse, result
70
+ end
71
+
72
+ def test_sending_to_google_works_with_google_handled_subscription
73
+ setup_command(@command)
74
+
75
+ @command.shopping_cart.create_item do |item|
76
+ item.name = "Test subscription"
77
+ item.description = "12 month subscription"
78
+ item.unit_price = Money.us_dollar(0)
79
+ item.quantity = 1
80
+ item.private_data = { :id => 123456 }
81
+
82
+ item.create_subscription do |subscription|
83
+ subscription.type = "google"
84
+ subscription.period = "MONTHLY"
85
+
86
+ subscription.add_payment do |payment|
87
+ payment.times = 12
88
+ payment.maximum_charge = Money.us_dollar(1200)
89
+ end
90
+
91
+ subscription.add_recurrent_item do |rec_item|
92
+ rec_item.name = "Usage of My Awesome Website for One Month"
93
+ rec_item.description = "Your flat charge for accessing my web site"
94
+ rec_item.quantity = 1
95
+ rec_item.unit_price = Money.us_dollar(1200)
96
+
97
+ rec_item.create_digital_content do |content|
98
+ content.display_disposition = "OPTIMISTIC"
99
+ content.url = "http://mywebsite.example.com"
100
+ content.description = "Pie is found at this web site!"
101
+ end
102
+ end
103
+
104
+ item.create_digital_content do |content|
105
+ content.display_disposition = "OPTIMISTIC"
106
+ content.description = "Congratulations! Your subscription is being set up. Feel free to log onto" +
107
+ "<a href=\"http://mywebsite.example.com\">My website</a>."
108
+ end
109
+ end
110
+ end
111
+
112
+ result = @command.send_to_google_checkout
113
+ assert_kind_of CheckoutRedirectResponse, result
114
+ end
115
+
116
+ def test_sending_to_google_works_with_merchant_handled_subscription
117
+ setup_command(@command)
118
+
119
+ @command.shopping_cart.create_item do |item|
120
+ item.name = "Test subscription"
121
+ item.description = "12 month subscription"
122
+ item.unit_price = Money.us_dollar(0)
123
+ item.quantity = 1
124
+ item.private_data = { :id => 123456 }
125
+
126
+ item.create_subscription do |subscription|
127
+ subscription.type = "merchant"
128
+ subscription.period = "MONTHLY"
129
+ subscription.start_date = Time.new
130
+ subscription.start_date += (60 * 60 * 24 * 30)
131
+ subscription.no_charge_after = subscription.start_date + (60 * 60 * 24 * 365)
132
+
133
+ subscription.add_payment do |payment|
134
+ payment.times = 12
135
+ payment.maximum_charge = Money.us_dollar(1200)
136
+ end
137
+
138
+ item.create_digital_content do |content|
139
+ content.display_disposition = "OPTIMISTIC"
140
+ content.description = "Congratulations! Your subscription is being set up. Feel free to log onto" +
141
+ "<a href=\"http://mywebsite.example.com\">My website</a>."
142
+ end
143
+ end
144
+ end
145
+
146
+ result = @command.send_to_google_checkout
147
+ assert_kind_of CheckoutRedirectResponse, result
148
+ end
149
+
150
+ def test_using_invalid_credentials_raise_google_checkout_error
151
+ invalid_patches = [ [ :merchant_id, 'invalid' ], [ :merchant_key, 'invalid' ] ]
152
+
153
+ invalid_patches.each do |patch|
154
+ config = FRONTEND_CONFIGURATION.dup
155
+ config[patch[0]] = patch[1]
156
+ @frontend = Frontend.new(config)
157
+ @frontend.tax_table_factory = TestTaxTableFactory.new
158
+ @command = @frontend.create_checkout_command
159
+
160
+ setup_command(@command)
161
+ assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
162
+ end
163
+ end
164
+
165
+ def test_invalid_xml_raises_google_checkout_error
166
+ class << @command
167
+ def to_xml
168
+ ''
169
+ end
170
+ end
171
+
172
+ setup_command(@command)
173
+ assert_raises(GoogleCheckoutError) { @command.send_to_google_checkout }
174
+ end
175
+
176
+ protected
177
+
178
+ # Sets up the given CheckoutCommand so it contains some
179
+ # shipping methods and its cart contains some items.
180
+ def setup_command(command, shipping_type=FlatRateShipping)
181
+
182
+ if shipping_type == FlatRateShipping
183
+ # Add shipping methods.
184
+ command.create_shipping_method(FlatRateShipping) do |shipping|
185
+ shipping.name = 'UPS Ground Shipping'
186
+ shipping.price = Money.new(2000) # USD 20, GPB 20, etc.
187
+ shipping.create_allowed_area(UsCountryArea) do |area|
188
+ area.area = UsCountryArea::ALL
189
+ end
190
+ end
191
+ end
192
+
193
+ if shipping_type == MerchantCalculatedShipping
194
+ command.merchant_calculations_url = 'http://www.example.com'
195
+
196
+ command.create_shipping_method(MerchantCalculatedShipping) do |shipping|
197
+ shipping.name = 'International Shipping'
198
+ shipping.price = Money.new(2000)
199
+ shipping.create_address_filters_allowed_area(PostalArea) do |area|
200
+ area.country_code = 'US'
201
+ area.postal_code_pattern = '12*'
202
+ end
203
+ end
204
+ end
205
+
206
+ if shipping_type == CarrierCalculatedShipping
207
+ command.create_shipping_method(CarrierCalculatedShipping) do |shipping|
208
+ shipping.create_carrier_calculated_shipping_option do | option |
209
+ option.shipping_company =
210
+ CarrierCalculatedShipping::CarrierCalculatedShippingOption::FEDEX
211
+ option.price = Money.new(3000)
212
+ option.shipping_type = 'Priority Overnight'
213
+ option.carrier_pickup = 'REGULAR_PICKUP'
214
+ option.additional_fixed_charge = Money.new(500)
215
+ option.additional_variable_charge_percent = 15.5
216
+ end
217
+ shipping.create_shipping_package do | package |
218
+ ship_from = AnonymousAddress.new
219
+ ship_from.address_id = 'ABC'
220
+ ship_from.city = 'Ann Arbor'
221
+ ship_from.region = 'MI'
222
+ ship_from.country_code = 'US'
223
+ ship_from.postal_code = '48104'
224
+ package.ship_from = ship_from
225
+ package.delivery_address_category =
226
+ CarrierCalculatedShipping::ShippingPackage::COMMERCIAL
227
+ package.height = Dimension.new(1)
228
+ package.length = Dimension.new(2)
229
+ package.width = Dimension.new(3)
230
+ end
231
+ end
232
+ end
233
+
234
+ # Add items to the cart.
235
+ 1.upto(5) do |i|
236
+ command.shopping_cart.create_item do |item|
237
+ item.name = "Test Item #{i}"
238
+ item.description = "This is a test item (#{i})"
239
+ item.unit_price = Money.new(350)
240
+ item.quantity = i * 3
241
+ item.id = "test-#{i}-123456789"
242
+ item.weight = Weight.new(2.2)
243
+ end
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,115 @@
1
+ # Project: google4r
2
+ # File: /test/test_helper.rb
3
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
4
+ # Copyright: (c) 2007 by Manuel Holtgrewe
5
+ # License: MIT License as follows:
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining
8
+ # a copy of this software and associated documentation files (the
9
+ # "Software"), to deal in the Software without restriction, including
10
+ # without limitation the rights to use, copy, modify, merge, publish,
11
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
12
+ # persons to whom the Software is furnished to do so, subject to the
13
+ # following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included
16
+ # in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
24
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ # setup load path
27
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
28
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
29
+
30
+ # require dependencies
31
+
32
+ require 'test/unit'
33
+
34
+ require 'rubygems'
35
+ require 'mocha'
36
+
37
+ class Array
38
+ # Returns the "power set" for this Array. This means that an array with all
39
+ # subsets of the array's elements will be returned.
40
+ def power
41
+ # the power set line is stolen from http://johncarrino.net/blog/2006/08/11/powerset-in-ruby/
42
+ inject([[]]){|c,y|r=[];c.each{|i|r<<i;r<<i+[y]};r}
43
+ end
44
+ end
45
+
46
+ # A helper class for the tests that require TaxTable objects.
47
+ class TestTaxTableFactory
48
+ def effective_tax_tables_at(time)
49
+ table = Google4R::Checkout::TaxTable.new(false)
50
+ table.name = "Some Table"
51
+
52
+ [ table ]
53
+ end
54
+ end
55
+
56
+ class Test::Unit::TestCase
57
+ def assert_nospace_equal(expected, actual)
58
+ return assert_equal(expected.gsub(/\s/, ''), actual.gsub(/\s/, ''))
59
+ end
60
+
61
+ # Perform assertion on strings. The advantage of this method over the normal assert_equal
62
+ # method is that it displays the exact mismatch location and is aware of multi line strings.
63
+ #
64
+ # This comes at a performance cost since we have to compare character wise.
65
+ #
66
+ # === Example
67
+ #
68
+ # assert_string_equals("1\n2", "1\3", "Test Message!")
69
+ #
70
+ # Test Message!
71
+ # <1
72
+ # 2> expected but was
73
+ # <1
74
+ # 3>.Actual value is a real prefix of the expected value!
75
+ def assert_strings_equal(expected, actual, msg=nil)
76
+ return true if expected == actual
77
+
78
+ message = msg.nil? ? '' : "#{msg}\n"
79
+ message += %Q{<#{expected}> expected but was
80
+ <#{actual}>.}
81
+
82
+ expected_lines, actual_lines = expected.split(/\r\n|\n|\r/), actual.split(/\r\n|\n|\r/)
83
+
84
+ 1.upto([ expected_lines.length, actual_lines.length ].min) do |i|
85
+ next if expected_lines[i] == actual_lines[i]
86
+
87
+ # expected line != actual line
88
+ if expected_lines[i].length != actual_lines[i].length then
89
+ _wrap_assertion do
90
+ message += "\nLine <#{i+1}> expected to be <#{expected_lines[i].length}> bytes long but was <#{actual_lines[i].length}> bytes long."
91
+ raise Test::Unit::AssertionFailedError, message
92
+ end
93
+ end
94
+
95
+ 1.upto(expected_lines[i].length) do |j|
96
+ if expected_lines[i][j] != actual_lines[i][j] then
97
+ _wrap_assertion do
98
+ message += "\nCharacter <#{j}> of line <#{i+1}> expected to be <#{expected_lines[i][j]}> but was <#{actual_lines[i][j]}.>"
99
+ raise Test::Unit::AssertionFailedError, message
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ # if we reach here then one of expected and actual is a prefix of the other
106
+ if expected.length < actual.length then
107
+ message += "\nExpected value is a real prefix of the actual value!"
108
+ else
109
+ message += "\nActual value is a real prefix of the expected value!"
110
+ end
111
+ _wrap_assertion do
112
+ raise Test::Unit::AssertionFailedError, message
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,70 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/add_merchant_order_number_command_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot 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
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the AddMerchantOrderNumberCommand class.
35
+ class Google4R::Checkout::AddMerchantOrderNumberCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_add_merchant_order_number_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.merchant_order_number = 'P6502-53-7861SBJD'
44
+
45
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
46
+ <add-merchant-order-number xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
47
+ <merchant-order-number>P6502-53-7861SBJD</merchant-order-number>
48
+ </add-merchant-order-number>}
49
+ end
50
+
51
+ def test_behaves_correctly
52
+ [ :google_order_number, :merchant_order_number ].each do |symbol|
53
+ assert_respond_to @command, symbol
54
+ end
55
+ end
56
+
57
+ def test_xml
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_equal('P6502-53-7861SBJD', @command.merchant_order_number)
64
+ end
65
+
66
+ def test_to_xml_does_not_raise_exception
67
+ assert_nothing_raised { @command.to_xml }
68
+ end
69
+
70
+ end
@@ -0,0 +1,75 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/add_tracking_data_command_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot 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
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the AddTrackingDataCommand class.
35
+ class Google4R::Checkout::AddTrackingDataCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_add_tracking_data_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.carrier = 'UPS'
44
+ @command.tracking_number = 'Z9842W69871281267'
45
+
46
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
47
+ <add-tracking-data xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
48
+ <tracking-data>
49
+ <carrier>UPS</carrier>
50
+ <tracking-number>Z9842W69871281267</tracking-number>
51
+ </tracking-data>
52
+ </add-tracking-data>}
53
+ end
54
+
55
+ def test_behaves_correctly
56
+ [ :google_order_number, :carrier, :tracking_number ].each do |symbol|
57
+ assert_respond_to @command, symbol
58
+ end
59
+ end
60
+
61
+ def test_xml
62
+ assert_strings_equal(@sample_xml, @command.to_xml)
63
+ end
64
+
65
+ def test_accessors
66
+ assert_equal('841171949013218', @command.google_order_number)
67
+ assert_equal('Z9842W69871281267', @command.tracking_number)
68
+ assert_equal('UPS', @command.carrier)
69
+ end
70
+
71
+ def test_to_xml_does_not_raise_exception
72
+ assert_nothing_raised { @command.to_xml }
73
+ end
74
+
75
+ end
@@ -0,0 +1,131 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/address_test.rb
4
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
5
+ # Copyright: (c) 2007 by Manuel Holtgrewe
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
+ # Test for the class Address.
35
+ class Google4R::Checkout::AddressTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @data =
40
+ {
41
+ :contact_name => 'John Smith',
42
+ :email => 'johnsmith@example.com',
43
+ :fax => '+01123456789',
44
+ :phone => '+01123456789',
45
+ :address1 => '10 Example Road',
46
+ :address2 => 'Bar',
47
+ :city => 'Sampleville',
48
+ :company_name => 'Company Name',
49
+ :region => 'CA',
50
+ :postal_code => '94141',
51
+ :country_code => 'US',
52
+ }
53
+
54
+ @optional_fields = [ :fax, :phone, :address2, :company_name, :contact_name ]
55
+
56
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
57
+ <root>
58
+ <some-address>
59
+ <contact-name>%s</contact-name>
60
+ <email>%s</email>
61
+ <fax>%s</fax>
62
+ <phone>%s</phone>
63
+ <address1>%s</address1>
64
+ <address2>%s</address2>
65
+ <city>%s</city>
66
+ <company-name>%s</company-name>
67
+ <region>%s</region>
68
+ <postal-code>%s</postal-code>
69
+ <country-code>%s</country-code>
70
+ </some-address>
71
+ </root>}
72
+ end
73
+
74
+ def test_responds_correctly
75
+ @address = Address.new
76
+
77
+ @data.each do |key, value|
78
+ assert_respond_to @address, key, "key == #{key}"
79
+ assert_respond_to @address, "#{key}=".to_sym, "key == #{key}"
80
+ end
81
+ end
82
+
83
+ def test_creating_address_with_full_fields_works
84
+ xml_str = @xml_str %
85
+ [
86
+ @data[:contact_name], @data[:email], @data[:fax], @data[:phone], @data[:address1],
87
+ @data[:address2], @data[:city], @data[:company_name], @data[:region],
88
+ @data[:postal_code], @data[:country_code]
89
+ ]
90
+
91
+ document = REXML::Document.new(xml_str)
92
+
93
+ the_element = document.elements['/root/some-address']
94
+
95
+ address = Address.create_from_element(the_element)
96
+
97
+ @data.each do |key, value|
98
+ assert_equal value, address.send(key)
99
+ end
100
+ end
101
+
102
+ def test_creating_address_works_when_removing_optional_fields
103
+ @optional_fields.power.each do |optional_symbols|
104
+ xml_str = @xml_str %
105
+ [
106
+ @data[:contact_name], @data[:email], @data[:fax], @data[:phone], @data[:address1],
107
+ @data[:address2], @data[:city], @data[:company_name], @data[:region],
108
+ @data[:postal_code], @data[:country_code]
109
+ ]
110
+
111
+ # Remove all optional symbols in this run.
112
+ optional_symbols.each do |symbol|
113
+ xml_str = xml_str.gsub(%r{<#{symbol.to_s.gsub('_', '-')}>.*?</#{symbol.to_s.gsub('_', '-')}>}, '')
114
+ end
115
+
116
+ document = REXML::Document.new(xml_str)
117
+
118
+ the_element = document.elements['/root/some-address']
119
+
120
+ address = Address.create_from_element(the_element)
121
+
122
+ @data.each do |key, value|
123
+ if optional_symbols.include?(key) then
124
+ assert_nil address.send(key)
125
+ else
126
+ assert_equal value, address.send(key)
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end