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,94 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google4r
|
3
|
+
# File: lib/google4r/checkout/utils.rb
|
4
|
+
# Author: Tony Chan <api.htchan@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
|
+
# This file contains the classes and modules that are used by the command
|
28
|
+
# generating code.
|
29
|
+
|
30
|
+
require 'cgi'
|
31
|
+
require 'openssl'
|
32
|
+
require 'base64'
|
33
|
+
|
34
|
+
module Google4R #:nodoc:
|
35
|
+
module Checkout #:nodoc:
|
36
|
+
# HTML Signing
|
37
|
+
#
|
38
|
+
# Args:
|
39
|
+
# - params -- html form parameters
|
40
|
+
# - merchant_key -- Google Checkout merchant key
|
41
|
+
#
|
42
|
+
# Returns:
|
43
|
+
# - signature -- The base-64 encoded result of hashing the serialized
|
44
|
+
# parameters with the merchant key
|
45
|
+
#
|
46
|
+
# Example
|
47
|
+
# -------
|
48
|
+
# require 'google4r/checkout/utils'
|
49
|
+
#
|
50
|
+
# Google4R::Checkout.sign({:a=>'123', :b=>'456'}, 'merchantkey')
|
51
|
+
# => "5qBQYatFZk5BMS1hm5gSUS+9yrg="
|
52
|
+
#
|
53
|
+
def self.sign(params, merchant_key)
|
54
|
+
raise "params must be a Hash (e.g. {param1 => value1, param2 => value2, ...})" unless params.kind_of? Hash
|
55
|
+
raise "merchant_key must be a String" unless merchant_key.kind_of? String
|
56
|
+
|
57
|
+
# Remove unwanted parameters
|
58
|
+
params.delete_if do |key, value|
|
59
|
+
key = key.to_s
|
60
|
+
key == '_charset_' || key == 'analyticsdata' ||
|
61
|
+
key == 'urchindata' || key =~ /^(.+\.)*[xy]$/
|
62
|
+
end
|
63
|
+
|
64
|
+
# Strip away whitespaces and url-encode the values
|
65
|
+
params.each do |key, value|
|
66
|
+
params[key] = CGI::escape(value.to_s.strip)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Sort parameters alphabetically by value and then key
|
70
|
+
params_arr = params.sort do |x, y|
|
71
|
+
if x[0] != y[0] then
|
72
|
+
x[0].to_s <=> y[0].to_s
|
73
|
+
else
|
74
|
+
x[1].to_s <=> y[1].to_s
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create parameter string to be hashed
|
79
|
+
params_str = ''
|
80
|
+
params_arr.each do |x|
|
81
|
+
if params_str != '' then params_str += '&' end
|
82
|
+
params_str += x[0].to_s + '=' + x[1]
|
83
|
+
end
|
84
|
+
|
85
|
+
# Generate hashed signature
|
86
|
+
signature = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new,
|
87
|
+
merchant_key,
|
88
|
+
params_str)
|
89
|
+
|
90
|
+
# Encode the hash value in Base64 before returning it
|
91
|
+
return Base64.encode64(signature).chomp
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|