Class: Google4R::Checkout::NewOrderNotification

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

Overview

Google Checkout sends <new-order-notification> messages to the web service when a new order has been successfully filed with Google Checkout. These messages will be parsed into NewOrderNotification instances.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frontend) ⇒ NewOrderNotification

Sets the frontend attribute to the value of the frontend parameter.



146
147
148
# File 'lib/google4r/checkout/notifications.rb', line 146

def initialize(frontend)
  @frontend = frontend
end

Instance Attribute Details

#buyer_billing_addressObject

The buyer’s billing address (Address).



102
103
104
# File 'lib/google4r/checkout/notifications.rb', line 102

def buyer_billing_address
  @buyer_billing_address
end

#buyer_idObject

The buyer’s ID from Google Checkout (String).



108
109
110
# File 'lib/google4r/checkout/notifications.rb', line 108

def buyer_id
  @buyer_id
end

#buyer_shipping_addressObject

The buyer’s shipping adress (Address).



105
106
107
# File 'lib/google4r/checkout/notifications.rb', line 105

def buyer_shipping_address
  @buyer_shipping_address
end

#financial_order_stateObject

The order’s financial order state (String, one of FinancialOrderState::*).



114
115
116
# File 'lib/google4r/checkout/notifications.rb', line 114

def financial_order_state
  @financial_order_state
end

#frontendObject

The frontend this notification belongs to.



93
94
95
# File 'lib/google4r/checkout/notifications.rb', line 93

def frontend
  @frontend
end

#fulfillment_order_stateObject

The order’s fulfillment state (String, one of FulfillmentOrderState::*).



117
118
119
# File 'lib/google4r/checkout/notifications.rb', line 117

def fulfillment_order_state
  @fulfillment_order_state
end

#google_order_numberObject

The order’s number at Google Checkout (String).



99
100
101
# File 'lib/google4r/checkout/notifications.rb', line 99

def google_order_number
  @google_order_number
end

#marketing_preferencesObject

The buyer’s marketing preferences (MarketingPreferences).



111
112
113
# File 'lib/google4r/checkout/notifications.rb', line 111

def marketing_preferences
  @marketing_preferences
end

#order_adjustmentObject

The order’s total adjustment (OrderAdjustment).



123
124
125
# File 'lib/google4r/checkout/notifications.rb', line 123

def order_adjustment
  @order_adjustment
end

#order_totalObject

The order’s total amount (Money).



126
127
128
# File 'lib/google4r/checkout/notifications.rb', line 126

def order_total
  @order_total
end

#serial_numberObject

The serial number of the new order notification (String).



96
97
98
# File 'lib/google4r/checkout/notifications.rb', line 96

def serial_number
  @serial_number
end

#shopping_cartObject

The order’s shopping cart (ShoppingCart)



129
130
131
# File 'lib/google4r/checkout/notifications.rb', line 129

def shopping_cart
  @shopping_cart
end

#tax_tablesObject (readonly)

The tax tables for the items in the order notification.



143
144
145
# File 'lib/google4r/checkout/notifications.rb', line 143

def tax_tables
  @tax_tables
end

#timestampObject

The order’s timestamp (Time), also see #timestamp=



132
133
134
# File 'lib/google4r/checkout/notifications.rb', line 132

def timestamp
  @timestamp
end

Class Method Details

.create_from_element(element, frontend) ⇒ Object

Factory method to create a new CheckoutNotification object from the REXML:Element object

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

You have to pass in the Frontend class this notification belongs to.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/google4r/checkout/notifications.rb', line 156

def self.create_from_element(element, frontend)
  result = NewOrderNotification.new(frontend)
  
  result.timestamp = Time.parse(element.elements['timestamp'].text)
  result.serial_number = element.elements['@serial-number'].value
  result.google_order_number = element.elements['google-order-number'].text
  result.buyer_billing_address = Address.create_from_element(element.elements['buyer-billing-address'])
  result.buyer_shipping_address = Address.create_from_element(element.elements['buyer-shipping-address'])
  result.buyer_id = element.elements['buyer-id'].text
  result.marketing_preferences = MarketingPreferences.create_from_element(element.elements['buyer-marketing-preferences'])
  result.financial_order_state = element.elements['financial-order-state'].text
  result.fulfillment_order_state = element.elements['fulfillment-order-state'].text
  result.order_adjustment = OrderAdjustment.create_from_element(element.elements['order-adjustment'])
  result.shopping_cart = ShoppingCart.create_from_element(element.elements['shopping-cart'], result)

  amount = (element.elements['order-total'].text.to_f * 100).to_i rescue nil # TODO: this will break for currencies where 100c != 1d
  currency = element.elements['order-total/@currency'].value rescue nil
  result.order_total = Money.new(amount, currency)
  
  return result
end