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 (and later NotificationHandler) objects.

Example

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

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

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 those objects 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.

 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 = Frontend.new
frontend.tax_table_factory = TaxTableFactory.new

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.



79
80
81
82
83
84
85
# File 'lib/google4r/checkout/frontend.rb', line 79

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.



71
72
73
# File 'lib/google4r/checkout/frontend.rb', line 71

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.



75
76
77
# File 'lib/google4r/checkout/frontend.rb', line 75

def tax_table_factory
  @tax_table_factory
end

Instance Method Details

#create_checkout_commandObject

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



89
90
91
# File 'lib/google4r/checkout/frontend.rb', line 89

def create_checkout_command
  return CheckoutCommand.new(self)
end

#create_notification_handlerObject

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



95
96
97
# File 'lib/google4r/checkout/frontend.rb', line 95

def create_notification_handler
  return NotificationHandler.new(self)
end