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,83 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/reset_items_shipping_information_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 ResetItemsShippingInformationCommand class.
35
+ class Google4R::Checkout::ResetItemsShippingInformationCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_reset_items_shipping_information_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
+
48
+
49
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
50
+ <reset-items-shipping-information xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
51
+ <item-ids>
52
+ <item-id>
53
+ <merchant-item-id>A1</merchant-item-id>
54
+ </item-id>
55
+ <item-id>
56
+ <merchant-item-id>B2</merchant-item-id>
57
+ </item-id>
58
+ </item-ids>
59
+ <send-email>true</send-email>
60
+ </reset-items-shipping-information>}
61
+ end
62
+
63
+ def test_behaves_correctly
64
+ [ :google_order_number, :item_info_arr, :send_email,
65
+ :google_order_number=, :item_info_arr=, :send_email= ].each do |symbol|
66
+ assert_respond_to @command, symbol
67
+ end
68
+ end
69
+
70
+ def test_xml_send_email
71
+ assert_strings_equal(@sample_xml, @command.to_xml)
72
+ end
73
+
74
+ def test_accessors
75
+ assert_equal('841171949013218', @command.google_order_number)
76
+ assert @command.send_email
77
+ end
78
+
79
+ def test_to_xml_does_not_raise_exception
80
+ assert_nothing_raised { @command.to_xml }
81
+ end
82
+
83
+ end
@@ -0,0 +1,83 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/return_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 ReturnItemsCommand class.
35
+ class Google4R::Checkout::ReturnItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_return_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
+
48
+
49
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
50
+ <return-items xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
51
+ <item-ids>
52
+ <item-id>
53
+ <merchant-item-id>A1</merchant-item-id>
54
+ </item-id>
55
+ <item-id>
56
+ <merchant-item-id>B2</merchant-item-id>
57
+ </item-id>
58
+ </item-ids>
59
+ <send-email>true</send-email>
60
+ </return-items>}
61
+ end
62
+
63
+ def test_behaves_correctly
64
+ [ :google_order_number, :item_info_arr, :send_email,
65
+ :google_order_number=, :item_info_arr=, :send_email= ].each do |symbol|
66
+ assert_respond_to @command, symbol
67
+ end
68
+ end
69
+
70
+ def test_xml_send_email
71
+ assert_strings_equal(@sample_xml, @command.to_xml)
72
+ end
73
+
74
+ def test_accessors
75
+ assert_equal('841171949013218', @command.google_order_number)
76
+ assert @command.send_email
77
+ end
78
+
79
+ def test_to_xml_does_not_raise_exception
80
+ assert_nothing_raised { @command.to_xml }
81
+ end
82
+
83
+ end
@@ -0,0 +1,98 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/risk_info_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 Area.
35
+ class Google4R::Checkout::RiskInformationNotificationTest < 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
+ <risk-information-notification xmlns="http://checkout.google.com/schema/2" serial-number="4f5adc5b-aac5-4618-9e3b-75e60eaf29cd">
45
+ <timestamp>2007-04-30T08:03:57.000Z</timestamp>
46
+ <google-order-number>1564645586934214</google-order-number>
47
+ <risk-information>
48
+ <billing-address>
49
+ <!-- Not to be tested here but in Address --
50
+ <!--
51
+ <contact-name>Mr Contact Smith</contact-name>
52
+ <company-name>ACME Products</company-name>
53
+ <email>contact_smith@example.com</email>
54
+ <phone>012345 234567</phone>
55
+ <fax>012345 345678</fax>
56
+ <address1>123 Testing Road</address1>
57
+ <address2>Test Village</address2>
58
+ <country-code>GB</country-code>
59
+ <city>Testcity</city>
60
+ <region>South Testshire</region>
61
+ <postal-code>S6 1TT</postal-code>
62
+ -->
63
+ </billing-address>
64
+ <ip-address>123.456.123.456</ip-address>
65
+ <avs-response>Y</avs-response>
66
+ <cvn-response>M</cvn-response>
67
+ <eligible-for-protection>true</eligible-for-protection>
68
+ <partial-cc-number>6789</partial-cc-number>
69
+ <buyer-account-age>61</buyer-account-age>
70
+ </risk-information>
71
+ </risk-information-notification>
72
+ }
73
+
74
+ end
75
+
76
+ def test_create_from_element_works_correctly
77
+ # Stub out Address creation.
78
+ expectation = Address.stubs(:create_from_element).times(1).returns(:address)
79
+ expectation.with { |param| param.name == 'billing-address' }
80
+
81
+ root = REXML::Document.new(@example_xml).root
82
+
83
+ notification = RiskInformationNotification.create_from_element(root, @frontend)
84
+
85
+ assert_equal '4f5adc5b-aac5-4618-9e3b-75e60eaf29cd', notification.serial_number
86
+ assert_equal '1564645586934214', notification.google_order_number
87
+ assert_equal true, notification.eligible_for_protection
88
+
89
+ assert_equal :address, notification.buyer_billing_address
90
+
91
+ assert_equal 'Y', notification.avs_response
92
+ assert_equal 'M', notification.cvn_response
93
+ assert_equal '6789', notification.partial_card_number
94
+ assert_equal '123.456.123.456', notification.ip_address
95
+ assert_equal 61, notification.buyer_account_age
96
+ assert_equal Time.parse('2007-04-30T08:03:57.000Z'), notification.timestamp
97
+ end
98
+ end
@@ -0,0 +1,73 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/send_buyer_message_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 SendBuyerMessageCommand class.
35
+ class Google4R::Checkout::SendBuyerMessageCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_send_buyer_message_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.message = 'Due to high volume, your order will ship next week. Thank you for your patience.'
44
+ @command.send_email = true
45
+
46
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
47
+ <send-buyer-message xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
48
+ <message>Due to high volume, your order will ship next week. Thank you for your patience.</message>
49
+ <send-email>true</send-email>
50
+ </send-buyer-message>}
51
+ end
52
+
53
+ def test_behaves_correctly
54
+ [ :google_order_number, :message, :send_email ].each do |symbol|
55
+ assert_respond_to @command, symbol
56
+ end
57
+ end
58
+
59
+ def test_xml_send_email
60
+ assert_strings_equal(@sample_xml, @command.to_xml)
61
+ end
62
+
63
+ def test_accessors
64
+ assert_equal('841171949013218', @command.google_order_number)
65
+ assert_equal('Due to high volume, your order will ship next week. Thank you for your patience.', @command.message)
66
+ assert @command.send_email
67
+ end
68
+
69
+ def test_to_xml_does_not_raise_exception
70
+ assert_nothing_raised { @command.to_xml }
71
+ end
72
+
73
+ end
@@ -0,0 +1,101 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/ship_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 ShipItemsCommand class.
35
+ class Google4R::Checkout::ShipItemsCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_ship_items_command
41
+
42
+ @command.google_order_number = '841171949013218'
43
+ @command.send_email = true
44
+ @item_info_1 = ItemInfo.new('A1')
45
+ @item_info_1.create_tracking_data('UPS', 55555555)
46
+ @item_info_2 = ItemInfo.new('A2')
47
+ @item_info_2.create_tracking_data('FedEx', 12345678)
48
+ @command.item_info_arr = [@item_info_1, @item_info_2]
49
+
50
+
51
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
52
+ <ship-items xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
53
+ <item-shipping-information-list>
54
+ <item-shipping-information>
55
+ <item-id>
56
+ <merchant-item-id>A1</merchant-item-id>
57
+ </item-id>
58
+ <tracking-data-list>
59
+ <tracking-data>
60
+ <carrier>UPS</carrier>
61
+ <tracking-number>55555555</tracking-number>
62
+ </tracking-data>
63
+ </tracking-data-list>
64
+ </item-shipping-information>
65
+ <item-shipping-information>
66
+ <item-id>
67
+ <merchant-item-id>A2</merchant-item-id>
68
+ </item-id>
69
+ <tracking-data-list>
70
+ <tracking-data>
71
+ <carrier>FedEx</carrier>
72
+ <tracking-number>12345678</tracking-number>
73
+ </tracking-data>
74
+ </tracking-data-list>
75
+ </item-shipping-information>
76
+ </item-shipping-information-list>
77
+ <send-email>true</send-email>
78
+ </ship-items>}
79
+ end
80
+
81
+ def test_behaves_correctly
82
+ [ :google_order_number, :item_info_arr, :send_email,
83
+ :google_order_number=, :item_info_arr=, :send_email= ].each do |symbol|
84
+ assert_respond_to @command, symbol
85
+ end
86
+ end
87
+
88
+ def test_xml_send_email
89
+ assert_strings_equal(@sample_xml, @command.to_xml)
90
+ end
91
+
92
+ def test_accessors
93
+ assert_equal('841171949013218', @command.google_order_number)
94
+ assert @command.send_email
95
+ end
96
+
97
+ def test_to_xml_does_not_raise_exception
98
+ assert_nothing_raised { @command.to_xml }
99
+ end
100
+
101
+ end
@@ -0,0 +1,100 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/shipping_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 ShippingAdjustmentTest.
35
+ class Google4R::Checkout::ShippingAdjustmentTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
40
+ <%s>
41
+ <shipping-name>%s</shipping-name>
42
+ <shipping-cost currency="%s">%s</shipping-cost>
43
+ </%s>}
44
+
45
+ @valid_adjustment_types =
46
+ [
47
+ [ "FLAT_RATE", 'flat-rate-shipping-adjustment' ],
48
+ [ "PICKUP", 'pickup-shipping-adjustment' ],
49
+ ]
50
+
51
+ @invalid_adjustment_types = [ 'merchant-calculated-shipping', 'invalid-shipping' ]
52
+ end
53
+
54
+ def test_responds_correctly
55
+ adjustment = ShippingAdjustment.new
56
+
57
+ [ :type, :type=, :name, :name=, :cost, :cost= ].each do |symbol|
58
+ assert_respond_to adjustment, symbol
59
+ end
60
+ end
61
+
62
+ def test_constants_are_defined
63
+ assert defined?(ShippingAdjustment::FLAT_RATE)
64
+ assert defined?(ShippingAdjustment::PICKUP)
65
+ end
66
+
67
+ def test_create_from_element_works_with_valid_shipping_adjustment_types
68
+ @valid_adjustment_types.each do |pair|
69
+ type, tag_name = pair
70
+
71
+ xml_str = @xml_str %
72
+ [
73
+ tag_name, 'Some Name', 'USD', '10.00', tag_name
74
+ ]
75
+
76
+ element = REXML::Document.new(xml_str).root
77
+
78
+ adjustment = ShippingAdjustment.create_from_element(element)
79
+
80
+ assert_equal Money.new(1000, 'USD'), adjustment.cost
81
+ assert_equal type, adjustment.type
82
+ assert_equal 'Some Name', adjustment.name
83
+ end
84
+ end
85
+
86
+ def test_create_from_element_raises_exception_with_invalid_shipping_adjustment_types
87
+ @invalid_adjustment_types.each do |tag_name|
88
+ xml_str = @xml_str %
89
+ [
90
+ tag_name, 'Some Name', 'USD', '10.00', tag_name
91
+ ]
92
+
93
+ element = REXML::Document.new(xml_str).root
94
+
95
+ assert_raises(RuntimeError) do
96
+ adjustment = ShippingAdjustment.create_from_element(element)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,146 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/area_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
+ # Tests for the ShoppingCart class and all subclasses.
35
+ class Google4R::Checkout::ShoppingCartTest < 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
+ @command = @frontend.create_checkout_command
42
+ @shopping_cart = @command.shopping_cart
43
+
44
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8" ?>
45
+ <shopping-cart>
46
+ <merchant-private-data>
47
+ <affiliate-code>01234</affiliate-code>
48
+ </merchant-private-data>
49
+ <cart-expiration>
50
+ <good-until-date>2007-12-31T23:59:59-05:00</good-until-date>
51
+ </cart-expiration>
52
+ <items>
53
+ <item>
54
+ <item-name>AA Rechargeable Battery Pack</item-name>
55
+ <item-description>Battery pack containing four AA rechargeable batteries</item-description>
56
+ <unit-price currency="USD">12.00</unit-price>
57
+ <quantity>1</quantity>
58
+ </item>
59
+ <item>
60
+ <item-name>MegaSound 2GB MP3 Player</item-name>
61
+ <item-description>Portable MP3 player - stores 500 songs</item-description>
62
+ <quantity>1</quantity>
63
+ <unit-price currency="USD">178.00</unit-price>
64
+ </item>
65
+ </items>
66
+ </shopping-cart>}
67
+
68
+ @optional_tags = [ 'cart-expiration', 'merchant-private-data' ]
69
+ end
70
+
71
+ def test_behaves_correctly
72
+ [ :owner, :expires_at, :items, :owner, :private_data, :private_data= ].each do |sym|
73
+ assert_respond_to @shopping_cart, sym
74
+ end
75
+ end
76
+
77
+ def test_initialized_correctly
78
+ assert_equal @command, @shopping_cart.owner
79
+ assert_equal nil, @shopping_cart.expires_at
80
+ assert_equal [], @shopping_cart.items
81
+ assert_equal @command, @shopping_cart.owner
82
+ end
83
+
84
+ def test_accessors_work_correctly
85
+ hash = { 'foo' => [ { 'bar' => 'baz' }, "d'oh", 2 ] }
86
+ @shopping_cart.private_data = hash.dup
87
+ assert_equal hash, @shopping_cart.private_data
88
+ end
89
+
90
+ def test_setting_private_data_only_works_with_a_hash
91
+ assert_raises(RuntimeError) { @shopping_cart.private_data = 1 }
92
+ assert_raises(RuntimeError) { @shopping_cart.private_data = nil }
93
+ assert_raises(RuntimeError) { @shopping_cart.private_data = 'Foobar' }
94
+ assert_raises(RuntimeError) { @shopping_cart.private_data = [] }
95
+ end
96
+
97
+ def test_create_item_works_correctly_with_block
98
+ the_item = nil
99
+
100
+ res =
101
+ @shopping_cart.create_item do |item|
102
+ the_item = item
103
+
104
+ assert_kind_of Item, item
105
+ end
106
+
107
+ assert_equal res, the_item
108
+ assert @shopping_cart.items.include?(the_item)
109
+ end
110
+
111
+ def test_create_item_works_correctly_without_block
112
+ item = @shopping_cart.create_item
113
+
114
+ assert @shopping_cart.items.include?(item)
115
+ end
116
+
117
+ def test_create_from_element_works
118
+ @optional_tags.power.each do |optional_tag_names|
119
+ xml_str = @xml_str
120
+
121
+ optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
122
+
123
+ element = REXML::Document.new(xml_str).root
124
+
125
+ expect = Item.stubs(:create_from_element)
126
+ expect.with do |element, shopping_cart|
127
+ element.name == 'item' and
128
+ element.elements['item-name'].text == 'AA Rechargeable Battery Pack'
129
+ end
130
+ expect.times(1).returns(:item1)
131
+
132
+ expect = Item.stubs(:create_from_element)
133
+ expect.with do |element, shopping_cart|
134
+ element.name == 'item' and
135
+ element.elements['item-name'].text == 'MegaSound 2GB MP3 Player'
136
+ end
137
+ expect.times(1).returns(:item2)
138
+
139
+ shopping_cart = ShoppingCart.create_from_element(element, nil)
140
+
141
+ assert_equal Time.parse("2007-12-31T23:59:59-05:00"), shopping_cart.expires_at unless optional_tag_names.include?('cart-expiration')
142
+ assert_equal [ :item1, :item2 ], shopping_cart.items
143
+ assert_equal({ 'affiliate-code' => '01234' }, shopping_cart.private_data) unless optional_tag_names.include?('merchant-private-data')
144
+ end
145
+ end
146
+ end