Class: Google4R::Checkout::ShippingAdjustment
- Inherits:
-
Object
- Object
- Google4R::Checkout::ShippingAdjustment
- Defined in:
- lib/google4r/checkout/notifications.rb
Overview
ShippingAdjustments represent the chosen shipping method.
Constant Summary collapse
- MERCHANT_CALCULATED =
"MERCHANT_CALCULATED".freeze
- FLAT_RATE =
"FLAT_RATE".freeze
- PICKUP =
"PICKUP".freeze
Instance Attribute Summary collapse
-
#cost ⇒ Object
The cost of the selected shipping (Money).
-
#name ⇒ Object
The name of the shipping adjustment.
-
#type ⇒ Object
The type of the shipping adjustment, one of MERCHANT_CALCULATED, FLAT_RATE PICKUP.
Class Method Summary collapse
-
.create_from_element(element) ⇒ Object
Creates a new ShippingAdjustment object from a REXML::Element object.
Instance Attribute Details
#cost ⇒ Object
The cost of the selected shipping (Money).
409 410 411 |
# File 'lib/google4r/checkout/notifications.rb', line 409 def cost @cost end |
#name ⇒ Object
The name of the shipping adjustment.
406 407 408 |
# File 'lib/google4r/checkout/notifications.rb', line 406 def name @name end |
#type ⇒ Object
The type of the shipping adjustment, one of MERCHANT_CALCULATED, FLAT_RATE PICKUP.
403 404 405 |
# File 'lib/google4r/checkout/notifications.rb', line 403 def type @type end |
Class Method Details
.create_from_element(element) ⇒ Object
Creates a new ShippingAdjustment object from a REXML::Element object.
Can raise a RuntimeException if the given Element is invalid.
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/google4r/checkout/notifications.rb', line 414 def self.create_from_element(element) result = ShippingAdjustment.new hash = Hash.new hash[:type] = case element.name when 'flat-rate-shipping-adjustment' then FLAT_RATE when 'pickup-shipping-adjustment' then PICKUP when 'merchant-calculated-shipping-adjustment' then MERCHANT_CALCULATED else raise "Unexpected shipping adjustment '#{element.name}'" end hash[:name] = element.elements['shipping-name'].text hash[:cost] = (element.elements['shipping-cost'].text.to_f * 100).to_i # TODO: this will break for currencies where 100c != 1d hash[:cost_currency] = element.elements['shipping-cost/@currency'].value result.type = hash[:type] result.name = hash[:name] result.cost = Money.new(hash[:cost], hash[:cost_currency]) return result end |