Class: Google4R::Checkout::CheckoutCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/google4r/checkout/commands.rb

Overview

The CheckoutCommand represents a 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::ORDER_PROCESSING_API_URL, Google4R::Checkout::Command::PRODUCTION_URL_PREFIX, Google4R::Checkout::Command::SANDBOX_URL_PREFIX

Instance Attribute Summary collapse

Attributes inherited from Command

#command_tag_name, #frontend, #google_order_number

Instance Method Summary collapse

Methods inherited from Command

#send_to_google_checkout

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.



243
244
245
246
247
248
# File 'lib/google4r/checkout/commands.rb', line 243

def initialize(frontend)
  super(frontend)
  @shopping_cart = ShoppingCart.new(self)
  @tax_tables = frontend.tax_table_factory.effective_tax_tables_at(Time.new)
  @shipping_methods = Array.new
end

Instance Attribute Details

#accept_gift_certificatesObject

A boolean flag to indicate whether gift certificate is supported or not (optional).



222
223
224
# File 'lib/google4r/checkout/commands.rb', line 222

def accept_gift_certificates
  @accept_gift_certificates
end

#accept_merchant_couponsObject

A boolean flag to indicate whether merchant coupon is supported or not (optional).



219
220
221
# File 'lib/google4r/checkout/commands.rb', line 219

def accept_merchant_coupons
  @accept_merchant_coupons
end

#analytics_dataObject

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: http://code.google.com/apis/checkout/developer/checkout_analytics_integration.html



232
233
234
# File 'lib/google4r/checkout/commands.rb', line 232

def analytics_data
  @analytics_data
end

#continue_shopping_urlObject

The URL to continue shopping after completing the checkout (String, optional).



210
211
212
# File 'lib/google4r/checkout/commands.rb', line 210

def continue_shopping_url
  @continue_shopping_url
end

#edit_cart_urlObject

The URL at where the cart can be edited (String, optional).



207
208
209
# File 'lib/google4r/checkout/commands.rb', line 207

def edit_cart_url
  @edit_cart_url
end

#merchant_calculations_urlObject

The URL of the merchant calculation callback (optional).



216
217
218
# File 'lib/google4r/checkout/commands.rb', line 216

def merchant_calculations_url
  @merchant_calculations_url
end

#platform_idObject

A Google Checkout merchant ID that identifies the eCommerce provider.



225
226
227
# File 'lib/google4r/checkout/commands.rb', line 225

def platform_id
  @platform_id
end

#request_buyer_phone_numberObject

A boolean flag; true iff the customer HAS to provide his phone number (optional).



213
214
215
# File 'lib/google4r/checkout/commands.rb', line 213

def request_buyer_phone_number
  @request_buyer_phone_number
end

#shipping_methodsObject (readonly)

An array of ShippingMethod objects of this CheckoutCommand. Use #create_shipping_method to create new shipping methods.



204
205
206
# File 'lib/google4r/checkout/commands.rb', line 204

def shipping_methods
  @shipping_methods
end

#shopping_cartObject (readonly)

The ShoppingCart of this CheckoutCommand.



195
196
197
# File 'lib/google4r/checkout/commands.rb', line 195

def shopping_cart
  @shopping_cart
end

#tax_tablesObject (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.



200
201
202
# File 'lib/google4r/checkout/commands.rb', line 200

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 created shipping method will be used as the default.

Raises a ArgumentError if the parameter clazz is invalid.

Yields:

  • (shipping_method)


262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/google4r/checkout/commands.rb', line 262

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_xmlObject

Generates the XML for this CheckoutCommand.



235
236
237
# File 'lib/google4r/checkout/commands.rb', line 235

def to_xml
  CheckoutCommandXmlGenerator.new(self).generate
end