Class: Google4R::Checkout::Frontend
- Inherits:
-
Object
- Object
- Google4R::Checkout::Frontend
- 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
-
#configuration ⇒ Object
readonly
The configuration for this Frontend class.
-
#tax_table_factory ⇒ Object
An object with a factory method that can create the effective TaxTable objects that were valid at a given point of time.
Instance Method Summary collapse
-
#create_add_merchant_order_number_command ⇒ Object
Factory method to create a new AddMerchantOrderNumberCommand object.
-
#create_add_tracking_data_command ⇒ Object
Factory method to create a new AddTrackingDataCommand object.
-
#create_archive_order_command ⇒ Object
Factory method to create a new ArchiveOrderCommand object.
-
#create_authorize_order_command ⇒ Object
Factory method to create a new AuthorizeOrderCommand object.
-
#create_backorder_items_command ⇒ Object
Factory method to create a new BackorderItemsCommand object.
-
#create_callback_handler ⇒ Object
Factory method that creates a new CallbackHandler object.
-
#create_cancel_items_command ⇒ Object
Factory method to create a new CancelItemsCommand object.
-
#create_cancel_order_command ⇒ Object
Factory method to create a new CancelOrderCommand object.
-
#create_charge_order_command ⇒ Object
Factory method to create a new ChargeOrderCommand object.
-
#create_checkout_command ⇒ Object
Factory method that creates a new CheckoutCommand object.
-
#create_deliver_order_command ⇒ Object
Factory method to create a new DeliverOrderCommand object.
-
#create_notification_handler ⇒ Object
Factory method that creates a new NotificationHandler object.
-
#create_refund_order_command ⇒ Object
Factory method to create a new RefundOrderCommand object.
-
#create_reset_items_shipping_information_command ⇒ Object
Factory method to create a new ResetItemsShippingInformationCommand object.
-
#create_return_items_command ⇒ Object
Factory method to create a new ReturnItemsCommand object.
-
#create_send_buyer_message_command ⇒ Object
Factory method to create a new SendBuyerMessageCommand object.
-
#create_ship_items_command ⇒ Object
Factory method to create a new ShipItemsCommand object.
-
#create_unarchive_order_command ⇒ Object
Factory method to create a new UnarchiveOrderCommand object.
-
#initialize(configuration) ⇒ Frontend
constructor
Creates a new Frontend instance and sets the configuration attribute to the parameter configuration.
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
#configuration ⇒ Object (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_factory ⇒ Object
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_command ⇒ Object
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_command ⇒ Object
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_command ⇒ Object
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_command ⇒ Object
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 return AuthorizeOrderCommand.new(self) end |
#create_backorder_items_command ⇒ Object
Factory method to create a new BackorderItemsCommand object. Use this method to create your BackorderItemsCommand instances.
181 182 183 |
# File 'lib/google4r/checkout/frontend.rb', line 181 def create_backorder_items_command return BackorderItemsCommand.new(self) end |
#create_callback_handler ⇒ Object
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_command ⇒ Object
Factory method to create a new CancelItemsCommand object. Use this method to create your CancelItemsCommand instances.
193 194 195 |
# File 'lib/google4r/checkout/frontend.rb', line 193 def create_cancel_items_command return CancelItemsCommand.new(self) end |
#create_cancel_order_command ⇒ Object
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_command ⇒ Object
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_command ⇒ Object
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_deliver_order_command ⇒ Object
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_handler ⇒ Object
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_command ⇒ Object
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_command ⇒ Object
Factory method to create a new ResetItemsShippingInformationCommand object. Use this method to create your ResetItemsShippingInformationCommand instances.
199 200 201 |
# File 'lib/google4r/checkout/frontend.rb', line 199 def create_reset_items_shipping_information_command return ResetItemsShippingInformationCommand.new(self) end |
#create_return_items_command ⇒ Object
Factory method to create a new ReturnItemsCommand object. Use this method to create your ReturnItemsCommand instances.
187 188 189 |
# File 'lib/google4r/checkout/frontend.rb', line 187 def create_return_items_command return ReturnItemsCommand.new(self) end |
#create_send_buyer_message_command ⇒ Object
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 return SendBuyerMessageCommand.new(self) end |
#create_ship_items_command ⇒ Object
Factory method to create a new ShipItemsCommand object. Use this method to create your ShipItemsCommand instances.
175 176 177 |
# File 'lib/google4r/checkout/frontend.rb', line 175 def create_ship_items_command return ShipItemsCommand.new(self) end |
#create_unarchive_order_command ⇒ Object
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 |