google4r-checkout 1.1.beta3 → 1.1.beta4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,5 +1,17 @@
1
1
  =google4r-checkout Changelog
2
2
 
3
+ == 1.1.beta4 (2010-07-09)
4
+
5
+ * All changes in this release contributed by George Palmer (thanks very much George!)
6
+ * Make the tax field optional as can be set at Google Account level
7
+ * Add a new command ChargeAndShipOrder (v2.5 of the API although we ended up going with 2.4 but it was fully tested and worked)
8
+ * Ability to get the refund amount available in RefundAmountNotification
9
+ * Ability to get gateway fee information
10
+
11
+ == 1.1.beta3 (2010-06-28)
12
+
13
+ * Add required test files to the gem build
14
+
3
15
  == 1.1.beta2 (2010-06-23)
4
16
 
5
17
  * Make gem compatible with Money 3.x (thanks George Palmer!)
@@ -263,8 +263,10 @@ module Google4R #:nodoc:
263
263
  def initialize(frontend)
264
264
  super(frontend)
265
265
  @shopping_cart = ShoppingCart.new(self)
266
- @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.new)
267
266
  @shipping_methods = Array.new
267
+ if frontend.tax_table_factory
268
+ @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.new)
269
+ end
268
270
  end
269
271
 
270
272
  # Use this method to create a new shipping method. You have to pass in one of
@@ -353,6 +355,26 @@ module Google4R #:nodoc:
353
355
  end
354
356
  end
355
357
 
358
+ class ChargeAndShipOrderCommand < Command
359
+ # The amount to charge, optional, Money
360
+ attr_accessor :amount
361
+
362
+ # if google checkout should email buyer to ssay order is dispatched
363
+ attr_accessor :send_email
364
+
365
+ # The name of the company responsible for shipping the item. Valid values
366
+ # for this tag are DHL, FedEx, UPS, USPS and Other.
367
+ attr_accessor :carrier
368
+
369
+ # The shipper's tracking number that is associated with an order
370
+ attr_accessor :tracking_number
371
+
372
+ # Generates the XML for this ChargeOrderCommand
373
+ def to_xml
374
+ ChargeAndShipOrderCommandXmlGenerator.new(self).generate
375
+ end
376
+ end
377
+
356
378
  # The RefundOrderCommand instructs Google Checkout to refund an order
357
379
  class RefundOrderCommand < Command
358
380
  # The amount to refund, optional, Money
@@ -116,6 +116,12 @@ module Google4R #:nodoc:
116
116
  return ChargeOrderCommand.new(self)
117
117
  end
118
118
 
119
+ # Factory method to create a new ChargeAndShipOrderCommand object. Use this method to
120
+ # create your ChargeAndShipOrderCommand instances.
121
+ def create_charge_and_ship_order_command
122
+ return ChargeAndShipOrderCommand.new(self)
123
+ end
124
+
119
125
  # Factory method that creates a new CheckoutCommand object. Use this method to create
120
126
  # your CheckoutCommand instances.
121
127
  def create_checkout_command
@@ -132,7 +132,9 @@ module Google4R #:nodoc:
132
132
  @anonymous_addresses = Array.new
133
133
  @shipping_methods = Array.new
134
134
  @merchant_code_strings = Array.new
135
- @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.now)
135
+ if frontend.tax_table_factory
136
+ @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.now)
137
+ end
136
138
  end
137
139
 
138
140
  # Factory method to create a new MerchantCalculationCallback object from
@@ -207,7 +207,9 @@ module Google4R #:nodoc:
207
207
  # tax_table_factory.
208
208
  def timestamp=(time)
209
209
  @timestamp = time
210
- @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(time)
210
+ if frontend.tax_table_factory
211
+ @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(time)
212
+ end
211
213
  end
212
214
 
213
215
  # Factory method to create a new CheckoutNotification object from the REXML:Element object
@@ -266,7 +268,9 @@ module Google4R #:nodoc:
266
268
  # tax_table_factory.
267
269
  def timestamp=(time)
268
270
  @timestamp = time
269
- @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(time)
271
+ if frontend.tax_table_factory
272
+ @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(time)
273
+ end
270
274
  end
271
275
 
272
276
  # Factory method that creates a new OrderStateChangeNotification from an REXML::Element instance.
@@ -299,6 +303,8 @@ module Google4R #:nodoc:
299
303
 
300
304
  # The total amount charged for an order (Money)
301
305
  attr_accessor :total_charge_amount
306
+
307
+ attr_accessor :latest_charge_fee
302
308
 
303
309
  # Factory method that creates a new ChargeAmountNotification from an REXML::Element instance.
304
310
  # Use this to create instances of ChargeAmountNotification.
@@ -319,6 +325,10 @@ module Google4R #:nodoc:
319
325
  amount = (BigDecimal.new(element.elements['total-charge-amount'].text)*100).to_i
320
326
  charge.total_charge_amount = Money.new(amount, currency)
321
327
 
328
+ if element.elements["latest-charge-fee"]
329
+ charge.latest_charge_fee = ChargeFee.create_from_element(element.elements["latest-charge-fee"])
330
+ end
331
+
322
332
  charge.timestamp = Time.parse(element.elements['timestamp'].text)
323
333
 
324
334
  return charge
@@ -336,6 +346,9 @@ module Google4R #:nodoc:
336
346
  # The total amount refunded for an order (Money)
337
347
  attr_accessor :total_refund_amount
338
348
 
349
+ # The amount of the fee refunded by Google (Money)
350
+ attr_accessor :latest_fee_refund_amount
351
+
339
352
  # Factory method that creates a new RefundAmountNotification from an REXML::Element instance.
340
353
  # Use this to create instances of RefundAmountNotification.
341
354
  #
@@ -355,6 +368,10 @@ module Google4R #:nodoc:
355
368
  amount = (BigDecimal.new(element.elements['total-refund-amount'].text)*100).to_i
356
369
  refund.total_refund_amount = Money.new(amount, currency)
357
370
 
371
+ currency = element.elements['latest-fee-refund-amount'].attributes['currency']
372
+ amount = (BigDecimal.new(element.elements['latest-fee-refund-amount'].text)*100).to_i
373
+ refund.latest_fee_refund_amount = Money.new(amount, currency)
374
+
358
375
  refund.timestamp = Time.parse(element.elements['timestamp'].text)
359
376
 
360
377
  return refund
@@ -1261,6 +1261,26 @@ module Google4R #:nodoc:
1261
1261
  end
1262
1262
  end
1263
1263
 
1264
+ # ChargeFee instances are used in the ChargeAmountNotifications
1265
+ class ChargeFee
1266
+ # The flat portion of the fee (Money)
1267
+ attr_accessor :flat
1268
+
1269
+ # The percentage of the transaction value (Float)
1270
+ attr_accessor :percentage
1271
+
1272
+ # The total fee (Money)
1273
+ attr_accessor :total
1274
+
1275
+ def self.create_from_element(element)
1276
+ result = ChargeFee.new
1277
+ result.flat = Money.new(element.elements['flat'].text.to_f * 100, nil)
1278
+ result.percentage = element.elements['percentage'].text.to_f
1279
+ result.total = Money.new(element.elements['total'].text.to_f * 100, nil)
1280
+ result
1281
+ end
1282
+ end
1283
+
1264
1284
  # financial_state
1265
1285
  # REVIEWING - Google Checkout is reviewing the order.
1266
1286
  # CHARGEABLE - The order is ready to be charged.
@@ -57,6 +57,7 @@ module Google4R #:nodoc:
57
57
  # The list of command tag names
58
58
  COMMAND_TO_TAG =
59
59
  {
60
+ ChargeAndShipOrderCommand => "charge-and-ship-order",
60
61
  ChargeOrderCommand => 'charge-order',
61
62
  RefundOrderCommand => 'refund-order',
62
63
  CancelOrderCommand => 'cancel-order',
@@ -618,6 +619,33 @@ module Google4R #:nodoc:
618
619
  amount_element.add_attribute('currency', money.currency.to_s)
619
620
  end
620
621
  end
622
+
623
+ class ChargeAndShipOrderCommandXmlGenerator < CommandXmlGenerator
624
+
625
+ protected
626
+
627
+ def process_command(command)
628
+ root = super
629
+ process_money(root, command.amount) if command.amount
630
+ process_tracking_data(root, command.carrier, command.tracking_number)
631
+ root.add_element('send-email').text = command.send_email.to_s if command.send_email
632
+ end
633
+
634
+ def process_money(parent, money)
635
+ amount_element = parent.add_element('amount')
636
+ amount_element.text = money.to_s
637
+ amount_element.add_attribute('currency', money.currency.to_s)
638
+ end
639
+
640
+ def process_tracking_data(parent, carrier, tracking_number)
641
+ if carrier and tracking_number then
642
+ e1 = parent.add_element('tracking-data-list')
643
+ e2 = e1.add_element('tracking-data')
644
+ e2.add_element('carrier').text = carrier
645
+ e2.add_element('tracking-number').text = tracking_number
646
+ end
647
+ end
648
+ end
621
649
 
622
650
  class RefundOrderCommandXmlGenerator < CommandXmlGenerator
623
651
 
@@ -46,6 +46,11 @@ class Google4R::Checkout::ChargeAmountNotificationTest < Test::Unit::TestCase
46
46
  <google-order-number>722226456784742</google-order-number>
47
47
  <latest-charge-amount currency="GBP">1.23</latest-charge-amount>
48
48
  <total-charge-amount currency="GBP">9.99</total-charge-amount>
49
+ <latest-charge-fee>
50
+ <total>1.21</total>
51
+ <flat>0.2</flat>
52
+ <percentage>3.4</percentage>
53
+ </latest-charge-fee>
49
54
  </charge-amount-notification>
50
55
  }
51
56
  end
@@ -60,5 +65,8 @@ class Google4R::Checkout::ChargeAmountNotificationTest < Test::Unit::TestCase
60
65
  assert_equal Time.parse('2007-05-06T18:41:21.000Z'), notification.timestamp
61
66
  assert_equal(Money.new(999, 'GBP'), notification.total_charge_amount)
62
67
  assert_equal(Money.new(123, 'GBP'), notification.latest_charge_amount)
68
+ assert_equal(Money.new(20, nil), notification.latest_charge_fee.flat)
69
+ assert_equal(3.4, notification.latest_charge_fee.percentage)
70
+ assert_equal(Money.new(121, nil), notification.latest_charge_fee.total)
63
71
  end
64
72
  end
@@ -0,0 +1,69 @@
1
+ #--
2
+ # Project: google_checkout4r
3
+ # File: test/unit/charge_order_command_test.rb
4
+ # Author: George Palmer <george.palmer at gmail dot com>
5
+ # Copyright: (c) 2010 by George Palmer
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::ChargeAndShipOrderCommandTest < Test::Unit::TestCase
36
+ include Google4R::Checkout
37
+
38
+ def setup
39
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
40
+ @command = @frontend.create_charge_and_ship_order_command
41
+ @command.google_order_number = '1234-5678-ABCD-1234'
42
+ @command.amount = Money.new(1000, 'GBP')
43
+ end
44
+
45
+ def test_behaves_correctly
46
+ [ :google_order_number, :amount, :send_email, :carrier, :tracking_number ].each do |symbol|
47
+ assert_respond_to @command, symbol
48
+ end
49
+ end
50
+
51
+ def test_xml_without_amount
52
+ @command.amount = nil
53
+ assert_no_command_element_exists("amount", @command)
54
+ end
55
+
56
+ def test_accessors
57
+ assert_equal('1234-5678-ABCD-1234', @command.google_order_number)
58
+ assert_equal(Money.new(1000, 'GBP'), @command.amount)
59
+ end
60
+
61
+ def test_xml_generation
62
+ assert_command_element_text_equals("10.00", "> amount[currency=GBP]", @command)
63
+ end
64
+
65
+ def test_to_xml_does_not_raise_exception
66
+ assert_nothing_raised { @command.to_xml }
67
+ end
68
+
69
+ end
@@ -0,0 +1,53 @@
1
+ require 'google4r/checkout'
2
+
3
+ require 'test/frontend_configuration'
4
+ #--
5
+ # Project: google_checkout4r
6
+ # File: test/unit/tracking_data_test.rb
7
+ # Author: George Palmer <george.palmer at gmail dot com>
8
+ # Copyright: (c) 2007 by George Palmer
9
+ # License: MIT License as follows:
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining
12
+ # a copy of this software and associated documentation files (the
13
+ # "Software"), to deal in the Software without restriction, including
14
+ # without limitation the rights to use, copy, modify, merge, publish,
15
+ # distribute, sublicense, and/or sell copies of the Software, and to permit
16
+ # persons to whom the Software is furnished to do so, subject to the
17
+ # following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included
20
+ # in all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28
+ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ #++
30
+
31
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
32
+
33
+ require 'google4r/checkout'
34
+
35
+ require 'test/frontend_configuration'
36
+
37
+ # Test for the class TrackingData.
38
+ class Google4R::Checkout::ChargeFeeTest < Test::Unit::TestCase
39
+ include Google4R::Checkout
40
+
41
+ def setup
42
+ @charge_fee = ChargeFee.new
43
+ @charge_fee.flat = 0.5
44
+ @charge_fee.percentage = 5.0
45
+ @charge_fee.total = 12.10
46
+ end
47
+
48
+ def test_responds_correctly
49
+ [ :flat, :percentage, :total].each do |sym|
50
+ assert_respond_to @charge_fee, sym
51
+ end
52
+ end
53
+ end
@@ -46,6 +46,7 @@ class Google4R::Checkout::RefundAmountNotificationTest < Test::Unit::TestCase
46
46
  <google-order-number>841171949013218</google-order-number>
47
47
  <latest-refund-amount currency="GBP">226.06</latest-refund-amount>
48
48
  <total-refund-amount currency="GBP">226.06</total-refund-amount>
49
+ <latest-fee-refund-amount>5.04</latest-fee-refund-amount>
49
50
  <timestamp>2006-03-18T20:25:31</timestamp>
50
51
  </refund-amount-notification>
51
52
  }
@@ -61,5 +62,6 @@ class Google4R::Checkout::RefundAmountNotificationTest < Test::Unit::TestCase
61
62
  assert_equal Time.parse('2006-03-18T20:25:31'), notification.timestamp
62
63
  assert_equal(Money.new(22606, 'GBP'), notification.total_refund_amount)
63
64
  assert_equal(Money.new(22606, 'GBP'), notification.latest_refund_amount)
65
+ assert_equal(Money.new(504, nil), notification.latest_fee_refund_amount)
64
66
  end
65
67
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google4r-checkout
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1848230121
4
+ hash: -1848230124
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - beta3
10
- version: 1.1.beta3
9
+ - beta4
10
+ version: 1.1.beta4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Chan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-28 00:00:00 -04:00
18
+ date: 2010-07-09 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -69,6 +69,8 @@ files:
69
69
  - test/unit/cancel_order_command_test.rb
70
70
  - test/unit/carrier_calculated_shipping_test.rb
71
71
  - test/unit/charge_amount_notification_test.rb
72
+ - test/unit/charge_and_ship_order_command_test.rb
73
+ - test/unit/charge_fee_test.rb
72
74
  - test/unit/charge_order_command_test.rb
73
75
  - test/unit/chargeback_amount_notification_test.rb
74
76
  - test/unit/checkout_command_test.rb
@@ -173,6 +175,8 @@ test_files:
173
175
  - test/unit/cancel_order_command_test.rb
174
176
  - test/unit/carrier_calculated_shipping_test.rb
175
177
  - test/unit/charge_amount_notification_test.rb
178
+ - test/unit/charge_and_ship_order_command_test.rb
179
+ - test/unit/charge_fee_test.rb
176
180
  - test/unit/charge_order_command_test.rb
177
181
  - test/unit/chargeback_amount_notification_test.rb
178
182
  - test/unit/checkout_command_test.rb