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::CHECKOUT_API_URL, Google4R::Checkout::Command::DONATE_CHECKOUT_API_URL, Google4R::Checkout::Command::DONATE_ORDER_PROCESSING_API_URL, Google4R::Checkout::Command::DONATE_ORDER_REPORT_API_URL, Google4R::Checkout::Command::ORDER_PROCESSING_API_URL, Google4R::Checkout::Command::ORDER_REPORT_API_URL, Google4R::Checkout::Command::POLLING_API_URL, Google4R::Checkout::Command::PRODUCTION_URL_PREFIX, Google4R::Checkout::Command::SANDBOX_URL_PREFIX
Instance Attribute Summary collapse
-
#accept_gift_certificates ⇒ Object
A boolean flag to indicate whether gift certificate is supported or not (optional).
-
#accept_merchant_coupons ⇒ Object
A boolean flag to indicate whether merchant coupon is supported or not (optional).
-
#analytics_data ⇒ Object
Setting this allows Google Analytics to track purchases that use Checkout The value should be as set by the analytics javascript in the hidden form element names “analyticsdata” on the page with the checkout button.
-
#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).
-
#merchant_calculations_url ⇒ Object
The URL of the merchant calculation callback (optional).
-
#parameterized_urls ⇒ Object
readonly
Returns the value of attribute parameterized_urls.
-
#platform_id ⇒ Object
A Google Checkout merchant ID that identifies the eCommerce provider.
-
#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.
-
#shopping_cart ⇒ Object
readonly
The ShoppingCart of this CheckoutCommand.
-
#tax_tables ⇒ Object
readonly
An array of the TaxTable objects of this CheckoutCommand.
Attributes inherited from Command
#command_tag_name, #frontend, #google_order_number
Instance Method Summary collapse
-
#create_parameterized_url(opts) {|parameterized_url| ... } ⇒ Object
Use this method to create a new parameterized_url object.
-
#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
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.
348 349 350 351 352 353 354 355 356 |
# File 'lib/google4r/checkout/commands.rb', line 348 def initialize(frontend) super(frontend) @shopping_cart = ShoppingCart.new(self) @shipping_methods = Array.new @parameterized_urls = Array.new if frontend.tax_table_factory @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.new) end end |
Instance Attribute Details
#accept_gift_certificates ⇒ Object
A boolean flag to indicate whether gift certificate is supported or not (optional).
327 328 329 |
# File 'lib/google4r/checkout/commands.rb', line 327 def accept_gift_certificates @accept_gift_certificates end |
#accept_merchant_coupons ⇒ Object
A boolean flag to indicate whether merchant coupon is supported or not (optional).
324 325 326 |
# File 'lib/google4r/checkout/commands.rb', line 324 def accept_merchant_coupons @accept_merchant_coupons end |
#analytics_data ⇒ Object
Setting this allows Google Analytics to track purchases that use Checkout The value should be as set by the analytics javascript in the hidden form element names “analyticsdata” on the page with the checkout button. If left unset then the element will not be generated. see: code.google.com/apis/checkout/developer/checkout_analytics_integration.html
337 338 339 |
# File 'lib/google4r/checkout/commands.rb', line 337 def analytics_data @analytics_data end |
#continue_shopping_url ⇒ Object
The URL to continue shopping after completing the checkout (String, optional).
315 316 317 |
# File 'lib/google4r/checkout/commands.rb', line 315 def continue_shopping_url @continue_shopping_url end |
#edit_cart_url ⇒ Object
The URL at where the cart can be edited (String, optional).
312 313 314 |
# File 'lib/google4r/checkout/commands.rb', line 312 def edit_cart_url @edit_cart_url end |
#merchant_calculations_url ⇒ Object
The URL of the merchant calculation callback (optional).
321 322 323 |
# File 'lib/google4r/checkout/commands.rb', line 321 def merchant_calculations_url @merchant_calculations_url end |
#parameterized_urls ⇒ Object (readonly)
Returns the value of attribute parameterized_urls.
309 310 311 |
# File 'lib/google4r/checkout/commands.rb', line 309 def parameterized_urls @parameterized_urls end |
#platform_id ⇒ Object
A Google Checkout merchant ID that identifies the eCommerce provider.
330 331 332 |
# File 'lib/google4r/checkout/commands.rb', line 330 def platform_id @platform_id end |
#request_buyer_phone_number ⇒ Object
A boolean flag; true iff the customer HAS to provide his phone number (optional).
318 319 320 |
# File 'lib/google4r/checkout/commands.rb', line 318 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.
307 308 309 |
# File 'lib/google4r/checkout/commands.rb', line 307 def shipping_methods @shipping_methods end |
#shopping_cart ⇒ Object (readonly)
The ShoppingCart of this CheckoutCommand.
298 299 300 |
# File 'lib/google4r/checkout/commands.rb', line 298 def shopping_cart @shopping_cart 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.
303 304 305 |
# File 'lib/google4r/checkout/commands.rb', line 303 def tax_tables @tax_tables end |
Instance Method Details
#create_parameterized_url(opts) {|parameterized_url| ... } ⇒ Object
Use this method to create a new parameterized_url object. It requires the URL to be passed in the ‘opts’ hash. It will create a new instance of the paramterized URL object.
Raises an argument error if the URL passed in the opts hash is not a String
To find more information on 3rd party conversion tracking visit the API documentation code.google.com/apis/checkout/developer/checkout_pixel_tracking.html
393 394 395 396 397 398 399 400 401 402 |
# File 'lib/google4r/checkout/commands.rb', line 393 def create_parameterized_url(opts, &block) raise(ArgumentError, "Url option required") unless opts[:url].kind_of?(String) parameterized_url = ParameterizedUrl.new(opts[:url]) @parameterized_urls << parameterized_url yield(parameterized_url) if block_given? return parameterized_url end |
#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 created shipping method will be used as the default.
Raises a ArgumentError if the parameter clazz is invalid.
370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/google4r/checkout/commands.rb', line 370 def create_shipping_method(clazz, &block) if not [ PickupShipping, FlatRateShipping, MerchantCalculatedShipping, CarrierCalculatedShipping ].include?(clazz) then raise ArgumentError, "Unknown shipping method: #{clazz.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.
340 341 342 |
# File 'lib/google4r/checkout/commands.rb', line 340 def to_xml CheckoutCommandXmlGenerator.new(self).generate end |