google4r-checkout-jn 1.1.jniziol

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/CHANGES +136 -0
  2. data/LICENSE +22 -0
  3. data/README.md +72 -0
  4. data/lib/google4r/checkout.rb +34 -0
  5. data/lib/google4r/checkout/commands.rb +665 -0
  6. data/lib/google4r/checkout/frontend.rb +222 -0
  7. data/lib/google4r/checkout/merchant_calculation.rb +323 -0
  8. data/lib/google4r/checkout/notifications.rb +774 -0
  9. data/lib/google4r/checkout/shared.rb +1386 -0
  10. data/lib/google4r/checkout/utils.rb +94 -0
  11. data/lib/google4r/checkout/xml_generation.rb +1023 -0
  12. data/test/frontend_configuration_example.rb +13 -0
  13. data/test/integration/checkout_command_test.rb +261 -0
  14. data/test/test_helper.rb +105 -0
  15. data/test/unit/add_merchant_order_number_command_test.rb +65 -0
  16. data/test/unit/add_tracking_data_command_test.rb +68 -0
  17. data/test/unit/address_test.rb +131 -0
  18. data/test/unit/anonymous_address_test.rb +75 -0
  19. data/test/unit/archive_order_command_test.rb +63 -0
  20. data/test/unit/area_test.rb +44 -0
  21. data/test/unit/authorization_amount_notification_test.rb +69 -0
  22. data/test/unit/authorize_order_command_test.rb +63 -0
  23. data/test/unit/backorder_items_command_test.rb +69 -0
  24. data/test/unit/callback_handler_test.rb +83 -0
  25. data/test/unit/cancel_items_command_test.rb +76 -0
  26. data/test/unit/cancel_order_command_test.rb +74 -0
  27. data/test/unit/carrier_calculated_shipping_test.rb +57 -0
  28. data/test/unit/charge_amount_notification_test.rb +72 -0
  29. data/test/unit/charge_and_ship_order_command_test.rb +69 -0
  30. data/test/unit/charge_fee_test.rb +53 -0
  31. data/test/unit/charge_order_command_test.rb +69 -0
  32. data/test/unit/chargeback_amount_notification_test.rb +69 -0
  33. data/test/unit/checkout_command_test.rb +149 -0
  34. data/test/unit/checkout_command_xml_generator_test.rb +216 -0
  35. data/test/unit/command_test.rb +116 -0
  36. data/test/unit/deliver_order_command_test.rb +65 -0
  37. data/test/unit/delivery_method_test.rb +42 -0
  38. data/test/unit/digital_content_test.rb +105 -0
  39. data/test/unit/flat_rate_shipping_test.rb +133 -0
  40. data/test/unit/frontend_test.rb +144 -0
  41. data/test/unit/item_info_test.rb +69 -0
  42. data/test/unit/item_test.rb +171 -0
  43. data/test/unit/marketing_preferences_test.rb +65 -0
  44. data/test/unit/merchant_calculated_shipping_test.rb +173 -0
  45. data/test/unit/merchant_calculation_callback_test.rb +137 -0
  46. data/test/unit/merchant_calculation_result_test.rb +78 -0
  47. data/test/unit/merchant_calculation_results_test.rb +203 -0
  48. data/test/unit/merchant_code_result_test.rb +51 -0
  49. data/test/unit/merchant_code_test.rb +122 -0
  50. data/test/unit/new_order_notification_test.rb +115 -0
  51. data/test/unit/notification_acknowledgement_test.rb +67 -0
  52. data/test/unit/notification_handler_test.rb +113 -0
  53. data/test/unit/order_adjustment_test.rb +119 -0
  54. data/test/unit/order_report_command_test.rb +109 -0
  55. data/test/unit/order_state_change_notification_test.rb +158 -0
  56. data/test/unit/parameterized_url_test.rb +57 -0
  57. data/test/unit/pickup_shipping_test.rb +70 -0
  58. data/test/unit/postal_area_test.rb +71 -0
  59. data/test/unit/private_data_parser_test.rb +68 -0
  60. data/test/unit/refund_amount_notification_test.rb +67 -0
  61. data/test/unit/refund_order_command_test.rb +79 -0
  62. data/test/unit/reset_items_shipping_information_command_test.rb +69 -0
  63. data/test/unit/return_items_command_test.rb +69 -0
  64. data/test/unit/risk_information_notification_test.rb +98 -0
  65. data/test/unit/send_buyer_message_command_test.rb +68 -0
  66. data/test/unit/ship_items_command_test.rb +81 -0
  67. data/test/unit/shipping_adjustment_test.rb +100 -0
  68. data/test/unit/shopping_cart_test.rb +146 -0
  69. data/test/unit/tax_rule_test.rb +70 -0
  70. data/test/unit/tax_table_test.rb +88 -0
  71. data/test/unit/tracking_data_test.rb +54 -0
  72. data/test/unit/unarchive_order_command_test.rb +63 -0
  73. data/test/unit/url_parameter_test.rb +55 -0
  74. data/test/unit/us_country_area_test.rb +76 -0
  75. data/test/unit/us_state_area_test.rb +70 -0
  76. data/test/unit/us_zip_area_test.rb +66 -0
  77. data/test/unit/world_area_test.rb +48 -0
  78. data/var/cacert.pem +7815 -0
  79. metadata +230 -0
@@ -0,0 +1,69 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/backorder_items_command_test.rb
4
+ # Author: Tony Chan <api.htchan 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 BackorderItemsCommand class.
35
+ class Google4R::Checkout::BackorderItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_backorder_items_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+ @item_info1 = ItemInfo.new('A1')
45
+ @item_info2 = ItemInfo.new('B2')
46
+ @command.item_info_arr = [@item_info1, @item_info2]
47
+ end
48
+
49
+ def test_behaves_correctly
50
+ [ :google_order_number, :item_info_arr, :send_email,
51
+ :google_order_number=, :item_info_arr=, :send_email= ].each do |symbol|
52
+ assert_respond_to @command, symbol
53
+ end
54
+ end
55
+
56
+ def test_xml_send_email
57
+ assert_command_element_text_equals("true", "> send-email", @command)
58
+ end
59
+
60
+ def test_accessors
61
+ assert_equal('841171949013218', @command.google_order_number)
62
+ assert @command.send_email
63
+ end
64
+
65
+ def test_to_xml_does_not_raise_exception
66
+ assert_nothing_raised { @command.to_xml }
67
+ end
68
+
69
+ end
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Project: google4r
3
+ # File: test/unit/callback_handler_test.rb
4
+ # Author: Tony Chan <api dot 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
+ # Test for the class CallbackHandler.
35
+ class Google4R::Checkout::CallbackHandlerTest < 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
+ @callback_handler = @frontend.create_callback_handler
42
+
43
+ @xmls_with_known_tags =
44
+ [
45
+ [
46
+ '<merchant-calculation-callback xmlns="http://checkout.google.com/schema/2" />',
47
+ 'merchant-calculation-callback',
48
+ MerchantCalculationCallback
49
+ ]
50
+ ]
51
+
52
+ @xmls_with_unknown_tags =
53
+ [
54
+ '<unknown-callback/>'
55
+ ]
56
+ end
57
+
58
+ def test_handler_gets_initialized_correctly
59
+ assert_equal @frontend, @callback_handler.frontend
60
+ end
61
+
62
+ def test_returns_correct_callback_class_for_known_callback
63
+ @xmls_with_known_tags.each do |triple|
64
+ xml_str, tag_name, klass = triple
65
+
66
+ expect = klass.stubs(:create_from_element)
67
+ expect.times(1).returns(:foo)
68
+ expect.with { |element, frontend| element.name == tag_name and frontend == @frontend }
69
+
70
+ result = nil
71
+ assert_nothing_raised {
72
+ result = @callback_handler.handle(xml_str)
73
+ }
74
+ assert_equal :foo, result
75
+ end
76
+ end
77
+
78
+ def test_raises_exception_on_unknown_callback
79
+ @xmls_with_unknown_tags.each do |xml_str|
80
+ assert_raises(UnknownCallbackType) { @callback_handler.handle(xml_str) }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,76 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/cancel_items_command_test.rb
4
+ # Author: Tony Chan <api.htchan 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 CancelItemsCommand class.
35
+ class Google4R::Checkout::CancelItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_cancel_items_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+ @item_info1 = ItemInfo.new('A1')
45
+ @item_info2 = ItemInfo.new('B2')
46
+ @command.item_info_arr = [@item_info1, @item_info2]
47
+ @command.reason = 'This item is no longer manufactured.'
48
+ @command.comment = 'Suggested replacement is model XBR2700.'
49
+ end
50
+
51
+ def test_behaves_correctly
52
+ [ :google_order_number, :item_info_arr, :send_email,
53
+ :google_order_number=, :item_info_arr=, :send_email=,
54
+ :reason, :reason=, :comment, :comment=].each do |symbol|
55
+ assert_respond_to @command, symbol
56
+ end
57
+ end
58
+
59
+ def test_xml_send_email
60
+ assert_command_element_text_equals("true", "> send-email", @command)
61
+ assert_command_element_text_equals(@command.reason, "> reason", @command)
62
+ assert_command_element_text_equals(@command.comment, "> comment", @command)
63
+ end
64
+
65
+ def test_accessors
66
+ assert_equal('841171949013218', @command.google_order_number)
67
+ assert @command.send_email
68
+ assert_equal('This item is no longer manufactured.', @command.reason)
69
+ assert_equal('Suggested replacement is model XBR2700.', @command.comment)
70
+ end
71
+
72
+ def test_to_xml_does_not_raise_exception
73
+ assert_nothing_raised { @command.to_xml }
74
+ end
75
+
76
+ end
@@ -0,0 +1,74 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/cancel_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 CancelOrderCommand class.
35
+ class Google4R::Checkout::CancelOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_cancel_order_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.reason = 'Buyer cancelled the order'
44
+ @command.comment = 'Buyer ordered another item'
45
+ end
46
+
47
+ def test_behaves_correctly
48
+ [ :google_order_number, :reason, :comment ].each do |symbol|
49
+ assert_respond_to @command, symbol
50
+ end
51
+ end
52
+
53
+ def test_accessors
54
+ assert_equal 'Buyer cancelled the order', @command.reason
55
+ assert_equal '841171949013218', @command.google_order_number
56
+ assert_equal 'Buyer ordered another item', @command.comment
57
+ end
58
+
59
+ def test_xml
60
+ assert_command_element_text_equals(@command.reason, "> reason", @command)
61
+ assert_command_element_text_equals(@command.comment, "> comment", @command)
62
+ end
63
+
64
+ def test_xml_when_comment_not_used
65
+ @command.comment = nil
66
+ assert_command_element_text_equals(@command.reason, "> reason", @command)
67
+ assert_no_command_element_exists("> comment", @command)
68
+ end
69
+
70
+ def test_to_xml_does_not_raise_exception
71
+ assert_nothing_raised { @command.to_xml }
72
+ end
73
+
74
+ end
@@ -0,0 +1,57 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/carrier_calculated_shipping_test.rb
4
+ # Author: Tony Chan <api.htchan at gmail dot com>
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 FlatRateShipping class.
35
+ class Google4R::Checkout::CarrierCalculatedShippingTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @shipping = CarrierCalculatedShipping.new
40
+ end
41
+
42
+ def test_carrier_calculated_shipping_method_behaves_correctly
43
+ [ :carrier_calculated_shipping_options, :shipping_packages,
44
+ :create_carrier_calculated_shipping_option,
45
+ :create_shipping_package,
46
+ :create_from_element
47
+ ].each do |symbol|
48
+ assert_respond_to @shipping, symbol
49
+ end
50
+ end
51
+
52
+ def test_initialization
53
+ assert_equal [], @shipping.carrier_calculated_shipping_options
54
+ assert_equal [], @shipping.shipping_packages
55
+ end
56
+
57
+ end
@@ -0,0 +1,72 @@
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
+ <latest-charge-fee>
50
+ <total>1.21</total>
51
+ <flat>0.2</flat>
52
+ <percentage>3.4</percentage>
53
+ </latest-charge-fee>
54
+ </charge-amount-notification>
55
+ }
56
+ end
57
+
58
+ def test_create_from_element_works_correctly
59
+ root = REXML::Document.new(@example_xml).root
60
+
61
+ notification = ChargeAmountNotification.create_from_element(root, @frontend)
62
+
63
+ assert_equal 'e91f167e-4f98-4b29-b793-80aaa6a61c911', notification.serial_number
64
+ assert_equal '722226456784742', notification.google_order_number
65
+ assert_equal Time.parse('2007-05-06T18:41:21.000Z'), notification.timestamp
66
+ assert_equal(Money.new(999, 'GBP'), notification.total_charge_amount)
67
+ assert_equal(Money.new(123, 'GBP'), notification.latest_charge_amount)
68
+ assert_equal(Money.new(20, nil), notification.latest_charge_fee.flat)
69
+ assert_equal(3.4, notification.latest_charge_fee.percentage)
70
+ assert_equal(Money.new(121, nil), notification.latest_charge_fee.total)
71
+ end
72
+ end
@@ -0,0 +1,69 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/charge_order_command_test.rb
4
+ # Author: George Palmer <george.palmer at gmail dot com>
5
+ # Copyright: (c) 2010 by George Palmer
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::ChargeAndShipOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_charge_and_ship_order_command
41
+ @command.google_order_number = '1234-5678-ABCD-1234'
42
+ @command.amount = Money.new(1000, 'GBP')
43
+ end
44
+
45
+ def test_behaves_correctly
46
+ [ :google_order_number, :amount, :send_email, :carrier, :tracking_number ].each do |symbol|
47
+ assert_respond_to @command, symbol
48
+ end
49
+ end
50
+
51
+ def test_xml_without_amount
52
+ @command.amount = nil
53
+ assert_no_command_element_exists("amount", @command)
54
+ end
55
+
56
+ def test_accessors
57
+ assert_equal('1234-5678-ABCD-1234', @command.google_order_number)
58
+ assert_equal(Money.new(1000, 'GBP'), @command.amount)
59
+ end
60
+
61
+ def test_xml_generation
62
+ assert_command_element_text_equals("10.00", "> amount[currency=GBP]", @command)
63
+ end
64
+
65
+ def test_to_xml_does_not_raise_exception
66
+ assert_nothing_raised { @command.to_xml }
67
+ end
68
+
69
+ end