Class: Google4R::Checkout::Frontend

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

Overview

The Frontend class is the factory that is to be used to create the Command, NotificationHandler and CallbackHandler objects.

Example

configuration = { :merchant_id => '123456789', :merchant_key => '12345abcd' }

frontend = Google4R::Checkout::Frontend.new(configuration)

Tax Table Factory

You have to set the tax_table_factory attribute of every Frontend object before you can call #create_checkout_command or #create_notification_handler because the objects created by those methods require tax tables.

The Tax Table Factory must provide the method "effective_tax_tables_at" accept a Time object and provide a method that returns an Array of TaxTable object that describe the effective tax rules at the given point of time.

Effectively, this means you have to implement the Temporal Property pattern as described here: http://www.martinfowler.com/ap2/temporalProperty.html.

Example

class TaxTableFactory
def effective_tax_tables_at(time)
  if time < Time.parse("Wed Apr 09 08:56:03 CDT 2003") then
    table1, table2 = TaxTable.new, TaxTable.new
    # ... set rules
    [ table1, table 2]
  else
    table3, table4 = TaxTable.new, TaxTable.new
    # ... set rules
    [ table3, table 4]
  end
end
end

frontend = Google4R::Checkout::Frontend.new(configuration)
frontend.tax_table_factory = TaxTableFactory.new

checkout_command = frontend.create_checkout_command
# ...
handler = frontend.create_notification_handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Frontend

Creates a new Frontend instance and sets the configuration attribute to the parameter configuration.



87
88
89
90
91
92
93
# File 'lib/google4r/checkout/frontend.rb', line 87

def initialize(configuration)
  raise "Missing configuration setting: merchant_id"  if configuration[:merchant_id].nil?
  raise "Missing configuration setting: merchant_key" if configuration[:merchant_key].nil?
  raise "Missing configuration setting: use_sandbox"  if configuration[:use_sandbox].nil?
  
  @configuration = configuration.dup.freeze
end

Instance Attribute Details

#configurationObject (readonly)

The configuration for this Frontend class. It will be used by all classes created by this Frontend instance (Hash).



79
80
81
# File 'lib/google4r/checkout/frontend.rb', line 79

def configuration
  @configuration
end

#tax_table_factoryObject

An object with a factory method that can create the effective TaxTable objects that were valid at a given point of time.



83
84
85
# File 'lib/google4r/checkout/frontend.rb', line 83

def tax_table_factory
  @tax_table_factory
end

Instance Method Details

#create_add_merchant_order_number_commandObject

Factory method to create a new AddMerchantOrderNumberCommand object. Use this method to create your AddMerchantOrderNumberCommand instances.



151
152
153
# File 'lib/google4r/checkout/frontend.rb', line 151

def create_add_merchant_order_number_command
  return AddMerchantOrderNumberCommand.new(self)
end

#create_add_tracking_data_commandObject

Factory method to create a new AddTrackingDataCommand object. Use this method to create your AddTrackingDataCommand instances.



157
158
159
# File 'lib/google4r/checkout/frontend.rb', line 157

def create_add_tracking_data_command
  return AddTrackingDataCommand.new(self)
end

#create_archive_order_commandObject

Factory method to create a new ArchiveOrderCommand object. Use this method to create your ArchiveOrderCommand instances.



163
164
165
# File 'lib/google4r/checkout/frontend.rb', line 163

def create_archive_order_command
  return ArchiveOrderCommand.new(self)
end

#create_authorize_order_commandObject

Factory method to create a new AuthorizeOrderCommand object. Use this method to create your AuthorizeOrderCommand instances.



145
146
147
# File 'lib/google4r/checkout/frontend.rb', line 145

def create_authorize_order_command
  return AuthorizeOrderCommand.new(self)
end

#create_backorder_items_commandObject

Factory method to create a new BackorderItemsCommand object. Use this method to create your BackorderItemsCommand instances.



187
188
189
# File 'lib/google4r/checkout/frontend.rb', line 187

def create_backorder_items_command
  return BackorderItemsCommand.new(self)
end

#create_callback_handlerObject

Factory method that creates a new CallbackHandler object. Use this method to create your CallbackHandler instances.



103
104
105
# File 'lib/google4r/checkout/frontend.rb', line 103

def create_callback_handler
  return CallbackHandler.new(self)
end

#create_cancel_items_commandObject

Factory method to create a new CancelItemsCommand object. Use this method to create your CancelItemsCommand instances.



199
200
201
# File 'lib/google4r/checkout/frontend.rb', line 199

def create_cancel_items_command
  return CancelItemsCommand.new(self)
end

#create_cancel_order_commandObject

Factory method to create a new CancelOrderCommand object. Use this method to create your CancelOrderCommand instances.



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

def create_cancel_order_command
  return CancelOrderCommand.new(self)
end

#create_charge_order_commandObject

Factory method to create a new ChargeOrderCommand object. Use this method to create your ChargeOrderCommand instances.



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

def create_charge_order_command
  return ChargeOrderCommand.new(self)
end

#create_checkout_commandObject

Factory method that creates a new CheckoutCommand object. Use this method to create your CheckoutCommand instances.



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

def create_checkout_command
  return CheckoutCommand.new(self)
end

#create_create_order_recurrence_request_commandObject

Factory method to create a new CreateOrderRecurrenceRequestCommand object. Use this method to create your CreateOrderRecurrenceRequestCommand instances.



175
176
177
# File 'lib/google4r/checkout/frontend.rb', line 175

def create_create_order_recurrence_request_command
  return CreateOrderRecurrenceRequestCommand.new(self)
end

#create_deliver_order_commandObject

Factory method to create a new DeliverOrderCommand object. Use this method to create your DeliverOrderCommand instances.



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

def create_deliver_order_command
  return DeliverOrderCommand.new(self)
end

#create_notification_handlerObject

Factory method that creates a new NotificationHandler object. Use this method to create your NotificationHandler instances.



97
98
99
# File 'lib/google4r/checkout/frontend.rb', line 97

def create_notification_handler
  return NotificationHandler.new(self)
end

#create_refund_order_commandObject

Factory method to create a new RefundOrderCommand object. Use this method to create your RefundOrderCommand instances.



133
134
135
# File 'lib/google4r/checkout/frontend.rb', line 133

def create_refund_order_command
  return RefundOrderCommand.new(self)
end

#create_reset_items_shipping_information_commandObject

Factory method to create a new ResetItemsShippingInformationCommand object. Use this method to create your ResetItemsShippingInformationCommand instances.



205
206
207
# File 'lib/google4r/checkout/frontend.rb', line 205

def create_reset_items_shipping_information_command
  return ResetItemsShippingInformationCommand.new(self)
end

#create_return_items_commandObject

Factory method to create a new ReturnItemsCommand object. Use this method to create your ReturnItemsCommand instances.



193
194
195
# File 'lib/google4r/checkout/frontend.rb', line 193

def create_return_items_command
  return ReturnItemsCommand.new(self)
end

#create_send_buyer_message_commandObject

Factory method to create a new SendBuyerMessageCommand object. Use this method to create your SendBuyerMessageCommand instances.



139
140
141
# File 'lib/google4r/checkout/frontend.rb', line 139

def create_send_buyer_message_command
  return SendBuyerMessageCommand.new(self)
end

#create_ship_items_commandObject

Factory method to create a new ShipItemsCommand object. Use this method to create your ShipItemsCommand instances.



181
182
183
# File 'lib/google4r/checkout/frontend.rb', line 181

def create_ship_items_command
  return ShipItemsCommand.new(self)
end

#create_unarchive_order_commandObject

Factory method to create a new UnarchiveOrderCommand object. Use this method to create your UnarchiveOrderCommand instances.



169
170
171
# File 'lib/google4r/checkout/frontend.rb', line 169

def create_unarchive_order_command
  return UnarchiveOrderCommand.new(self)
end