nbudin-google4r-checkout 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGES +83 -0
- data/LICENSE +22 -0
- data/README +58 -0
- data/Rakefile +80 -0
- data/VERSION +1 -0
- data/lib/google4r/checkout/commands.rb +515 -0
- data/lib/google4r/checkout/frontend.rb +204 -0
- data/lib/google4r/checkout/merchant_calculation.rb +321 -0
- data/lib/google4r/checkout/notifications.rb +708 -0
- data/lib/google4r/checkout/shared.rb +1249 -0
- data/lib/google4r/checkout/utils.rb +94 -0
- data/lib/google4r/checkout/xml_generation.rb +920 -0
- data/lib/google4r/checkout.rb +34 -0
- data/test/frontend_configuration.rb +13 -0
- data/test/integration/checkout_command_test.rb +246 -0
- data/test/test_helper.rb +115 -0
- data/test/unit/add_merchant_order_number_command_test.rb +70 -0
- data/test/unit/add_tracking_data_command_test.rb +75 -0
- data/test/unit/address_test.rb +131 -0
- data/test/unit/anonymous_address_test.rb +75 -0
- data/test/unit/archive_order_command_test.rb +66 -0
- data/test/unit/area_test.rb +44 -0
- data/test/unit/authorization_amount_notification_test.rb +69 -0
- data/test/unit/authorize_order_command_test.rb +66 -0
- data/test/unit/backorder_items_command_test.rb +83 -0
- data/test/unit/callback_handler_test.rb +83 -0
- data/test/unit/cancel_items_command_test.rb +89 -0
- data/test/unit/cancel_order_command_test.rb +83 -0
- data/test/unit/carrier_calculated_shipping_test.rb +57 -0
- data/test/unit/charge_amount_notification_test.rb +64 -0
- data/test/unit/charge_order_command_test.rb +77 -0
- data/test/unit/chargeback_amount_notification_test.rb +65 -0
- data/test/unit/checkout_command_test.rb +125 -0
- data/test/unit/checkout_command_xml_generator_test.rb +218 -0
- data/test/unit/command_test.rb +116 -0
- data/test/unit/deliver_order_command_test.rb +70 -0
- data/test/unit/delivery_method_test.rb +42 -0
- data/test/unit/digital_content_test.rb +105 -0
- data/test/unit/flat_rate_shipping_test.rb +132 -0
- data/test/unit/frontend_test.rb +136 -0
- data/test/unit/item_info_test.rb +69 -0
- data/test/unit/item_test.rb +171 -0
- data/test/unit/marketing_preferences_test.rb +65 -0
- data/test/unit/merchant_calculated_shipping_test.rb +172 -0
- data/test/unit/merchant_calculation_callback_test.rb +137 -0
- data/test/unit/merchant_calculation_result_test.rb +78 -0
- data/test/unit/merchant_calculation_results_test.rb +178 -0
- data/test/unit/merchant_code_result_test.rb +51 -0
- data/test/unit/merchant_code_test.rb +122 -0
- data/test/unit/new_order_notification_test.rb +115 -0
- data/test/unit/notification_acknowledgement_test.rb +67 -0
- data/test/unit/notification_handler_test.rb +113 -0
- data/test/unit/order_adjustment_test.rb +119 -0
- data/test/unit/order_state_change_notification_test.rb +158 -0
- data/test/unit/pickup_shipping_test.rb +70 -0
- data/test/unit/postal_area_test.rb +71 -0
- data/test/unit/private_data_parser_test.rb +68 -0
- data/test/unit/refund_amount_notification_test.rb +65 -0
- data/test/unit/refund_order_command_test.rb +86 -0
- data/test/unit/reset_items_shipping_information_command_test.rb +83 -0
- data/test/unit/return_items_command_test.rb +83 -0
- data/test/unit/risk_information_notification_test.rb +98 -0
- data/test/unit/send_buyer_message_command_test.rb +73 -0
- data/test/unit/ship_items_command_test.rb +101 -0
- data/test/unit/shipping_adjustment_test.rb +100 -0
- data/test/unit/shopping_cart_test.rb +146 -0
- data/test/unit/tax_rule_test.rb +70 -0
- data/test/unit/tax_table_test.rb +82 -0
- data/test/unit/tracking_data_test.rb +54 -0
- data/test/unit/unarchive_order_command_test.rb +66 -0
- data/test/unit/us_country_area_test.rb +76 -0
- data/test/unit/us_state_area_test.rb +70 -0
- data/test/unit/us_zip_area_test.rb +66 -0
- data/test/unit/world_area_test.rb +48 -0
- data/test/xml/apiv2.xsd +997 -0
- data/test/xml/test_check_persisting_works_expected.xml +213 -0
- data/var/cacert.pem +7815 -0
- metadata +200 -0
@@ -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
|
@@ -0,0 +1,218 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/checkout_command_xml_generator_test.rb
|
4
|
+
# Authors: Manuel Holtgrewe <purestorm at ggnore dot net>
|
5
|
+
# Tony Chan <api.htchan at gmail dot com>
|
6
|
+
# Copyright: (c) 2007 by Manuel Holtgrewe
|
7
|
+
# License: MIT License as follows:
|
8
|
+
#
|
9
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
# a copy of this software and associated documentation files (the
|
11
|
+
# "Software"), to deal in the Software without restriction, including
|
12
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
# distribute, sublicense, and/or sell copies of the Software, and to permit
|
14
|
+
# persons to whom the Software is furnished to do so, subject to the
|
15
|
+
# following conditions:
|
16
|
+
#
|
17
|
+
# The above copyright notice and this permission notice shall be included
|
18
|
+
# in all copies or substantial portions of the Software.
|
19
|
+
#
|
20
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21
|
+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
23
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
24
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
25
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
26
|
+
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
#++
|
28
|
+
|
29
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
30
|
+
|
31
|
+
require 'google4r/checkout'
|
32
|
+
|
33
|
+
require 'test/frontend_configuration'
|
34
|
+
|
35
|
+
require 'tempfile'
|
36
|
+
|
37
|
+
require 'open3' rescue require 'win32/open3'
|
38
|
+
|
39
|
+
require 'rexml/document'
|
40
|
+
|
41
|
+
# Test for the class UsZipArea.
|
42
|
+
#
|
43
|
+
# TODO: Make the tests querying Google Checkout's diagnose service and the XSD validation optional.
|
44
|
+
class Google4R::Checkout::CheckoutCommandXmlGeneratorTest < Test::Unit::TestCase
|
45
|
+
include Google4R::Checkout
|
46
|
+
|
47
|
+
def setup
|
48
|
+
@schema_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'xml', 'apiv2.xsd'))
|
49
|
+
@expected_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'xml', 'test_check_persisting_works_expected.xml'))
|
50
|
+
|
51
|
+
@frontend = Frontend.new(FRONTEND_CONFIGURATION)
|
52
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
53
|
+
@command = @frontend.create_checkout_command
|
54
|
+
@generator = CheckoutCommandXmlGenerator.new(@command)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Note that this is not really a good test. We do not actually compare anything.
|
58
|
+
# Instead, we simply generate some XML, validate it using XSD via xmllint and then
|
59
|
+
# compare it to the output that we validated by reading it earlier.
|
60
|
+
def test_check_persisting_works
|
61
|
+
tax_tables = Array.new
|
62
|
+
table = TaxTable.new(false)
|
63
|
+
table.name = 'Default Table'
|
64
|
+
table.create_rule do |rule|
|
65
|
+
rule.rate = 0.04
|
66
|
+
rule.area = UsCountryArea.new
|
67
|
+
rule.area.area = UsCountryArea::ALL
|
68
|
+
end
|
69
|
+
table.create_rule do |rule|
|
70
|
+
rule.area=Google4R::Checkout::PostalArea.new('GB', 'S6*')
|
71
|
+
rule.shipping_taxed=true
|
72
|
+
rule.rate=0.03
|
73
|
+
end
|
74
|
+
table.create_rule do |rule|
|
75
|
+
rule.area=Google4R::Checkout::PostalArea.new('GB')
|
76
|
+
rule.shipping_taxed=false
|
77
|
+
rule.rate=0.07
|
78
|
+
end
|
79
|
+
table.create_rule do |rule|
|
80
|
+
rule.area=Google4R::Checkout::WorldArea.new
|
81
|
+
rule.shipping_taxed=true
|
82
|
+
rule.rate=0.10
|
83
|
+
end
|
84
|
+
tax_tables << table
|
85
|
+
nondefault_table = TaxTable.new(false)
|
86
|
+
nondefault_table.name = 'Special Table'
|
87
|
+
nondefault_table.create_rule do |rule|
|
88
|
+
rule.rate = 0.02
|
89
|
+
rule.area = UsCountryArea.new
|
90
|
+
rule.area.area = UsCountryArea::ALL
|
91
|
+
end
|
92
|
+
tax_tables << nondefault_table
|
93
|
+
|
94
|
+
TestTaxTableFactory.any_instance.stubs(:effective_tax_tables_at).returns(tax_tables)
|
95
|
+
@frontend.tax_table_factory = TestTaxTableFactory.new
|
96
|
+
@command = @frontend.create_checkout_command
|
97
|
+
|
98
|
+
@command.continue_shopping_url = 'http://wwww.example.com/continue_shopping'
|
99
|
+
@command.edit_cart_url = 'http://wwww.example.com/edit_cart'
|
100
|
+
@command.request_buyer_phone_number = false
|
101
|
+
@command.merchant_calculations_url = 'http://www.example.com/merchant_calcuations'
|
102
|
+
@command.accept_merchant_coupons = true
|
103
|
+
@command.accept_gift_certificates = true
|
104
|
+
@command.platform_id = '1234567890'
|
105
|
+
@command.analytics_data = 'abcd1234defgh5678ijklmn'
|
106
|
+
|
107
|
+
@generator = CheckoutCommandXmlGenerator.new(@command)
|
108
|
+
|
109
|
+
@command.shopping_cart.expires_at = Time.parse('2007-11-29T15:33:20 UTC')
|
110
|
+
|
111
|
+
@command.create_shipping_method(PickupShipping) do |shipping|
|
112
|
+
shipping.name = 'Pickup Test Shipping'
|
113
|
+
shipping.price = Money.new(100, 'USD')
|
114
|
+
end
|
115
|
+
|
116
|
+
@command.create_shipping_method(FlatRateShipping) do |shipping|
|
117
|
+
shipping.name = 'State Test Shipping'
|
118
|
+
shipping.price = Money.new(100, 'USD')
|
119
|
+
|
120
|
+
shipping.create_allowed_area(UsStateArea) { |area| area.state = 'CA' }
|
121
|
+
shipping.create_excluded_area(UsStateArea) { |area| area.state = 'TX' }
|
122
|
+
end
|
123
|
+
|
124
|
+
@command.create_shipping_method(FlatRateShipping) do |shipping|
|
125
|
+
shipping.name = 'Country Area Test Shipping'
|
126
|
+
shipping.price = Money.new(100, 'USD')
|
127
|
+
|
128
|
+
shipping.create_allowed_area(UsCountryArea) { |area| area.area = UsCountryArea::FULL_50_STATES }
|
129
|
+
shipping.create_excluded_area(UsCountryArea) { |area| area.area = UsCountryArea::CONTINENTAL_48 }
|
130
|
+
end
|
131
|
+
|
132
|
+
@command.create_shipping_method(FlatRateShipping) do |shipping|
|
133
|
+
shipping.name = 'Zip Test Shipping'
|
134
|
+
shipping.price = Money.new(100, 'USD')
|
135
|
+
|
136
|
+
shipping.create_allowed_area(UsZipArea) { |area| area.pattern = '1*' }
|
137
|
+
shipping.create_excluded_area(UsZipArea) { |area| area.pattern = '12*' }
|
138
|
+
end
|
139
|
+
|
140
|
+
@command.shopping_cart.private_data = { 'we' => 'can pass in some data here'.split }
|
141
|
+
|
142
|
+
1.upto(10) do |i|
|
143
|
+
@command.shopping_cart.create_item do |item|
|
144
|
+
item.name = "Item Name #{i}"
|
145
|
+
item.description = "Description #{i}"
|
146
|
+
item.unit_price = Money.new(i * 1000, 'USD')
|
147
|
+
item.quantity = i * 2
|
148
|
+
item.id = "Merchant ID #{i}"
|
149
|
+
if i == 1 then
|
150
|
+
item.private_data = { 'some' => { 'data' => 'Yeah, Yeah!' }, 'bars' => { 'bar' => [ 1, 2 ] } }
|
151
|
+
end
|
152
|
+
|
153
|
+
item.tax_table = nondefault_table if i % 2 == 1
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
xml_str = @generator.generate
|
158
|
+
assert_xml_validates_against_xml_schema(@schema_path, xml_str)
|
159
|
+
assert_string_equals_file_contents(@expected_path, xml_str)
|
160
|
+
assert_google_checkout_diagnose_returns_no_warnings(xml_str)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Test that values within hashes are persisted correctly.
|
164
|
+
def test_process_hash_processes_hash_values_correctly
|
165
|
+
element = REXML::Element.new('root')
|
166
|
+
@generator.instance_eval { process_hash(element, { 'key' => 'value' }) }
|
167
|
+
assert_equal "<root><key>value</key></root>", element.to_s
|
168
|
+
end
|
169
|
+
|
170
|
+
protected
|
171
|
+
|
172
|
+
def assert_google_checkout_diagnose_returns_no_warnings(xml_str)
|
173
|
+
tmpfile = Tempfile.new('xml_output')
|
174
|
+
tmpfile << xml_str
|
175
|
+
tmpfile.flush
|
176
|
+
|
177
|
+
url = "https://%s:%s@sandbox.google.com/checkout/cws/v2/Merchant/%s/request/diagnose" %
|
178
|
+
[ FRONTEND_CONFIGURATION[:merchant_id], FRONTEND_CONFIGURATION[:merchant_key],
|
179
|
+
FRONTEND_CONFIGURATION[:merchant_id] ]
|
180
|
+
|
181
|
+
stdin, stdout, stderr = Open3.popen3("curl -d @#{tmpfile.path} #{url}")
|
182
|
+
outstr = stdout.read
|
183
|
+
errstr = stderr.read
|
184
|
+
|
185
|
+
assert (outstr != ''), 'curl command not available'
|
186
|
+
|
187
|
+
# Check that there is no <warnings> tag in the XML.
|
188
|
+
xml_document = REXML::Document.new(outstr)
|
189
|
+
assert 0, xml_document.root.elements.to_a('//warnings').size
|
190
|
+
|
191
|
+
tmpfile.close!
|
192
|
+
end
|
193
|
+
|
194
|
+
def assert_xml_validates_against_xml_schema(schema_path, xml_str)
|
195
|
+
tmpfile = Tempfile.new('xml_output')
|
196
|
+
tmpfile << xml_str
|
197
|
+
tmpfile.flush
|
198
|
+
|
199
|
+
#puts "---\n#{xml_str}\n---"
|
200
|
+
|
201
|
+
stdin, stdout, stderr = Open3.popen3("xmllint --schema #{schema_path} #{tmpfile.path}")
|
202
|
+
|
203
|
+
outstr = stdout.read
|
204
|
+
errstr = stderr.read
|
205
|
+
if errstr !~ /validates$/ then
|
206
|
+
assert false, "The document did not validate: ---\nOUT:#{outstr}\nERR:#{errstr}\n---"
|
207
|
+
else
|
208
|
+
assert true
|
209
|
+
end
|
210
|
+
|
211
|
+
tmpfile.close!
|
212
|
+
end
|
213
|
+
|
214
|
+
def assert_string_equals_file_contents(expected_path, xml_str)
|
215
|
+
file_contents = File.open(expected_path, 'r') { |f| f.read }
|
216
|
+
assert_strings_equal file_contents, xml_str
|
217
|
+
end
|
218
|
+
end
|