archerfinley-google4r-checkout-1.0.5 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/CHANGES +93 -0
  2. data/LICENSE +22 -0
  3. data/README +58 -0
  4. data/Rakefile +13 -0
  5. data/VERSION +1 -0
  6. data/google4r-checkout-1.0.5-1.0.5.gem +0 -0
  7. data/google4r-checkout-1.0.5.gemspec +174 -0
  8. data/lib/google4r/checkout.rb +34 -0
  9. data/lib/google4r/checkout/commands.rb +567 -0
  10. data/lib/google4r/checkout/frontend.rb +210 -0
  11. data/lib/google4r/checkout/merchant_calculation.rb +321 -0
  12. data/lib/google4r/checkout/notifications.rb +708 -0
  13. data/lib/google4r/checkout/shared.rb +1086 -0
  14. data/lib/google4r/checkout/utils.rb +94 -0
  15. data/lib/google4r/checkout/xml_generation.rb +880 -0
  16. data/test/integration/checkout_command_test.rb +174 -0
  17. data/test/unit/add_merchant_order_number_command_test.rb +70 -0
  18. data/test/unit/add_tracking_data_command_test.rb +75 -0
  19. data/test/unit/address_test.rb +131 -0
  20. data/test/unit/anonymous_address_test.rb +75 -0
  21. data/test/unit/archive_order_command_test.rb +66 -0
  22. data/test/unit/area_test.rb +44 -0
  23. data/test/unit/authorization_amount_notification_test.rb +69 -0
  24. data/test/unit/authorize_order_command_test.rb +66 -0
  25. data/test/unit/backorder_items_command_test.rb +83 -0
  26. data/test/unit/callback_handler_test.rb +83 -0
  27. data/test/unit/cancel_items_command_test.rb +89 -0
  28. data/test/unit/cancel_order_command_test.rb +83 -0
  29. data/test/unit/carrier_calculated_shipping_test.rb +57 -0
  30. data/test/unit/charge_amount_notification_test.rb +64 -0
  31. data/test/unit/charge_order_command_test.rb +77 -0
  32. data/test/unit/chargeback_amount_notification_test.rb +65 -0
  33. data/test/unit/checkout_command_test.rb +125 -0
  34. data/test/unit/checkout_command_xml_generator_test.rb +218 -0
  35. data/test/unit/command_test.rb +116 -0
  36. data/test/unit/deliver_order_command_test.rb +70 -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 +132 -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 +172 -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 +178 -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 +111 -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/var/cacert.pem +7815 -0
  77. metadata +189 -0
@@ -0,0 +1,89 @@
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
+
50
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
51
+ <cancel-items xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
52
+ <item-ids>
53
+ <item-id>
54
+ <merchant-item-id>A1</merchant-item-id>
55
+ </item-id>
56
+ <item-id>
57
+ <merchant-item-id>B2</merchant-item-id>
58
+ </item-id>
59
+ </item-ids>
60
+ <send-email>true</send-email>
61
+ <reason>This item is no longer manufactured.</reason>
62
+ <comment>Suggested replacement is model XBR2700.</comment>
63
+ </cancel-items>}
64
+ end
65
+
66
+ def test_behaves_correctly
67
+ [ :google_order_number, :item_info_arr, :send_email,
68
+ :google_order_number=, :item_info_arr=, :send_email=,
69
+ :reason, :reason=, :comment, :comment=].each do |symbol|
70
+ assert_respond_to @command, symbol
71
+ end
72
+ end
73
+
74
+ def test_xml_send_email
75
+ assert_strings_equal(@sample_xml, @command.to_xml)
76
+ end
77
+
78
+ def test_accessors
79
+ assert_equal('841171949013218', @command.google_order_number)
80
+ assert @command.send_email
81
+ assert_equal('This item is no longer manufactured.', @command.reason)
82
+ assert_equal('Suggested replacement is model XBR2700.', @command.comment)
83
+ end
84
+
85
+ def test_to_xml_does_not_raise_exception
86
+ assert_nothing_raised { @command.to_xml }
87
+ end
88
+
89
+ end
@@ -0,0 +1,83 @@
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
+
46
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
47
+ <cancel-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
48
+ <reason>Buyer cancelled the order</reason>
49
+ <comment>Buyer ordered another item</comment>
50
+ </cancel-order>}
51
+
52
+ @sample_xml_no_comment=%Q{<?xml version='1.0' encoding='UTF-8'?>
53
+ <cancel-order xmlns='http://checkout.google.com/schema/2' google-order-number='841171949013218'>
54
+ <reason>Buyer cancelled the order</reason>
55
+ </cancel-order>}
56
+ end
57
+
58
+ def test_behaves_correctly
59
+ [ :google_order_number, :reason, :comment ].each do |symbol|
60
+ assert_respond_to @command, symbol
61
+ end
62
+ end
63
+
64
+ def test_accessors
65
+ assert_equal 'Buyer cancelled the order', @command.reason
66
+ assert_equal '841171949013218', @command.google_order_number
67
+ assert_equal 'Buyer ordered another item', @command.comment
68
+ end
69
+
70
+ def test_xml
71
+ assert_strings_equal @sample_xml, @command.to_xml
72
+ end
73
+
74
+ def test_xml_when_comment_not_used
75
+ @command.comment = nil
76
+ assert_strings_equal @sample_xml_no_comment, @command.to_xml
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,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,64 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/charge_amount_notification_test.rb
4
+ # Author: Dan Dukeson <dandukeson AT gmail.com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+ require 'rexml/document'
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class ChargeAmountNotification
35
+ class Google4R::Checkout::ChargeAmountNotificationTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @frontend.tax_table_factory = TestTaxTableFactory.new
41
+
42
+ @example_xml = %q{
43
+ <?xml version="1.0" encoding="UTF-8"?>
44
+ <charge-amount-notification xmlns="http://checkout.google.com/schema/2" serial-number="e91f167e-4f98-4b29-b793-80aaa6a61c911">
45
+ <timestamp>2007-05-06T18:41:21.000Z</timestamp>
46
+ <google-order-number>722226456784742</google-order-number>
47
+ <latest-charge-amount currency="GBP">1.23</latest-charge-amount>
48
+ <total-charge-amount currency="GBP">9.99</total-charge-amount>
49
+ </charge-amount-notification>
50
+ }
51
+ end
52
+
53
+ def test_create_from_element_works_correctly
54
+ root = REXML::Document.new(@example_xml).root
55
+
56
+ notification = ChargeAmountNotification.create_from_element(root, @frontend)
57
+
58
+ assert_equal 'e91f167e-4f98-4b29-b793-80aaa6a61c911', notification.serial_number
59
+ assert_equal '722226456784742', notification.google_order_number
60
+ assert_equal Time.parse('2007-05-06T18:41:21.000Z'), notification.timestamp
61
+ assert_equal(Money.new(999, 'GBP'), notification.total_charge_amount)
62
+ assert_equal(Money.new(123, 'GBP'), notification.latest_charge_amount)
63
+ end
64
+ end
@@ -0,0 +1,77 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/charge_order_command_test.rb
4
+ # Author: Dan Dukeson <dandukeson at gmail dot com>
5
+ # Copyright: (c) 2007 by Dan Dukeson
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+
32
+ require 'test/frontend_configuration'
33
+
34
+ # Tests for the ChargeOrderCommand class.
35
+ class Google4R::Checkout::ChargeOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_charge_order_command
41
+ @command.google_order_number = '1234-5678-ABCD-1234'
42
+ @command.amount = Money.new(1000, 'GBP')
43
+
44
+ @sample_xml=%Q{<?xml version='1.0' encoding='UTF-8'?>
45
+ <charge-order xmlns='http://checkout.google.com/schema/2' google-order-number='1234-5678-ABCD-1234'>
46
+ <amount currency='GBP'>10.00</amount>
47
+ </charge-order>}
48
+
49
+ @sample_no_amount=%Q{<?xml version='1.0' encoding='UTF-8'?>
50
+ <charge-order xmlns='http://checkout.google.com/schema/2' google-order-number='1234-5678-ABCD-1234'/>}
51
+ end
52
+
53
+ def test_behaves_correctly
54
+ [ :google_order_number, :amount ].each do |symbol|
55
+ assert_respond_to @command, symbol
56
+ end
57
+ end
58
+
59
+ def test_xml_with_amount
60
+ @command.amount = nil
61
+ assert_strings_equal(@sample_no_amount, @command.to_xml)
62
+ end
63
+
64
+ def test_accessors
65
+ assert_equal('1234-5678-ABCD-1234', @command.google_order_number)
66
+ assert_equal(Money.new(1000, 'GBP'), @command.amount)
67
+ end
68
+
69
+ def test_xml_generation
70
+ assert_strings_equal(@sample_xml, @command.to_xml)
71
+ end
72
+
73
+ def test_to_xml_does_not_raise_exception
74
+ assert_nothing_raised { @command.to_xml }
75
+ end
76
+
77
+ end
@@ -0,0 +1,65 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/chargeback_amount_notification_test.rb
4
+ # Author: Tony Chan <api.htchan AT gmail.com>
5
+ # Copyright: (c) 2007 by Tony Chan
6
+ # License: MIT License as follows:
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
13
+ # persons to whom the Software is furnished to do so, subject to the
14
+ # following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be included
17
+ # in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #++
27
+
28
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
29
+
30
+ require 'google4r/checkout'
31
+ require 'rexml/document'
32
+ require 'test/frontend_configuration'
33
+
34
+ # Test for the class ChargebackAmountNotification
35
+ class Google4R::Checkout::ChargebackAmountNotificationTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @frontend.tax_table_factory = TestTaxTableFactory.new
41
+
42
+ @example_xml = %q{
43
+ <?xml version="1.0" encoding="UTF-8"?>
44
+ <chargeback-amount-notification xmlns="http://checkout.google.com/schema/2"
45
+ serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
46
+ <google-order-number>841171949013218</google-order-number>
47
+ <latest-chargeback-amount currency="GBP">226.06</latest-chargeback-amount>
48
+ <total-chargeback-amount currency="GBP">226.06</total-chargeback-amount>
49
+ <timestamp>2006-03-18T20:25:31</timestamp>
50
+ </chargeback-amount-notification>
51
+ }
52
+ end
53
+
54
+ def test_create_from_element_works_correctly
55
+ root = REXML::Document.new(@example_xml).root
56
+
57
+ notification = ChargebackAmountNotification.create_from_element(root, @frontend)
58
+
59
+ assert_equal 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614', notification.serial_number
60
+ assert_equal '841171949013218', notification.google_order_number
61
+ assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
62
+ assert_equal(Money.new(22606, 'GBP'), notification.total_chargeback_amount)
63
+ assert_equal(Money.new(22606, 'GBP'), notification.latest_chargeback_amount)
64
+ end
65
+ end
@@ -0,0 +1,125 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/checkout_command_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 CheckoutCommand class.
35
+ class Google4R::Checkout::CheckoutCommandTest < 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
+ end
43
+
44
+ def test_tax_table_factory_works_correctly
45
+ TestTaxTableFactory.any_instance.stubs(:effective_tax_tables_at).returns([:tax_table])
46
+
47
+ frontend = Frontend.new(FRONTEND_CONFIGURATION)
48
+ frontend.tax_table_factory = TestTaxTableFactory.new
49
+ command = frontend.create_checkout_command
50
+
51
+ assert_equal [:tax_table], command.tax_tables
52
+ end
53
+
54
+ def test_initialized_correctly
55
+ assert_equal @frontend, @command.frontend
56
+ assert_kind_of ShoppingCart, @command.shopping_cart
57
+ assert_equal [], @command.shipping_methods
58
+ assert_nil @command.edit_cart_url
59
+ assert_nil @command.continue_shopping_url
60
+ assert_nil @command.request_buyer_phone_number
61
+ end
62
+
63
+ def test_command_behaves_correctly
64
+ [ :frontend, :shopping_cart, :tax_tables, :shipping_methods, :create_shipping_method,
65
+ :edit_cart_url, :edit_cart_url=, :continue_shopping_url, :continue_shopping_url=,
66
+ :request_buyer_phone_number, :request_buyer_phone_number=,
67
+ :merchant_calculations_url, :merchant_calculations_url=,
68
+ :accept_merchant_coupons, :accept_merchant_coupons=,
69
+ :accept_gift_certificates, :accept_gift_certificates=,
70
+ :platform_id, :platform_id=
71
+ ].each do |symbol|
72
+ assert_respond_to @command, symbol
73
+ end
74
+ end
75
+
76
+ def test_accessors_work_correctly
77
+ @command.edit_cart_url = "edit cart url"
78
+ assert_equal "edit cart url", @command.edit_cart_url
79
+
80
+ @command.continue_shopping_url = "continue shopping url"
81
+ assert_equal "continue shopping url", @command.continue_shopping_url
82
+
83
+ @command.request_buyer_phone_number = true
84
+ assert_equal true, @command.request_buyer_phone_number
85
+
86
+ assert_nil @command.analytics_data
87
+ @command.analytics_data = 'abcd1234defgh5678ijklmn'
88
+ assert_equal 'abcd1234defgh5678ijklmn', @command.analytics_data
89
+
90
+ end
91
+
92
+ def test_create_shipping_method_works_correctly_with_block
93
+ [ PickupShipping, FlatRateShipping, MerchantCalculatedShipping ].each do |clazz|
94
+
95
+ shipping = nil
96
+
97
+ res =
98
+ @command.create_shipping_method(clazz) do |obj|
99
+ shipping = obj
100
+ assert_kind_of clazz, obj
101
+ end
102
+
103
+ assert_equal res, shipping
104
+ assert @command.shipping_methods.include?(shipping)
105
+ end
106
+ end
107
+
108
+ def test_create_shipping_method_works_correctly_without_block
109
+ [ PickupShipping, FlatRateShipping, MerchantCalculatedShipping ].each do |clazz|
110
+ obj = @command.create_shipping_method(clazz)
111
+
112
+ assert_kind_of clazz, obj
113
+
114
+ assert @command.shipping_methods.include?(obj)
115
+ end
116
+ end
117
+
118
+ def test_create_shipping_method_raises_exception_on_invalid_clazz_parameter
119
+ assert_raises(ArgumentError) { @command.create_shipping_method(String) }
120
+ end
121
+
122
+ def test_to_xml_does_not_raise_exception
123
+ assert_nothing_raised { @command.to_xml }
124
+ end
125
+ end