Class: Google4R::Checkout::MerchantCalculationCallback

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

Overview

Google Checkout send a <merchant-calculation-callback> message to you when any of the events occur:

The customer signs in to Google Checkout.
The customer enters a new shipping address on the Place Order page.
The customer enters a coupon or gift certificate code.

The message will be parsed into a MerchantCalculationCallback instance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frontend) ⇒ MerchantCalculationCallback

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



130
131
132
133
134
135
136
137
138
# File 'lib/google4r/checkout/merchant_calculation.rb', line 130

def initialize(frontend)
  @frontend = frontend
  @anonymous_addresses = Array.new
  @shipping_methods = Array.new
  @merchant_code_strings = Array.new
  if frontend.tax_table_factory
    @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.now)
  end
end

Instance Attribute Details

#anonymous_addressesObject (readonly)

An array of AnonymousAddress objects of this callback.



115
116
117
# File 'lib/google4r/checkout/merchant_calculation.rb', line 115

def anonymous_addresses
  @anonymous_addresses
end

#buyer_languageObject

The buyer’s language



112
113
114
# File 'lib/google4r/checkout/merchant_calculation.rb', line 112

def buyer_language
  @buyer_language
end

#frontendObject

The frontend this callback belongs to.



106
107
108
# File 'lib/google4r/checkout/merchant_calculation.rb', line 106

def frontend
  @frontend
end

#merchant_code_stringsObject (readonly)

An array of merchant codes



124
125
126
# File 'lib/google4r/checkout/merchant_calculation.rb', line 124

def merchant_code_strings
  @merchant_code_strings
end

#shipping_methodsObject (readonly)

An array of shipping method names



121
122
123
# File 'lib/google4r/checkout/merchant_calculation.rb', line 121

def shipping_methods
  @shipping_methods
end

#shopping_cartObject

The order’s shopping cart (ShoppingCart)



109
110
111
# File 'lib/google4r/checkout/merchant_calculation.rb', line 109

def shopping_cart
  @shopping_cart
end

#taxObject

This indicates whether the merchant needs to calculate taxes for the order.



118
119
120
# File 'lib/google4r/checkout/merchant_calculation.rb', line 118

def tax
  @tax
end

#tax_tablesObject (readonly)

The tax tables for the items in the order notification.



127
128
129
# File 'lib/google4r/checkout/merchant_calculation.rb', line 127

def tax_tables
  @tax_tables
end

Class Method Details

.create_from_element(element, frontend) ⇒ Object

Factory method to create a new MerchantCalculationCallback 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 callback belongs to.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/google4r/checkout/merchant_calculation.rb', line 147

def self.create_from_element(element, frontend)
  result = MerchantCalculationCallback.new(frontend)
  
  result.shopping_cart = ShoppingCart.create_from_element(element.elements['shopping-cart'], result)
  result.buyer_language = element.elements['buyer-language'].text
  element.elements.each('calculate/addresses/anonymous-address') do |address_element|
    result.anonymous_addresses << AnonymousAddress.create_from_element(address_element)
  end
  result.tax = element.elements['calculate/tax'].text
  element.elements.each('calculate/shipping/method') do |shipping_method_element|
    result.shipping_methods << shipping_method_element.attributes['name']
  end
  element.elements.each('calculate/merchant-code-strings/merchant-code-string') do |merchant_code_string_element|
    result.merchant_code_strings << merchant_code_string_element.attributes['code']
  end
  
  return result
end