google4r-checkout 1.1.beta5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/README.md +87 -21
- data/lib/google4r/checkout/commands.rb +60 -1
- data/lib/google4r/checkout/frontend.rb +4 -0
- data/lib/google4r/checkout/notifications.rb +5 -3
- data/lib/google4r/checkout/shared.rb +72 -0
- data/lib/google4r/checkout/xml_generation.rb +39 -1
- data/test/integration/checkout_command_test.rb +8 -0
- data/test/unit/chargeback_amount_notification_test.rb +25 -0
- data/test/unit/checkout_command_test.rb +26 -2
- data/test/unit/parameterized_url_test.rb +57 -0
- data/test/unit/url_parameter_test.rb +55 -0
- metadata +52 -16
data/CHANGES
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
=google4r-checkout Changelog
|
2
2
|
|
3
|
+
== 1.1.0 (2011-06-29)
|
4
|
+
|
5
|
+
* Support for newer refund-notification XML format, contributed by Chris Parrish
|
6
|
+
* Update README to remove outdated Rails gem locking technique and add more examples
|
7
|
+
* Modernize gem build
|
8
|
+
|
3
9
|
== 1.1.beta5 (2010-09-21)
|
4
10
|
|
5
11
|
* Support for chargeback fees and chargeback gateway refund fees, contributed by George Palmer
|
data/README.md
CHANGED
@@ -46,27 +46,93 @@ The file should contain content similar to:
|
|
46
46
|
:use_sandbox => true
|
47
47
|
}
|
48
48
|
|
49
|
-
##
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
49
|
+
## Sending Commands to Google Checkout
|
50
|
+
|
51
|
+
To send commands to Google Checkout, use a Google4R::Checkout::Frontend object. The Frontend class contains a variety of methods for easily generating several types of commands, including checkout, cancel_order, charge_and_ship_order, etc.
|
52
|
+
|
53
|
+
Here's an example:
|
54
|
+
|
55
|
+
# Create the Frontend from our configuration
|
56
|
+
frontend = Google4R::Checkout::Frontend.new(
|
57
|
+
:merchant_id => conf['merchant_id'],
|
58
|
+
:merchant_key => conf['merchant_key'],
|
59
|
+
:use_sandbox => conf['use_sandbox']
|
60
|
+
)
|
61
|
+
|
62
|
+
# Create a new checkout command (to place an order)
|
63
|
+
cmd = frontend.create_checkout_command
|
64
|
+
|
65
|
+
# Add an item to the command's shopping cart
|
66
|
+
cmd.shopping_cart.create_item do |item|
|
67
|
+
item.name = "2-liter bottle of Diet Pepsi"
|
68
|
+
item.quantity = 100
|
69
|
+
item.unit_price = Money.new(1.99, "USD")
|
70
|
+
end
|
71
|
+
|
72
|
+
# Send the command to Google and capture the HTTP response
|
73
|
+
response = cmd.send_to_google_checkout
|
74
|
+
|
75
|
+
# Redirect the user to Google Checkout to complete the transaction
|
76
|
+
redirect_to response.redirect_url
|
77
|
+
|
78
|
+
For more information, see the Frontend class's RDocs and the Google Checkout API documentation.
|
79
|
+
|
80
|
+
## Writing Responders
|
81
|
+
|
82
|
+
To receive notifications from Google Checkout, you'll need to write an action in your web application to respond to Google Checkout XML requests. The basic strategy for this is to use a NotificationHandler object (which can be obtained through a Frontend object) to parse the HTTP request, then handle the resulting Notification object according to its class. You should then generate a NotificationAcknowledgment and return it as the response.
|
83
|
+
|
84
|
+
It's a good idea to verify the HTTP authentication headers for incoming requests. This will be a combination of your Merchant ID and Merchant Key.
|
85
|
+
|
86
|
+
Here is an example of how one might do this in Rails:
|
87
|
+
|
88
|
+
class PaymentNotificationController < ApplicationController
|
89
|
+
before_filter :verify_merchant_credentials, :only => [:google]
|
90
|
+
|
91
|
+
def google
|
92
|
+
frontend = Google4R::Checkout::Frontend.new(
|
93
|
+
:merchant_id => conf['merchant_id'],
|
94
|
+
:merchant_key => conf['merchant_key'],
|
95
|
+
:use_sandbox => conf['use_sandbox']
|
96
|
+
)
|
97
|
+
handler = frontend.create_notification_handler
|
98
|
+
|
99
|
+
begin
|
100
|
+
notification = handler.handle(request.raw_post) # raw_post contains the XML
|
101
|
+
rescue Google4R::Checkout::UnknownNotificationType
|
102
|
+
# This can happen if Google adds new commands and Google4R has not been
|
103
|
+
# upgraded yet. It is not fatal.
|
104
|
+
logger.warn "Unknown notification type"
|
105
|
+
return render :text => 'ignoring unknown notification type', :status => 200
|
106
|
+
end
|
107
|
+
|
108
|
+
case notification
|
109
|
+
when Google4R::Checkout::NewOrderNotification then
|
110
|
+
|
111
|
+
# handle a NewOrderNotification
|
112
|
+
|
113
|
+
when Google4R::Checkout::OrderStateChangeNotification then
|
114
|
+
|
115
|
+
# handle an OrderStateChangeNotification
|
116
|
+
|
117
|
+
else
|
118
|
+
return head :text => "I don't know how to handle a #{notification.class}", :status => 500
|
119
|
+
end
|
120
|
+
|
121
|
+
notification_acknowledgement = Google4R::Checkout::NotificationAcknowledgement.new(notification)
|
122
|
+
render :xml => notification_acknowledgement, :status => 200
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
# make sure the request authentication headers use the right merchant_id and merchant_key
|
127
|
+
def verify_merchant_credentials
|
128
|
+
authenticate_or_request_with_http_basic("Google Checkout notification endpoint") do |merchant_id, merchant_key|
|
129
|
+
(conf['merchant_id'].to_s == merchant_id.to_s) and (conf['merchant_key'].to_s == merchant_key.to_s)
|
130
|
+
end
|
131
|
+
end
|
68
132
|
end
|
69
133
|
|
70
|
-
|
134
|
+
## Dependencies
|
135
|
+
|
136
|
+
google4r-checkout makes extensive use of the money gem library, which is a required dependency. The unit tests also use Mocha and Nokogiri, which should be automatically pulled down by Bundler.
|
71
137
|
|
72
|
-
|
138
|
+
google4r-checkout doesn't depend on any particular Ruby web framework, so it should work with any version of Rails, Sinatra, Camping, or even no web framework at all.
|
@@ -93,12 +93,13 @@ module Google4R #:nodoc:
|
|
93
93
|
url_str +=
|
94
94
|
if self.class == CheckoutCommand then
|
95
95
|
CHECKOUT_API_URL
|
96
|
-
elsif self.class == OrderReportCommand then
|
96
|
+
elsif self.class == OrderReportCommand || self.class == NotificationHistoryRequestCommand then
|
97
97
|
ORDER_REPORT_API_URL
|
98
98
|
else
|
99
99
|
ORDER_PROCESSING_API_URL
|
100
100
|
end
|
101
101
|
url_str = url_str % frontend.configuration[:merchant_id]
|
102
|
+
|
102
103
|
url = URI.parse(url_str)
|
103
104
|
|
104
105
|
request = Net::HTTP::Post.new(url.path)
|
@@ -136,6 +137,23 @@ module Google4R #:nodoc:
|
|
136
137
|
when 'request-received'
|
137
138
|
serial_number = xml_doc.elements['/request-received'].attributes['serial-number']
|
138
139
|
return serial_number
|
140
|
+
# report history notifications
|
141
|
+
when 'order-summary'
|
142
|
+
raise 'Response type OrderSummaryResponse not implemented'
|
143
|
+
when 'new-order-notification'
|
144
|
+
return NewOrderNotification.create_from_element xml_doc.root, @frontend
|
145
|
+
when 'risk-information-notification'
|
146
|
+
return RiskInformationNotification.create_from_element xml_doc.root, @frontend
|
147
|
+
when 'order-state-change-notification'
|
148
|
+
return OrderStateChangeNotification.create_from_element xml_doc.root, @frontend
|
149
|
+
when 'charge-amount-notification'
|
150
|
+
return ChargeAmountNotification.create_from_element xml_doc.root, @frontend
|
151
|
+
when 'authorization-amount-notification'
|
152
|
+
return AuthorizationAmountNotification.create_from_element xml_doc.root, @frontend
|
153
|
+
when 'refund-amount-notification'
|
154
|
+
return RefundAmountNotification.create_from_element xml_doc.root, @frontend
|
155
|
+
when 'chargeback-amount-notification'
|
156
|
+
return ChargebackAmountNotification.create_from_element xml_doc.root, @frontend
|
139
157
|
else
|
140
158
|
raise "Unknown response:\n--\n#{xml_doc.to_s}\n--"
|
141
159
|
end
|
@@ -222,6 +240,8 @@ module Google4R #:nodoc:
|
|
222
240
|
# An array of ShippingMethod objects of this CheckoutCommand. Use
|
223
241
|
# #create_shipping_method to create new shipping methods.
|
224
242
|
attr_reader :shipping_methods
|
243
|
+
|
244
|
+
attr_reader :parameterized_urls
|
225
245
|
|
226
246
|
# The URL at where the cart can be edited (String, optional).
|
227
247
|
attr_accessor :edit_cart_url
|
@@ -264,6 +284,7 @@ module Google4R #:nodoc:
|
|
264
284
|
super(frontend)
|
265
285
|
@shopping_cart = ShoppingCart.new(self)
|
266
286
|
@shipping_methods = Array.new
|
287
|
+
@parameterized_urls = Array.new
|
267
288
|
if frontend.tax_table_factory
|
268
289
|
@tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.new)
|
269
290
|
end
|
@@ -295,6 +316,26 @@ module Google4R #:nodoc:
|
|
295
316
|
|
296
317
|
return shipping_method
|
297
318
|
end
|
319
|
+
|
320
|
+
# Use this method to create a new parameterized_url object. It requires the URL
|
321
|
+
# to be passed in the 'opts' hash. It will create a new instance of the
|
322
|
+
# paramterized URL object.
|
323
|
+
#
|
324
|
+
# Raises an argument error if the URL passed in the opts hash is not a String
|
325
|
+
#
|
326
|
+
# To find more information on 3rd party conversion tracking visit the API documentation
|
327
|
+
# http://code.google.com/apis/checkout/developer/checkout_pixel_tracking.html
|
328
|
+
def create_parameterized_url(opts, &block)
|
329
|
+
raise(ArgumentError, "Url option required") unless opts[:url].kind_of?(String)
|
330
|
+
|
331
|
+
parameterized_url = ParameterizedUrl.new(opts[:url])
|
332
|
+
@parameterized_urls << parameterized_url
|
333
|
+
|
334
|
+
yield(parameterized_url) if block_given?
|
335
|
+
|
336
|
+
return parameterized_url
|
337
|
+
end
|
338
|
+
|
298
339
|
end
|
299
340
|
|
300
341
|
# CheckoutRedirectResponse instances are returned when a CheckoutCommand is successfully
|
@@ -638,5 +679,23 @@ module Google4R #:nodoc:
|
|
638
679
|
ReturnOrderReportCommandXmlGenerator.new(self).generate
|
639
680
|
end
|
640
681
|
end
|
682
|
+
|
683
|
+
# The <notification-history-request> command allows you to receive
|
684
|
+
# a notification type node refered to by the serial number posted by
|
685
|
+
# google to the notification callback URL
|
686
|
+
class NotificationHistoryRequestCommand < Command
|
687
|
+
|
688
|
+
attr_reader :serial_number
|
689
|
+
|
690
|
+
def initialize(frontend, serial_number)
|
691
|
+
super frontend
|
692
|
+
|
693
|
+
@serial_number = serial_number
|
694
|
+
end
|
695
|
+
|
696
|
+
def to_xml
|
697
|
+
NotificationHistoryReportCommandXmlGenerator.new(self).generate
|
698
|
+
end
|
699
|
+
end
|
641
700
|
end
|
642
701
|
end
|
@@ -217,6 +217,10 @@ module Google4R #:nodoc:
|
|
217
217
|
def create_order_report_command(start_date, end_date)
|
218
218
|
return OrderReportCommand.new(self, start_date, end_date)
|
219
219
|
end
|
220
|
+
|
221
|
+
def create_notification_history_request_command(serial_number)
|
222
|
+
return NotificationHistoryRequestCommand.new(self, serial_number)
|
223
|
+
end
|
220
224
|
end
|
221
225
|
end
|
222
226
|
end
|
@@ -368,9 +368,11 @@ module Google4R #:nodoc:
|
|
368
368
|
amount = (BigDecimal.new(element.elements['total-refund-amount'].text)*100).to_i
|
369
369
|
refund.total_refund_amount = Money.new(amount, currency)
|
370
370
|
|
371
|
-
|
372
|
-
|
373
|
-
|
371
|
+
if element.elements['latest-fee-refund-amount']
|
372
|
+
currency = element.elements['latest-fee-refund-amount'].attributes['currency']
|
373
|
+
amount = (BigDecimal.new(element.elements['latest-fee-refund-amount'].text)*100).to_i
|
374
|
+
refund.latest_fee_refund_amount = Money.new(amount, currency)
|
375
|
+
end
|
374
376
|
|
375
377
|
refund.timestamp = Time.parse(element.elements['timestamp'].text)
|
376
378
|
|
@@ -1281,6 +1281,78 @@ module Google4R #:nodoc:
|
|
1281
1281
|
end
|
1282
1282
|
end
|
1283
1283
|
|
1284
|
+
# ParamaterizedUrl instances are used
|
1285
|
+
class ParameterizedUrl
|
1286
|
+
|
1287
|
+
# The third party conversion tracker URL
|
1288
|
+
attr_accessor :url
|
1289
|
+
|
1290
|
+
# Paramters passed to the third party conversion tracker - Read Only
|
1291
|
+
attr_reader :url_parameters
|
1292
|
+
|
1293
|
+
def initialize(url)
|
1294
|
+
@url = url.to_s
|
1295
|
+
@url_parameters = Array.new
|
1296
|
+
end
|
1297
|
+
|
1298
|
+
# UrlParameters can be created (recommended) using this method by passing in a hash
|
1299
|
+
# containing values for the :name of the parameter as is it to be provided to the third
|
1300
|
+
# party conversion tracker, and the :parameter_type that has a valued assigned by Google Checkout
|
1301
|
+
def create_url_parameter(opts)
|
1302
|
+
url_parameter = UrlParameter.new(self,opts)
|
1303
|
+
@url_parameters << url_parameter
|
1304
|
+
|
1305
|
+
return url_parameter
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
# Url Paramaters that are available from the Google Checkout API that can be
|
1311
|
+
# passed to the third party conversion tracker
|
1312
|
+
#
|
1313
|
+
# UrlParameter objects require a parameter name, which is the name of the value to be
|
1314
|
+
# provided to the third party conversion tracker, and a parameter type which is
|
1315
|
+
# the name of the value, as assigned by Google Checkout.
|
1316
|
+
#
|
1317
|
+
# The parameter_type must be a string, and must be a valid type, as defined in the subsequant list
|
1318
|
+
# otherwise an Argument Error is thrown.
|
1319
|
+
#
|
1320
|
+
# The :name symbol must have an associated value, and be of the String class, other
|
1321
|
+
# an argument error will be thrown
|
1322
|
+
# Below is a list of defined types, as assigned by Google Checkout.
|
1323
|
+
#
|
1324
|
+
# buyer-id - A Google-assigned value that uniquely identifies a customer email address.
|
1325
|
+
# order-id - A Google-assigned value that uniquely identifies an order. This value is displayed in the Merchant Center for each order. If you have implemented the Notification API, you will also see this value in all Google Checkout notifications.
|
1326
|
+
# order-subtotal - The total cost for all of the items in the order including coupons and discounts but excluding taxes and shipping charges.
|
1327
|
+
# order-subtotal-plus-tax - The total cost for all of the items in the order, including taxes, coupons and discounts, but excluding shipping charges.
|
1328
|
+
# order-subtotal-plus-shipping - The total cost for all of the items in the order, including shipping charges, coupons and discounts, but excluding taxes.
|
1329
|
+
# order-total - The total cost for all of the items in the order, including taxes, shipping charges, coupons and discounts.
|
1330
|
+
# tax-amount - The total amount of taxes charged for an order.
|
1331
|
+
# shipping-amount - The shipping cost associated with an order.
|
1332
|
+
# coupon-amount - The total amount of all coupons factored into the order total.
|
1333
|
+
# billing-city - The city associated with the order's billing address.
|
1334
|
+
# billing-region - The U.S. state associated with the order's billing address.
|
1335
|
+
# billing-postal-code - The five-digit U.S. zip code associated with the order's billing address.
|
1336
|
+
# billing-country-code - The two-letter ISO 3166 country code associated with the order's billing address.
|
1337
|
+
# shipping-city - The city associated with the order's shipping address.
|
1338
|
+
# shipping-region - The U.S. state associated with the order's shipping address.
|
1339
|
+
# shipping-postal-code - The five-digit U.S. zip code associated with the order's shipping address.
|
1340
|
+
# shipping-country-code - The two-letter ISO 3166 country code associated with the order's shipping address.
|
1341
|
+
class UrlParameter
|
1342
|
+
attr_reader :parameterized_url,:name,:parameter_type
|
1343
|
+
|
1344
|
+
VALID_TYPES = ['buyer-id', 'order-id', 'order-subtotal', 'order-subtotal-plus-tax', 'order-subtotal-plus-shipping', 'order-total', 'tax-amount','shipping-amount', 'coupon-amount', 'billing-city', 'billing-region', 'billing-postal-code', 'billing-country-code', 'shipping-city', 'shipping-region', 'shipping-postal-code', 'shipping-country-code'].freeze
|
1345
|
+
|
1346
|
+
def initialize(parameterized_url,opts)
|
1347
|
+
raise(ArgumentError,"url-parameter type can only be #{VALID_TYPES.join(", ")}") unless VALID_TYPES.include?(opts[:type])
|
1348
|
+
raise(ArgumentError, "Missing or invalid parameter name") unless opts[:name].kind_of?(String)
|
1349
|
+
|
1350
|
+
@parameterized_url = parameterized_url
|
1351
|
+
@name = opts[:name]
|
1352
|
+
@parameter_type = opts[:type]
|
1353
|
+
end
|
1354
|
+
end
|
1355
|
+
|
1284
1356
|
# financial_state
|
1285
1357
|
# REVIEWING - Google Checkout is reviewing the order.
|
1286
1358
|
# CHARGEABLE - The order is ready to be charged.
|
@@ -76,6 +76,7 @@ module Google4R #:nodoc:
|
|
76
76
|
ReturnItemsCommand => 'return-items',
|
77
77
|
ResetItemsShippingInformationCommand => 'reset-items-shipping-information',
|
78
78
|
OrderReportCommand => 'order-list-request',
|
79
|
+
NotificationHistoryRequestCommand => 'notification-history-request',
|
79
80
|
}
|
80
81
|
|
81
82
|
def initialize(command)
|
@@ -197,7 +198,14 @@ module Google4R #:nodoc:
|
|
197
198
|
analytics_element = flow_element.add_element('analytics-data')
|
198
199
|
analytics_element.text = command.analytics_data
|
199
200
|
end
|
200
|
-
|
201
|
+
|
202
|
+
# <parameterized-urls>
|
203
|
+
if command.parameterized_urls then
|
204
|
+
parameterized_url_element = flow_element.add_element('parameterized-urls')
|
205
|
+
command.parameterized_urls.each do |parameterized_url|
|
206
|
+
self.process_parameterized_urls(parameterized_url, parameterized_url_element)
|
207
|
+
end
|
208
|
+
end
|
201
209
|
end
|
202
210
|
|
203
211
|
# adds the tax-tables to the parent xml element
|
@@ -551,6 +559,19 @@ module Google4R #:nodoc:
|
|
551
559
|
end
|
552
560
|
end
|
553
561
|
|
562
|
+
# Adda the paramterized URL nodes for 3rd party conversion tracking
|
563
|
+
# Adds a <paramertized-url> element to a parent (<parameterized-urls>) element
|
564
|
+
def process_parameterized_urls(parameterized_url, parent)
|
565
|
+
parameterized_url_node = parent.add_element('parameterized-url')
|
566
|
+
parameterized_url_node.add_attribute('url', parameterized_url.url)
|
567
|
+
parent_parameters_node = parameterized_url_node.add_element('parameters') if parameterized_url.url_parameters
|
568
|
+
parameterized_url.url_parameters.each do |parameter|
|
569
|
+
parameter_node = parent_parameters_node.add_element('url-parameter')
|
570
|
+
parameter_node.add_attribute('name', parameter.name)
|
571
|
+
parameter_node.add_attribute('type',parameter.parameter_type)
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
554
575
|
# Converts a Hash into an XML structure. The keys are converted to tag names. If
|
555
576
|
# the values are Hashs themselves then process_hash is called upon them. If the
|
556
577
|
# values are Arrays then a new element with the key's name will be created.
|
@@ -999,5 +1020,22 @@ module Google4R #:nodoc:
|
|
999
1020
|
end
|
1000
1021
|
end
|
1001
1022
|
end
|
1023
|
+
|
1024
|
+
class NotificationHistoryReportCommandXmlGenerator < CommandXmlGenerator
|
1025
|
+
|
1026
|
+
def initialize(command)
|
1027
|
+
@command = command
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
protected
|
1031
|
+
|
1032
|
+
def process_command(command)
|
1033
|
+
root = super
|
1034
|
+
|
1035
|
+
sn_element = root.add_element('serial-number')
|
1036
|
+
sn_element.text = command.serial_number
|
1037
|
+
end
|
1038
|
+
end
|
1039
|
+
|
1002
1040
|
end
|
1003
1041
|
end
|
@@ -228,6 +228,14 @@ class Google4R::Checkout::CheckoutCommandIntegrationTest < Test::Unit::TestCase
|
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
231
|
+
# Add a paramterized URL with url parameters
|
232
|
+
command.create_parameterized_url(:url => "http://google.ca") do |parameterized_url|
|
233
|
+
parameterized_url.create_url_parameter(:name => "order", :type => 'order-id')
|
234
|
+
end
|
235
|
+
|
236
|
+
# Add a parameterized URL without URL parameters
|
237
|
+
command.create_parameterized_url(:url => "http://www.google.com")
|
238
|
+
|
231
239
|
# Add items to the cart.
|
232
240
|
1.upto(5) do |i|
|
233
241
|
command.shopping_cart.create_item do |item|
|
@@ -51,6 +51,18 @@ class Google4R::Checkout::ChargebackAmountNotificationTest < Test::Unit::TestCas
|
|
51
51
|
<timestamp>2006-03-18T20:25:31</timestamp>
|
52
52
|
</chargeback-amount-notification>
|
53
53
|
}
|
54
|
+
|
55
|
+
@example2_xml = %q{
|
56
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
57
|
+
<chargeback-amount-notification xmlns="http://checkout.google.com/schema/2"
|
58
|
+
serial-number="bea6bc1b-e1e2-44fe-80ff-0180e33a2614">
|
59
|
+
<google-order-number>841171949013218</google-order-number>
|
60
|
+
<latest-chargeback-amount currency="GBP">226.06</latest-chargeback-amount>
|
61
|
+
<total-chargeback-amount currency="GBP">226.06</total-chargeback-amount>
|
62
|
+
<timestamp>2006-03-18T20:25:31</timestamp>
|
63
|
+
</chargeback-amount-notification>
|
64
|
+
}
|
65
|
+
|
54
66
|
end
|
55
67
|
|
56
68
|
def test_create_from_element_works_correctly
|
@@ -66,4 +78,17 @@ class Google4R::Checkout::ChargebackAmountNotificationTest < Test::Unit::TestCas
|
|
66
78
|
assert_equal(Money.new(221, 'GBP'), notification.latest_fee_refund_amount)
|
67
79
|
assert_equal(Money.new(1000, 'GBP'), notification.latest_chargeback_fee_amount)
|
68
80
|
end
|
81
|
+
|
82
|
+
def test_create_from_minimal_element_works_correctly
|
83
|
+
root = REXML::Document.new(@example2_xml).root
|
84
|
+
|
85
|
+
notification = ChargebackAmountNotification.create_from_element(root, @frontend)
|
86
|
+
|
87
|
+
assert_equal 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614', notification.serial_number
|
88
|
+
assert_equal '841171949013218', notification.google_order_number
|
89
|
+
assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
|
90
|
+
assert_equal(Money.new(22606, 'GBP'), notification.total_chargeback_amount)
|
91
|
+
assert_equal(Money.new(22606, 'GBP'), notification.latest_chargeback_amount)
|
92
|
+
end
|
93
|
+
|
69
94
|
end
|
@@ -55,6 +55,7 @@ class Google4R::Checkout::CheckoutCommandTest < Test::Unit::TestCase
|
|
55
55
|
assert_equal @frontend, @command.frontend
|
56
56
|
assert_kind_of ShoppingCart, @command.shopping_cart
|
57
57
|
assert_equal [], @command.shipping_methods
|
58
|
+
assert_equal [], @command.parameterized_urls
|
58
59
|
assert_nil @command.edit_cart_url
|
59
60
|
assert_nil @command.continue_shopping_url
|
60
61
|
assert_nil @command.request_buyer_phone_number
|
@@ -67,7 +68,7 @@ class Google4R::Checkout::CheckoutCommandTest < Test::Unit::TestCase
|
|
67
68
|
:merchant_calculations_url, :merchant_calculations_url=,
|
68
69
|
:accept_merchant_coupons, :accept_merchant_coupons=,
|
69
70
|
:accept_gift_certificates, :accept_gift_certificates=,
|
70
|
-
:platform_id, :platform_id
|
71
|
+
:platform_id, :platform_id=, :parameterized_urls, :create_parameterized_url
|
71
72
|
].each do |symbol|
|
72
73
|
assert_respond_to @command, symbol
|
73
74
|
end
|
@@ -113,12 +114,35 @@ class Google4R::Checkout::CheckoutCommandTest < Test::Unit::TestCase
|
|
113
114
|
|
114
115
|
assert @command.shipping_methods.include?(obj)
|
115
116
|
end
|
116
|
-
end
|
117
|
+
end
|
117
118
|
|
118
119
|
def test_create_shipping_method_raises_exception_on_invalid_clazz_parameter
|
119
120
|
assert_raises(ArgumentError) { @command.create_shipping_method(String) }
|
120
121
|
end
|
121
122
|
|
123
|
+
def test_create_parameterized_url_method_works_without_block
|
124
|
+
parameterized_url = @command.create_parameterized_url(:url => "http://someurl")
|
125
|
+
|
126
|
+
assert_kind_of ParameterizedUrl,parameterized_url
|
127
|
+
|
128
|
+
assert @command.parameterized_urls.include?(parameterized_url)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_create_parameterized_url_method_works_with_block
|
132
|
+
obj = nil
|
133
|
+
|
134
|
+
@command.create_parameterized_url(:url => "http://someurl") do |parameterized_url|
|
135
|
+
obj = parameterized_url
|
136
|
+
assert_kind_of ParameterizedUrl, obj
|
137
|
+
end
|
138
|
+
|
139
|
+
assert @command.parameterized_urls.include?(obj)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_create_parameterized_url_method_raises_exception_on_missing_url
|
143
|
+
assert_raises(ArgumentError) { @command.create_parameterized_url() }
|
144
|
+
end
|
145
|
+
|
122
146
|
def test_to_xml_does_not_raise_exception
|
123
147
|
assert_nothing_raised { @command.to_xml }
|
124
148
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/paramterized_url_test.rb
|
4
|
+
# Author: Johnathan Niziol <johnathan.niziol at canadadrugs dot com>
|
5
|
+
# Copyright: (c) 2011 by Johnathan Niziol
|
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 Parameterized class.
|
35
|
+
class Google4R::Checkout::ParameterizedUrlTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@parameterized_url = ParameterizedUrl.new("http://testurl.com")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_parameterized_url_behaves_correctly
|
43
|
+
assert_respond_to @parameterized_url, :url
|
44
|
+
assert_respond_to @parameterized_url, :create_url_parameter
|
45
|
+
assert_respond_to @parameterized_url, :url_parameters
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_initialized_correctly
|
49
|
+
assert_equal "http://testurl.com", @parameterized_url.url
|
50
|
+
assert_equal [], @parameterized_url.url_parameters
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_accessors_work_correctly
|
54
|
+
@parameterized_url.url = "url"
|
55
|
+
assert_equal "url", @parameterized_url.url
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#--
|
2
|
+
# Project: google_checkout4r
|
3
|
+
# File: test/unit/paramterized_url_test.rb
|
4
|
+
# Author: Johnathan Niziol <jniziol at gmail dot com>
|
5
|
+
# Copyright: (c) 2007 by Johnathan Niziol
|
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 TaxTable class.
|
35
|
+
class Google4R::Checkout::UrlParameterTest < Test::Unit::TestCase
|
36
|
+
include Google4R::Checkout
|
37
|
+
|
38
|
+
def setup
|
39
|
+
@parameterized_url = ParameterizedUrl.new("http://www.google.com")
|
40
|
+
@url_parameter = @parameterized_url.create_url_parameter(:name => 'order', :type => 'order-id')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_url_parameter_behaves_correctly
|
44
|
+
assert_respond_to @url_parameter, :parameterized_url
|
45
|
+
assert_respond_to @url_parameter, :name
|
46
|
+
assert_respond_to @url_parameter, :parameter_type
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_initialized_correctly
|
50
|
+
assert_equal "order", @url_parameter.name
|
51
|
+
assert_equal "order-id", @url_parameter.parameter_type
|
52
|
+
assert_equal @parameterized_url, @url_parameter.parameterized_url
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
metadata
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google4r-checkout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Chan
|
14
|
+
- Dan Dukeson
|
15
|
+
- Nat Budin
|
16
|
+
- George Palmer
|
17
|
+
- Daniel Higham
|
18
|
+
- Johnathan Niziol
|
19
|
+
- Chris Parrish
|
14
20
|
autorequire:
|
15
21
|
bindir: bin
|
16
22
|
cert_chain: []
|
17
23
|
|
18
|
-
date:
|
24
|
+
date: 2011-06-29 00:00:00 -04:00
|
19
25
|
default_executable:
|
20
26
|
dependencies:
|
21
27
|
- !ruby/object:Gem::Dependency
|
@@ -34,8 +40,36 @@ dependencies:
|
|
34
40
|
version: 2.3.0
|
35
41
|
type: :runtime
|
36
42
|
version_requirements: *id001
|
37
|
-
|
38
|
-
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: mocha
|
45
|
+
prerelease: false
|
46
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
type: :development
|
56
|
+
version_requirements: *id002
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: nokogiri
|
59
|
+
prerelease: false
|
60
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id003
|
71
|
+
description: " google4r-checkout is a lightweight, framework-agnostic Ruby library to access the Google Checkout service and implement \n notification handlers. It exposes object-oriented wrappers for all of Google Checkout's API commands and notifications.\n"
|
72
|
+
email: natbudin@gmail.com
|
39
73
|
executables: []
|
40
74
|
|
41
75
|
extensions: []
|
@@ -96,6 +130,7 @@ files:
|
|
96
130
|
- test/unit/order_adjustment_test.rb
|
97
131
|
- test/unit/order_report_command_test.rb
|
98
132
|
- test/unit/order_state_change_notification_test.rb
|
133
|
+
- test/unit/parameterized_url_test.rb
|
99
134
|
- test/unit/pickup_shipping_test.rb
|
100
135
|
- test/unit/postal_area_test.rb
|
101
136
|
- test/unit/private_data_parser_test.rb
|
@@ -112,6 +147,7 @@ files:
|
|
112
147
|
- test/unit/tax_table_test.rb
|
113
148
|
- test/unit/tracking_data_test.rb
|
114
149
|
- test/unit/unarchive_order_command_test.rb
|
150
|
+
- test/unit/url_parameter_test.rb
|
115
151
|
- test/unit/us_country_area_test.rb
|
116
152
|
- test/unit/us_state_area_test.rb
|
117
153
|
- test/unit/us_zip_area_test.rb
|
@@ -122,7 +158,7 @@ files:
|
|
122
158
|
- LICENSE
|
123
159
|
- CHANGES
|
124
160
|
has_rdoc: true
|
125
|
-
homepage: http://
|
161
|
+
homepage: http://github.com/nbudin/google4r-checkout
|
126
162
|
licenses: []
|
127
163
|
|
128
164
|
post_install_message:
|
@@ -144,21 +180,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
181
|
none: false
|
146
182
|
requirements:
|
147
|
-
- - "
|
183
|
+
- - ">="
|
148
184
|
- !ruby/object:Gem::Version
|
149
|
-
hash:
|
185
|
+
hash: 3
|
150
186
|
segments:
|
151
|
-
-
|
152
|
-
|
153
|
-
- 1
|
154
|
-
version: 1.3.1
|
187
|
+
- 0
|
188
|
+
version: "0"
|
155
189
|
requirements: []
|
156
190
|
|
157
191
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.
|
192
|
+
rubygems_version: 1.5.0
|
159
193
|
signing_key:
|
160
194
|
specification_version: 3
|
161
|
-
summary:
|
195
|
+
summary: Full-featured Google Checkout library for Ruby
|
162
196
|
test_files:
|
163
197
|
- test/integration/checkout_command_test.rb
|
164
198
|
- test/unit/add_merchant_order_number_command_test.rb
|
@@ -202,6 +236,7 @@ test_files:
|
|
202
236
|
- test/unit/order_adjustment_test.rb
|
203
237
|
- test/unit/order_report_command_test.rb
|
204
238
|
- test/unit/order_state_change_notification_test.rb
|
239
|
+
- test/unit/parameterized_url_test.rb
|
205
240
|
- test/unit/pickup_shipping_test.rb
|
206
241
|
- test/unit/postal_area_test.rb
|
207
242
|
- test/unit/private_data_parser_test.rb
|
@@ -218,6 +253,7 @@ test_files:
|
|
218
253
|
- test/unit/tax_table_test.rb
|
219
254
|
- test/unit/tracking_data_test.rb
|
220
255
|
- test/unit/unarchive_order_command_test.rb
|
256
|
+
- test/unit/url_parameter_test.rb
|
221
257
|
- test/unit/us_country_area_test.rb
|
222
258
|
- test/unit/us_state_area_test.rb
|
223
259
|
- test/unit/us_zip_area_test.rb
|