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)
Donations
If you are processing orders for a Google-verified 501©(3) or 510©(6) nonprofit, you can collect donations instead of orders. To do so, specify the :purchase_type option as :donation.
configuration = { :merchant_id => '123456789', :merchant_key => '12345abcd',
:purchase_type => :donation }
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: 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_and_ship_order_command ⇒ Object
Factory method to create a new ChargeAndShipOrderCommand 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_create_order_recurrence_request_command ⇒ Object
Factory method to create a new CreateOrderRecurrenceRequestCommand object.
-
#create_deliver_order_command ⇒ Object
Factory method to create a new DeliverOrderCommand object.
- #create_notification_data_request_command(continue_token) ⇒ Object
- #create_notification_data_token_request_command(options = {}) ⇒ Object
-
#create_notification_handler ⇒ Object
Factory method that creates a new NotificationHandler object.
- #create_notification_history_request_command(serial_number) ⇒ Object
-
#create_order_report_command(start_date, end_date) ⇒ Object
Factory method that creates a new OrderReportCommand 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.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/google4r/checkout/frontend.rb', line 98 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[:purchase_type] ||= :order raise "Invalid configuration setting: purchase_type" unless[:donation, :order].include?(configuration[:purchase_type]) @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).
90 91 92 |
# File 'lib/google4r/checkout/frontend.rb', line 90 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.
94 95 96 |
# File 'lib/google4r/checkout/frontend.rb', line 94 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.
171 172 173 |
# File 'lib/google4r/checkout/frontend.rb', line 171 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.
177 178 179 |
# File 'lib/google4r/checkout/frontend.rb', line 177 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.
183 184 185 |
# File 'lib/google4r/checkout/frontend.rb', line 183 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.
165 166 167 |
# File 'lib/google4r/checkout/frontend.rb', line 165 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.
207 208 209 |
# File 'lib/google4r/checkout/frontend.rb', line 207 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.
117 118 119 |
# File 'lib/google4r/checkout/frontend.rb', line 117 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.
219 220 221 |
# File 'lib/google4r/checkout/frontend.rb', line 219 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.
147 148 149 |
# File 'lib/google4r/checkout/frontend.rb', line 147 def create_cancel_order_command return CancelOrderCommand.new(self) end |
#create_charge_and_ship_order_command ⇒ Object
Factory method to create a new ChargeAndShipOrderCommand object. Use this method to create your ChargeAndShipOrderCommand instances.
135 136 137 |
# File 'lib/google4r/checkout/frontend.rb', line 135 def create_charge_and_ship_order_command return ChargeAndShipOrderCommand.new(self) end |
#create_charge_order_command ⇒ Object
Factory method to create a new ChargeOrderCommand object. Use this method to create your ChargeOrderCommand instances.
129 130 131 |
# File 'lib/google4r/checkout/frontend.rb', line 129 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.
141 142 143 |
# File 'lib/google4r/checkout/frontend.rb', line 141 def create_checkout_command return CheckoutCommand.new(self) end |
#create_create_order_recurrence_request_command ⇒ Object
Factory method to create a new CreateOrderRecurrenceRequestCommand object. Use this method to create your CreateOrderRecurrenceRequestCommand instances.
195 196 197 |
# File 'lib/google4r/checkout/frontend.rb', line 195 def create_create_order_recurrence_request_command return CreateOrderRecurrenceRequestCommand.new(self) end |
#create_deliver_order_command ⇒ Object
Factory method to create a new DeliverOrderCommand object. Use this method to create your DeliverOrderCommand instances.
123 124 125 |
# File 'lib/google4r/checkout/frontend.rb', line 123 def create_deliver_order_command return DeliverOrderCommand.new(self) end |
#create_notification_data_request_command(continue_token) ⇒ Object
239 240 241 |
# File 'lib/google4r/checkout/frontend.rb', line 239 def create_notification_data_request_command(continue_token) return NotificationDataRequestCommand.new(self, continue_token) end |
#create_notification_data_token_request_command(options = {}) ⇒ Object
243 244 245 |
# File 'lib/google4r/checkout/frontend.rb', line 243 def create_notification_data_token_request_command(={}) return NotificationDataTokenRequestCommand.new(self, ) end |
#create_notification_handler ⇒ Object
Factory method that creates a new NotificationHandler object. Use this method to create your NotificationHandler instances.
111 112 113 |
# File 'lib/google4r/checkout/frontend.rb', line 111 def create_notification_handler return NotificationHandler.new(self) end |
#create_notification_history_request_command(serial_number) ⇒ Object
235 236 237 |
# File 'lib/google4r/checkout/frontend.rb', line 235 def create_notification_history_request_command(serial_number) return NotificationHistoryRequestCommand.new(self, serial_number) end |
#create_order_report_command(start_date, end_date) ⇒ Object
Factory method that creates a new OrderReportCommand object. Use this method to create your OrderReportCommand instances.
231 232 233 |
# File 'lib/google4r/checkout/frontend.rb', line 231 def create_order_report_command(start_date, end_date) return OrderReportCommand.new(self, start_date, end_date) end |
#create_refund_order_command ⇒ Object
Factory method to create a new RefundOrderCommand object. Use this method to create your RefundOrderCommand instances.
153 154 155 |
# File 'lib/google4r/checkout/frontend.rb', line 153 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.
225 226 227 |
# File 'lib/google4r/checkout/frontend.rb', line 225 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.
213 214 215 |
# File 'lib/google4r/checkout/frontend.rb', line 213 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.
159 160 161 |
# File 'lib/google4r/checkout/frontend.rb', line 159 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.
201 202 203 |
# File 'lib/google4r/checkout/frontend.rb', line 201 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.
189 190 191 |
# File 'lib/google4r/checkout/frontend.rb', line 189 def create_unarchive_order_command return UnarchiveOrderCommand.new(self) end |