Class: Google4R::Checkout::MerchantCalculationResults
- Inherits:
-
Object
- Object
- Google4R::Checkout::MerchantCalculationResults
- Defined in:
- lib/google4r/checkout/merchant_calculation.rb
Overview
This class represents a merchant-calculation-results XML
Usage Sample
results = MerchantCalculationResults.new coupon_result = CouponResult.new(true, ‘FirstVisitCoupon’, Money.new(500, ‘USD’), ‘Congratulations! You saved $5.00 on your first visit!’) gift_certificate_result = GiftCertificateResult.new(true, ‘GiftCert012345’, Money.new(1000, ‘USD’), ‘You used your Gift Certificate!’)
results.create_merchant_calculation_result do |result|
result.shipping_name = 'SuperShip'
result.address_id = '739030698069958'
result.shipping_rate = Money.new(703, 'USD')
result.shippable = true
result.total_tax = Money.new(1467, 'USD')
result.create_merchant_code_result(@coupon_result)
result.create_merchant_code_result(@gift_certificate_result)
end
results.create_merchant_calculation_result do |result|
result.shipping_name = 'UPS Ground'
result.address_id = '739030698069958'
result.shipping_rate = Money.new(556, 'USD')
result.shippable = true
result.total_tax = Money.new(1467, 'USD')
result.create_merchant_code_result(@coupon_result)
result.create_merchant_code_result(@gift_certificate_result)
end
results.to_xml # To create the XML to return to Google
Instance Attribute Summary collapse
-
#merchant_calculation_results ⇒ Object
readonly
An array of merchant calcuation results.
Instance Method Summary collapse
-
#create_merchant_calculation_result(result = nil, &block) ⇒ Object
This method takes a MerchantCalculationResult object and add it to the merchant_calculation_results array.
-
#initialize ⇒ MerchantCalculationResults
constructor
A new instance of MerchantCalculationResults.
- #to_xml ⇒ Object
Constructor Details
#initialize ⇒ MerchantCalculationResults
Returns a new instance of MerchantCalculationResults.
201 202 203 |
# File 'lib/google4r/checkout/merchant_calculation.rb', line 201 def initialize() @merchant_calculation_results = Array.new end |
Instance Attribute Details
#merchant_calculation_results ⇒ Object (readonly)
An array of merchant calcuation results
199 200 201 |
# File 'lib/google4r/checkout/merchant_calculation.rb', line 199 def merchant_calculation_results @merchant_calculation_results end |
Instance Method Details
#create_merchant_calculation_result(result = nil, &block) ⇒ Object
This method takes a MerchantCalculationResult object and add it to the merchant_calculation_results array. If the object is not provided, it will instantiate one and add it to the array. An optional code block can be supplied to set the attributes of the new MerchantCalculationResult object.
Raises RuntimeError exceptions if the given object is not of type MerchantCalculationResult.
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/google4r/checkout/merchant_calculation.rb', line 212 def create_merchant_calculation_result(result=nil, &block) if result.nil? result = MerchantCalculationResult.new # Pass the newly generated item to the given block to set its attributes. yield(result) if block_given? else raise "Not a MerchantCalculationResult!" unless result.kind_of?(MerchantCalculationResult) end @merchant_calculation_results << result end |
#to_xml ⇒ Object
223 224 225 |
# File 'lib/google4r/checkout/merchant_calculation.rb', line 223 def to_xml() return MerchantCalculationResultsXmlGenerator.new(self).generate() end |