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,119 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/order_adjustment_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 OrderAdjustment.
35
+ class Google4R::Checkout::OrderAdjustmentTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
40
+ <order-adjustment>
41
+ <merchant-calculation-successful>true</merchant-calculation-successful>
42
+ <merchant-codes>
43
+ <dummy-adjustment-one />
44
+ <dummy-adjustment-two />
45
+ </merchant-codes>
46
+ <total-tax currency="USD">11.05</total-tax>
47
+ <adjustment-total currency="USD">12.05</adjustment-total>
48
+ <shipping>
49
+ <%s />
50
+ </shipping>
51
+ </order-adjustment>}
52
+ @shipping_adjustments = [ 'flat-rate-shipping-adjustment', 'pickup-shipping-adjustment' ]
53
+ end
54
+
55
+ def test_reponds_correctly
56
+ assert_respond_to OrderAdjustment, :create_from_element
57
+
58
+ adjustment = OrderAdjustment.new
59
+
60
+ [ :adjustment_total, :adjustment_total=, :merchant_calculation_successful,
61
+ :merchant_calculation_successful, :merchant_codes, :merchant_codes=,
62
+ :shipping, :shipping=, :total_tax, :total_tax=
63
+ ].each do |symbol|
64
+ assert_respond_to adjustment, symbol
65
+ end
66
+ end
67
+
68
+ def test_create_from_xml_works_correctly
69
+ @shipping_adjustments.each do |adjustment_name|
70
+ # Build Mocha Expectations
71
+ expect = MerchantCode.stubs(:create_from_element)
72
+ expect.with { |element| element.name == 'dummy-adjustment-one' }
73
+ expect.times(1).returns(:dummy_adjustment1)
74
+
75
+ expect = MerchantCode.stubs(:create_from_element)
76
+ expect.with { |element| element.name == 'dummy-adjustment-two' }
77
+ expect.times(1).returns(:dummy_adjustment2)
78
+
79
+ expect = ShippingAdjustment.stubs(:create_from_element)
80
+ expect.with { |element| element.name == adjustment_name }
81
+ expect.times(1).returns(adjustment_name.to_sym)
82
+
83
+ # Create the adjustment
84
+ element = REXML::Document.new(@xml_str % [ adjustment_name ]).root
85
+ adjustment = OrderAdjustment.create_from_element(element)
86
+
87
+ # Assert!
88
+ assert_equal Money.new(1205, 'USD'), adjustment.adjustment_total
89
+ assert_equal true, adjustment.merchant_calculation_successful
90
+ assert_equal [ :dummy_adjustment1, :dummy_adjustment2 ], adjustment.merchant_codes
91
+ assert_equal adjustment_name.to_sym, adjustment.shipping
92
+ assert_equal Money.new(1105, 'USD'), adjustment.total_tax
93
+ end
94
+ end
95
+
96
+ def test_create_from_xml_works_correctly_without_shiping_tag
97
+ # Build Mocha Expectations
98
+ expect = MerchantCode.stubs(:create_from_element)
99
+ expect.with { |element| element.name == 'dummy-adjustment-one' }
100
+ expect.times(1).returns(:dummy_adjustment1)
101
+
102
+ expect = MerchantCode.stubs(:create_from_element)
103
+ expect.with { |element| element.name == 'dummy-adjustment-two' }
104
+ expect.times(1).returns(:dummy_adjustment2)
105
+
106
+ expect = ShippingAdjustment.expects(:create_from_element).never
107
+
108
+ # Create the adjustment
109
+ element = REXML::Document.new(@xml_str.gsub(%r{<shipping>.*<\/shipping>}m, '')).root
110
+ adjustment = OrderAdjustment.create_from_element(element)
111
+
112
+ # Assert!
113
+ assert_equal Money.new(1205, 'USD'), adjustment.adjustment_total
114
+ assert_equal true, adjustment.merchant_calculation_successful
115
+ assert_equal [ :dummy_adjustment1, :dummy_adjustment2 ], adjustment.merchant_codes
116
+ assert_equal nil, adjustment.shipping
117
+ assert_equal Money.new(1105, 'USD'), adjustment.total_tax
118
+ end
119
+ end
@@ -0,0 +1,158 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/order_state_change_notification_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 Area.
35
+ class Google4R::Checkout::OrderStateChangeNotificationTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @data = Hash.new
40
+ @data[:serial_number] = "c821426e-7caa-4d51-9b2e-48ef7ecd6423"
41
+ @data[:google_order_number] = "841171949013218"
42
+ @data[:new_financial_order_state] = "CHARGING"
43
+ @data[:previous_fulfillment_order_state] = "NEW"
44
+ @data[:new_financial_order_state] = "CHARGEABLE"
45
+ @data[:previous_fulfillment_order_state] = "NEW"
46
+ @data[:reason] = "charge_customer"
47
+ @data[:timestamp] = Time.new
48
+
49
+ @xml_template = %q{<?xml version="1.0" encoding="UTF-8"?>
50
+ <order-state-change-notification xmlns="http://checkout.google.com/schema/2" serial-number="%s">
51
+ <google-order-number>%s</google-order-number>
52
+ <new-financial-order-state>%s</new-financial-order-state>
53
+ <new-fulfillment-order-state>%s</new-fulfillment-order-state>
54
+ <previous-financial-order-state>%s</previous-financial-order-state>
55
+ <previous-fulfillment-order-state>%s</previous-fulfillment-order-state>
56
+ <reason>%s</reason>
57
+ <timestamp>%s</timestamp>
58
+ </order-state-change-notification>
59
+ }
60
+
61
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
62
+ @frontend.tax_table_factory = TestTaxTableFactory.new
63
+ end
64
+
65
+ def test_order_state_change_notification_responds_correctly
66
+ assert_respond_to OrderStateChangeNotification, :create_from_element
67
+
68
+ notification = OrderStateChangeNotification.new(@frontend)
69
+
70
+ [ :serial_number, :google_order_number, :new_financial_order_state, :previous_fulfillment_order_state,
71
+ :new_financial_order_state, :previous_fulfillment_order_state, :reason, :timestamp,
72
+ :serial_number=, :google_order_number=, :new_financial_order_state=, :previous_fulfillment_order_state=,
73
+ :new_financial_order_state=, :previous_fulfillment_order_state=, :reason=, :timestamp
74
+ ].each do |sym|
75
+ assert_respond_to notification, sym
76
+ end
77
+ end
78
+
79
+ def test_financial_order_state_defines_correct_constants
80
+ assert defined?(FinancialOrderState::REVIEWING)
81
+ assert defined?(FinancialOrderState::CHARGEABLE)
82
+ assert defined?(FinancialOrderState::CHARGING)
83
+ assert defined?(FinancialOrderState::CHARGED)
84
+ assert defined?(FinancialOrderState::PAYMENT_DECLINED)
85
+ assert defined?(FinancialOrderState::CANCELLED)
86
+ assert defined?(FinancialOrderState::CANCELLED_BY_GOOGLE)
87
+
88
+ assert_equal "REVIEWING", FinancialOrderState::REVIEWING
89
+ assert_equal "CHARGEABLE", FinancialOrderState::CHARGEABLE
90
+ assert_equal "CHARGING", FinancialOrderState::CHARGING
91
+ assert_equal "CHARGED", FinancialOrderState::CHARGED
92
+ assert_equal "PAYMENT_DECLINED", FinancialOrderState::PAYMENT_DECLINED
93
+ assert_equal "CANCELLED", FinancialOrderState::CANCELLED
94
+ assert_equal "CANCELLED_BY_GOOGLE", FinancialOrderState::CANCELLED_BY_GOOGLE
95
+ end
96
+
97
+ def test_fulfillment_order_state_defines_correct_constants
98
+ assert defined?(FulfillmentOrderState::NEW)
99
+ assert defined?(FulfillmentOrderState::PROCESSING)
100
+ assert defined?(FulfillmentOrderState::DELIVERED)
101
+ assert defined?(FulfillmentOrderState::WILL_NOT_DELIVER)
102
+
103
+ assert_equal "NEW", FulfillmentOrderState::NEW
104
+ assert_equal "PROCESSING", FulfillmentOrderState::PROCESSING
105
+ assert_equal "DELIVERED", FulfillmentOrderState::DELIVERED
106
+ assert_equal "WILL_NOT_DELIVER", FulfillmentOrderState::WILL_NOT_DELIVER
107
+ end
108
+
109
+ # <reason> in notification
110
+ def test_create_from_xml_should_correctly_create_order_state_change_notification_with_reason
111
+ [ true, false ].each do |skip_reason|
112
+ xml_str = @xml_template %
113
+ [
114
+ @data[:serial_number], @data[:google_order_number], @data[:new_financial_order_state],
115
+ @data[:new_fulfillment_order_state], @data[:previous_financial_order_state],
116
+ @data[:previous_fulfillment_order_state], @data[:reason], @data[:timestamp].iso8601
117
+ ]
118
+
119
+ xml_str = xml_str.gsub(/<reason>.*?<\/reason>/, '') if skip_reason
120
+
121
+ notification = OrderStateChangeNotification.create_from_element(REXML::Document.new(xml_str).root, @frontend)
122
+
123
+ @data.each do |key, value|
124
+ next if skip_reason and key == :reason
125
+
126
+ if key == :timestamp then
127
+ assert_in_delta @data[:timestamp].to_f, notification.timestamp.to_f, 1
128
+ else
129
+ assert_equal @data[key], notification.send(key), "#{key}"
130
+ end
131
+ end
132
+
133
+ assert_nil notification.reason if skip_reason
134
+ end
135
+ end
136
+
137
+ def test_create_from_xml_should_raise_exception_with_missing_tags
138
+ # Remove all required tags from the XML and expect the XPath query in
139
+ # OrderStateChangeNotification#create_from_xml to evaluate to nil and thus
140
+ # raise a NoMethodError.
141
+ [ 'google-order-number', 'new-financial-order-state', 'new-fulfillment-order-state',
142
+ 'previous-financial-order-state', 'previous-fulfillment-order-state', 'timestamp' ].each do |tag_name|
143
+ xml_str = @xml_template %
144
+ [
145
+ @data[:serial_number], @data[:google_order_number], @data[:new_financial_order_state],
146
+ @data[:new_fulfillment_order_state], @data[:previous_financial_order_state],
147
+ @data[:previous_fulfillment_order_state], @data[:reason], @data[:timestamp].iso8601
148
+ ]
149
+
150
+ xml_str = xml_str.gsub(%r{<#{tag_name}>.*?</#{tag_name}>}, '')
151
+ doc = REXML::Document.new(xml_str)
152
+
153
+ assert_raises(NoMethodError, "Removed tag: #{tag_name} - #{xml_str}") {
154
+ notification = OrderStateChangeNotification.create_from_element(doc.root, @frontend)
155
+ }
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,70 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/pickup_shipping_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 PickupShipping class.
35
+ class Google4R::Checkout::PickupShippingMethodTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @shipping = PickupShipping.new
40
+ end
41
+
42
+ def test_initialization
43
+ assert_nil @shipping.name
44
+ assert_nil @shipping.price
45
+ end
46
+
47
+ def test_pickup_shipping_method_behaves_correctly
48
+ [ :name, :name=, :price, :price= ].each do |sym|
49
+ assert_respond_to @shipping, sym
50
+ end
51
+ end
52
+
53
+ def test_pickup_shipping_method_setting_attributes_works_correctly
54
+ @shipping.name = "Shipping Method Name"
55
+ assert_equal "Shipping Method Name", @shipping.name
56
+
57
+ @shipping.price = Money.new(100, "EUR")
58
+ assert_kind_of Money, @shipping.price
59
+ assert_equal 100, @shipping.price.cents
60
+ assert_equal "EUR", @shipping.price.currency
61
+ end
62
+
63
+ def test_pickup_shipping_method_price_is_validated
64
+ # Test that PickupShippingMethod checks for its price attribute responding
65
+ # to cents and currency.
66
+ assert_raises(RuntimeError) { @shipping.price = nil }
67
+ assert_raises(RuntimeError) { @shipping.price = 10 }
68
+ assert_raises(RuntimeError) { @shipping.price = "str" }
69
+ end
70
+ end
@@ -0,0 +1,71 @@
1
+ require 'google4r/checkout'
2
+
3
+ require 'test/frontend_configuration'
4
+ #--
5
+ # Project: google_checkout4r
6
+ # File: test/unit/area_test.rb
7
+ # Author: Manuel Holtgrewe <purestorm at ggnore dot net>
8
+ # Copyright: (c) 2007 by Manuel Holtgrewe
9
+ # License: MIT License as follows:
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining
12
+ # a copy of this software and associated documentation files (the
13
+ # "Software"), to deal in the Software without restriction, including
14
+ # without limitation the rights to use, copy, modify, merge, publish,
15
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ # persons to whom the Software is furnished to do so, subject to the
17
+ # following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included
20
+ # in all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ #++
30
+
31
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
32
+
33
+ require 'google4r/checkout'
34
+
35
+ require 'test/frontend_configuration'
36
+
37
+ # Test for the class Area.
38
+ class Google4R::Checkout::PostalAreaTest < Test::Unit::TestCase
39
+ include Google4R::Checkout
40
+
41
+ def setup
42
+ @area = PostalArea.new('GB', 'S6*')
43
+ end
44
+
45
+ def test_initialization_works
46
+ assert_equal 'GB' , @area.country_code
47
+ assert_equal 'S6*', @area.postal_code_pattern
48
+ end
49
+
50
+ def test_us_state_area_behaves_correctly
51
+ assert_respond_to @area, :country_code
52
+ assert_respond_to @area, :country_code=
53
+ assert_respond_to @area, :postal_code_pattern
54
+ assert_respond_to @area, :postal_code_pattern=
55
+ end
56
+
57
+ def test_accessors_should_work
58
+ @area.postal_code_pattern = '100*'
59
+ assert_equal '100*', @area.postal_code_pattern
60
+
61
+ @area.country_code = 'DE'
62
+ assert_equal 'DE', @area.country_code
63
+ end
64
+
65
+ def test_initialize_without_postcode_works
66
+ pa = PostalArea.new('DE')
67
+ assert_equal 'DE', pa.country_code
68
+ assert_nil pa.postal_code_pattern
69
+ end
70
+
71
+ end
@@ -0,0 +1,68 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/private_data_parser_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 PrivateDataParser.
35
+ class Google4R::Checkout::PrivateDataParserTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @xml_str1 = %q{<merchant-private-item-data>
40
+ <item-note>Text 1</item-note>
41
+ <item-note>Text 2</item-note>
42
+ <nested>
43
+ <tags>value</tags>
44
+ </nested>
45
+ </merchant-private-item-data>}
46
+ end
47
+
48
+ def test_responds_correctly
49
+ assert_respond_to PrivateDataParser, :element_to_value
50
+ end
51
+
52
+ def test_parser_works_in_simple_example
53
+ element = REXML::Document.new(@xml_str1).root.elements['//tags']
54
+
55
+ assert_equal 'value', PrivateDataParser.element_to_value(element)
56
+ end
57
+
58
+ def test_parser_works_in_complex_example
59
+ doc = REXML::Document.new(@xml_str1)
60
+
61
+ hash =
62
+ {
63
+ 'item-note' => [ 'Text 1', 'Text 2' ],
64
+ 'nested' => { 'tags' => 'value' }
65
+ }
66
+ assert_equal hash, PrivateDataParser.element_to_value(doc.root)
67
+ end
68
+ end
@@ -0,0 +1,65 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/refund_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 RefundAmountNotification
35
+ class Google4R::Checkout::RefundAmountNotificationTest < 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
+ <refund-amount-notification xmlns="http://checkout.google.com/schema/2"
45
+ serial-number="d669f8c7-6d75-4ad6-9278-d2fc997d15f2">
46
+ <google-order-number>841171949013218</google-order-number>
47
+ <latest-refund-amount currency="GBP">226.06</latest-refund-amount>
48
+ <total-refund-amount currency="GBP">226.06</total-refund-amount>
49
+ <timestamp>2006-03-18T20:25:31</timestamp>
50
+ </refund-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 = RefundAmountNotification.create_from_element(root, @frontend)
58
+
59
+ assert_equal 'd669f8c7-6d75-4ad6-9278-d2fc997d15f2', 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_refund_amount)
63
+ assert_equal(Money.new(22606, 'GBP'), notification.latest_refund_amount)
64
+ end
65
+ end
@@ -0,0 +1,86 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/refund_order_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 RefundOrderCommand class.
35
+ class Google4R::Checkout::RefundOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_refund_order_command
41
+ @command.google_order_number = '841171949013218'
42
+ @command.amount = Money.new(1000, 'USD')
43
+ @command.comment = 'Discount for inconvenience; ship replacement item'
44
+ @command.reason = 'Damaged Merchandise'
45
+
46
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
47
+ <refund-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
48
+ <amount currency='USD'>10.00</amount>
49
+ <comment>Discount for inconvenience; ship replacement item</comment>
50
+ <reason>Damaged Merchandise</reason>
51
+ </refund-order>}
52
+
53
+ @sample_reason_only=%Q{<?xml version='1.0' encoding='UTF-8'?>
54
+ <refund-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
55
+ <reason>Damaged Merchandise</reason>
56
+ </refund-order>}
57
+ end
58
+
59
+ def test_behaves_correctly
60
+ [ :google_order_number, :amount, :reason, :comment ].each do |symbol|
61
+ assert_respond_to @command, symbol
62
+ end
63
+ end
64
+
65
+ def test_xml_with_amount
66
+ @command.amount = nil
67
+ @command.comment = nil
68
+ assert_strings_equal(@sample_reason_only, @command.to_xml)
69
+ end
70
+
71
+ def test_accessors
72
+ assert_equal('841171949013218', @command.google_order_number)
73
+ assert_equal(Money.new(1000, 'USD'), @command.amount)
74
+ assert_equal('Discount for inconvenience; ship replacement item', @command.comment)
75
+ assert_equal('Damaged Merchandise', @command.reason)
76
+ end
77
+
78
+ def test_xml_generation
79
+ assert_strings_equal(@sample_xml, @command.to_xml)
80
+ end
81
+
82
+ def test_to_xml_does_not_raise_exception
83
+ assert_nothing_raised { @command.to_xml }
84
+ end
85
+
86
+ end