Class: Google4R::Checkout::ChargeAmountNotification

Inherits:
Notification
  • Object
show all
Defined in:
lib/google4r/checkout/notifications.rb

Overview

Google Checkout sends <charge-amount-notification> messages to the web service when the to confirm that the charge was successfully executed.

Instance Attribute Summary collapse

Attributes inherited from Notification

#frontend, #google_order_number, #serial_number, #timestamp

Class Method Summary collapse

Methods inherited from Notification

#initialize

Constructor Details

This class inherits a constructor from Google4R::Checkout::Notification

Instance Attribute Details

#latest_charge_amountObject

The amount most recently charged for an order (Money)



305
306
307
# File 'lib/google4r/checkout/notifications.rb', line 305

def latest_charge_amount
  @latest_charge_amount
end

#latest_charge_feeObject

Returns the value of attribute latest_charge_fee.



310
311
312
# File 'lib/google4r/checkout/notifications.rb', line 310

def latest_charge_fee
  @latest_charge_fee
end

#total_charge_amountObject

The total amount charged for an order (Money)



308
309
310
# File 'lib/google4r/checkout/notifications.rb', line 308

def total_charge_amount
  @total_charge_amount
end

Class Method Details

.create_from_element(element, frontend) ⇒ Object

Factory method that creates a new ChargeAmountNotification from an REXML::Element instance. Use this to create instances of ChargeAmountNotification.

Raises NoMethodError and RuntimeError exceptions if the given element misses required elements.



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/google4r/checkout/notifications.rb', line 317

def self.create_from_element(element, frontend)
  charge = ChargeAmountNotification.new(frontend)
  
  charge.serial_number = element.attributes['serial-number']
  charge.google_order_number = element.elements['google-order-number'].text        
  
  currency = element.elements['latest-charge-amount'].attributes['currency'] 
  amount = (BigDecimal.new(element.elements['latest-charge-amount'].text)*100).to_i
  charge.latest_charge_amount = Money.new(amount, currency)
  
  currency = element.elements['total-charge-amount'].attributes['currency']
  amount = (BigDecimal.new(element.elements['total-charge-amount'].text)*100).to_i
  charge.total_charge_amount = Money.new(amount, currency)  
  
  if element.elements["latest-charge-fee"]
    charge.latest_charge_fee = ChargeFee.create_from_element(element.elements["latest-charge-fee"])
  end
  
  charge.timestamp = Time.parse(element.elements['timestamp'].text)

  return charge
end