Class: Google4R::Checkout::CheckoutCommand
- Defined in:
- lib/google4r/checkout/commands.rb
Overview
The CheckoutCommand represents a <checkout-shopping-cart> command sent to the server.
A CheckoutCommand instance can have an arbitrary number of TaxTable and ShippingMethod instances. You must create these instances using the create_* methods which CheckoutCommand supplies.
CheckoutCommand#send_to_google_checkout returns CheckoutRedirectResponse instances.
Use the Frontend class to create new CheckoutCommand instances and do not instanciate the class directly.
Note that you have to create/set the tax tables for CheckoutCommands before you can add any items to the cart that define a tax table.
Example
frontend = Google4R::Checkout::Frontend.new(configuration)
frontend.tax_table_factory = TaxTableFactory.new
command = frontend.create_checkout_command
Constant Summary
Constants inherited from Command
Google4R::Checkout::Command::PRODUCTION_URL, Google4R::Checkout::Command::SANDBOX_URL
Instance Attribute Summary collapse
-
#cart ⇒ Object
readonly
The ShoppingCart of this CheckoutCommand.
-
#continue_shopping_url ⇒ Object
The URL to continue shopping after completing the checkout (String, optional).
-
#edit_cart_url ⇒ Object
The URL at where the cart can be edited (String, optional).
-
#request_buyer_phone_number ⇒ Object
A boolean flag; true iff the customer HAS to provide his phone number (optional).
-
#shipping_methods ⇒ Object
readonly
An array of ShippingMethod objects of this CheckoutCommand.
-
#tax_tables ⇒ Object
readonly
An array of the TaxTable objects of this CheckoutCommand.
Attributes inherited from Command
Instance Method Summary collapse
-
#create_shipping_method(clazz) {|shipping_method| ... } ⇒ Object
Use this method to create a new shipping method.
-
#initialize(frontend) ⇒ CheckoutCommand
constructor
Initialize a new CheckoutCommand with a fresh CheckoutCart and an empty Array of tax tables and an empty array of ShippingMethod instances.
-
#to_xml ⇒ Object
Generates the XML for this CheckoutCommand.
Methods inherited from Command
#send_to_google_checkout, #sign_and_encode
Constructor Details
#initialize(frontend) ⇒ CheckoutCommand
Initialize a new CheckoutCommand with a fresh CheckoutCart and an empty Array of tax tables and an empty array of ShippingMethod instances. Do not use this method directly but use Frontent#create_checkout_command to create CheckoutCommand objects.
218 219 220 221 222 223 224 |
# File 'lib/google4r/checkout/commands.rb', line 218 def initialize(frontend) super(frontend) @cart = ShoppingCart.new(self) @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.new) @shipping_methods = Array.new end |
Instance Attribute Details
#cart ⇒ Object (readonly)
The ShoppingCart of this CheckoutCommand.
189 190 191 |
# File 'lib/google4r/checkout/commands.rb', line 189 def cart @cart end |
#continue_shopping_url ⇒ Object
The URL to continue shopping after completing the checkout (String, optional).
204 205 206 |
# File 'lib/google4r/checkout/commands.rb', line 204 def continue_shopping_url @continue_shopping_url end |
#edit_cart_url ⇒ Object
The URL at where the cart can be edited (String, optional).
201 202 203 |
# File 'lib/google4r/checkout/commands.rb', line 201 def edit_cart_url @edit_cart_url end |
#request_buyer_phone_number ⇒ Object
A boolean flag; true iff the customer HAS to provide his phone number (optional).
207 208 209 |
# File 'lib/google4r/checkout/commands.rb', line 207 def request_buyer_phone_number @request_buyer_phone_number end |
#shipping_methods ⇒ Object (readonly)
An array of ShippingMethod objects of this CheckoutCommand. Use #create_shipping_method to create new shipping methods.
198 199 200 |
# File 'lib/google4r/checkout/commands.rb', line 198 def shipping_methods @shipping_methods end |
#tax_tables ⇒ Object (readonly)
An array of the TaxTable objects of this CheckoutCommand. They have been created with the tax table factory of the frontend which created this command.
194 195 196 |
# File 'lib/google4r/checkout/commands.rb', line 194 def tax_tables @tax_tables end |
Instance Method Details
#create_shipping_method(clazz) {|shipping_method| ... } ⇒ Object
Use this method to create a new shipping method. You have to pass in one of { PickupShipping, FlatRateShipping } for clazz. The method will create a new instance of the class you passedin object and add it to the internal list of shipping methods.
If you pass a block to this method (preferred) then the newly created ShippingMethod object will be passed into this block for setting its attributes. The newly created shipping method will be returned in all cases.
The first shipping method will be used as the default.
Raises a RuntimeError if the parameter clazz is invalid.
238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/google4r/checkout/commands.rb', line 238 def create_shipping_method(clazz, &block) if not [ PickupShipping, FlatRateShipping ].include?(clazz) then raise "Unknown shipping method: #{type.inspect}." end shipping_method = clazz.new @shipping_methods << shipping_method yield(shipping_method) if block_given? return shipping_method end |
#to_xml ⇒ Object
Generates the XML for this CheckoutCommand.
210 211 212 |
# File 'lib/google4r/checkout/commands.rb', line 210 def to_xml CheckoutCommandXmlGenerator.new(self).generate end |