Class: Google4R::Checkout::OrderAdjustment
- Inherits:
-
Object
- Object
- Google4R::Checkout::OrderAdjustment
- Defined in:
- lib/google4r/checkout/notifications.rb
Overview
OrderAdjustment objects contain the adjustments (i.e. the entities in the cart that represent positive and negative amounts (at the moment Google Checkout support coupons, gift certificates and shipping)).
Instance Attribute Summary collapse
-
#adjustment_total ⇒ Object
The <adjustment-total> tag contains the total adjustment to an order total based on tax, shipping, gift certificates and coupon codes (optional).
-
#merchant_calculation_successful ⇒ Object
Boolean, true iff the merchant calculations have been successful (optional).
-
#merchant_codes ⇒ Object
Array of MerchantCode objects.
-
#shipping ⇒ Object
The chosen ShippingAdjustment object for this order.
-
#total_tax ⇒ Object
The total amount of tax that has been paid for this order (Money, optional).
Class Method Summary collapse
-
.create_from_element(element) ⇒ Object
Creates a new OrderAdjustment from a given REXML::Element object.
Instance Attribute Details
#adjustment_total ⇒ Object
The <adjustment-total> tag contains the total adjustment to an order total based on tax, shipping, gift certificates and coupon codes (optional).
447 448 449 |
# File 'lib/google4r/checkout/notifications.rb', line 447 def adjustment_total @adjustment_total end |
#merchant_calculation_successful ⇒ Object
Boolean, true iff the merchant calculations have been successful (optional).
450 451 452 |
# File 'lib/google4r/checkout/notifications.rb', line 450 def merchant_calculation_successful @merchant_calculation_successful end |
#merchant_codes ⇒ Object
Array of MerchantCode objects.
453 454 455 |
# File 'lib/google4r/checkout/notifications.rb', line 453 def merchant_codes @merchant_codes end |
#shipping ⇒ Object
The chosen ShippingAdjustment object for this order.
456 457 458 |
# File 'lib/google4r/checkout/notifications.rb', line 456 def shipping @shipping end |
#total_tax ⇒ Object
The total amount of tax that has been paid for this order (Money, optional).
459 460 461 |
# File 'lib/google4r/checkout/notifications.rb', line 459 def total_tax @total_tax end |
Class Method Details
.create_from_element(element) ⇒ Object
Creates a new OrderAdjustment from a given REXML::Element object.
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/google4r/checkout/notifications.rb', line 462 def self.create_from_element(element) result = OrderAdjustment.new hash = Hash.new hash[:total_tax] = (element.elements['total-tax'].text.to_f * 100).to_i rescue nil # TODO: this will break for currencies where 100c != 1d hash[:total_tax_currency] = element.elements['total-tax/@currency'].value rescue nil shipping_element = element.elements["shipping/*"] hash[:shipping] = ShippingAdjustment.create_from_element(shipping_element) hash[:merchant_codes] = Array.new element.elements.each(%q{merchant-codes/*}) do |code_elem| hash[:merchant_codes] << MerchantCode.create_from_element(code_elem) end hash[:merchant_calculation_successful] = (element.elements['merchant-calculation-successful'].text.downcase == 'true') rescue nil hash[:adjustment_total] = (element.elements['adjustment-total'].text.to_f * 100).to_i rescue nil # TODO: this will break for currencies where 100c != 1d hash[:adjustment_total_currency] = element.elements['adjustment-total/@currency'].value rescue nil result.total_tax = Money.new(hash[:total_tax], hash[:total_tax_currency]) unless hash[:total_tax].nil? result.adjustment_total = Money.new(hash[:adjustment_total], hash[:adjustment_total_currency]) unless hash[:adjustment_total].nil? result.merchant_codes = hash[:merchant_codes] # no unless since the Array is initialized result.merchant_calculation_successful = hash[:merchant_calculation_successful] result.shipping = hash[:shipping] return result end |