Class: Google4R::Checkout::MerchantCalculationResult

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

Overview

The class represnts a merchant-calculation-result in the merchant-calculation-results XML

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shipping_name = '', address_id = '', shipping_rate = nil, shippable = false, total_tax = nil) ⇒ MerchantCalculationResult

Returns a new instance of MerchantCalculationResult.



248
249
250
251
252
253
254
255
# File 'lib/google4r/checkout/merchant_calculation.rb', line 248

def initialize(shipping_name='', address_id='', shipping_rate=nil, shippable=false, total_tax=nil)
  @shipping_name = shipping_name
  @address_id = address_id
  @shipping_rate = shipping_rate
  @shippable = shippable
  @total_tax = total_tax
  @merchant_code_results = Array.new
end

Instance Attribute Details

#address_idObject

The address id (string)



234
235
236
# File 'lib/google4r/checkout/merchant_calculation.rb', line 234

def address_id
  @address_id
end

#merchant_code_resultsObject (readonly)

An array of merchant code results



246
247
248
# File 'lib/google4r/checkout/merchant_calculation.rb', line 246

def merchant_code_results
  @merchant_code_results
end

#shippableObject

Is it this applicable to this order (boolean)



240
241
242
# File 'lib/google4r/checkout/merchant_calculation.rb', line 240

def shippable
  @shippable
end

#shipping_nameObject

The shipping name (string)



231
232
233
# File 'lib/google4r/checkout/merchant_calculation.rb', line 231

def shipping_name
  @shipping_name
end

#shipping_rateObject

The shipping rate (Money)



237
238
239
# File 'lib/google4r/checkout/merchant_calculation.rb', line 237

def shipping_rate
  @shipping_rate
end

#total_taxObject

The total tax (Money)



243
244
245
# File 'lib/google4r/checkout/merchant_calculation.rb', line 243

def total_tax
  @total_tax
end

Instance Method Details

#create_merchant_code_result(result = nil) {|result| ... } ⇒ Object

This method takes either a CouponResult or GiftCertificateResult object and add it to the merchant_code_results array. If the Class object of either the two types is provided, it will create an instance from the Class object. An optional code block can be supplied to set the attributes of the new object.

Raises RuntimeError exceptions if there is no argument or a wrong class type is provided.

Yields:

  • (result)


265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/google4r/checkout/merchant_calculation.rb', line 265

def create_merchant_code_result(result=nil, &block)
  if !result.nil?
    if [ CouponResult, GiftCertificateResult ].include?(result) # is a Class object
      result = result.new
    else
      raise "Invalid Merchant Code Result class type: #{result.class}!" unless 
        (result.kind_of?(CouponResult) || result.kind_of?(GiftCertificateResult))
    end
  else
    raise "You must either provide a MerchantCodeResult Class type or a CoupleResult or GiftCertificateResult instance."
  end
  @merchant_code_results << result

  # Pass the newly generated item to the given block to set its attributes.
  yield(result) if block_given?
  
end