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.



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

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)



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

def address_id
  @address_id
end

#merchant_code_resultsObject (readonly)

An array of merchant code results



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

def merchant_code_results
  @merchant_code_results
end

#shippableObject

Is it this applicable to this order (boolean)



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

def shippable
  @shippable
end

#shipping_nameObject

The shipping name (string)



229
230
231
# File 'lib/google4r/checkout/merchant_calculation.rb', line 229

def shipping_name
  @shipping_name
end

#shipping_rateObject

The shipping rate (Money)



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

def shipping_rate
  @shipping_rate
end

#total_taxObject

The total tax (Money)



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

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)


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

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