Class: Google4R::Checkout::MerchantCode
- Inherits:
-
Object
- Object
- Google4R::Checkout::MerchantCode
- Defined in:
- lib/google4r/checkout/notifications.rb
Overview
MerchantCodes represent gift certificates or coupons that have been used in an order.
Only used with Merchant Calculations.
Constant Summary collapse
- GIFT_CERTIFICATE =
"GIFT_CERTIFICATE".freeze
- COUPON =
"COUPON".freeze
Instance Attribute Summary collapse
-
#applied_amount ⇒ Object
The amount of the adjustment that has been applied to the cart’s total (Money).
-
#calculated_amount ⇒ Object
The amount of money that has been calculated as the adjustment’s worth (Money, optional).
-
#code ⇒ Object
The adjustment’s code (String).
-
#message ⇒ Object
The message associated with the direct adjustment (String, optional).
-
#type ⇒ Object
The type of the adjustment.
Class Method Summary collapse
-
.create_from_element(element) ⇒ Object
Creates the MerchantCode from the given REXML::Element instance.
Instance Attribute Details
#applied_amount ⇒ Object
The amount of the adjustment that has been applied to the cart’s total (Money).
356 357 358 |
# File 'lib/google4r/checkout/notifications.rb', line 356 def applied_amount @applied_amount end |
#calculated_amount ⇒ Object
The amount of money that has been calculated as the adjustment’s worth (Money, optional).
353 354 355 |
# File 'lib/google4r/checkout/notifications.rb', line 353 def calculated_amount @calculated_amount end |
#code ⇒ Object
The adjustment’s code (String).
350 351 352 |
# File 'lib/google4r/checkout/notifications.rb', line 350 def code @code end |
#message ⇒ Object
The message associated with the direct adjustment (String, optional).
359 360 361 |
# File 'lib/google4r/checkout/notifications.rb', line 359 def @message end |
#type ⇒ Object
The type of the adjustment. Can be one of GIFT_CERTIFICATE and COUPON.
347 348 349 |
# File 'lib/google4r/checkout/notifications.rb', line 347 def type @type end |
Class Method Details
.create_from_element(element) ⇒ Object
Creates the MerchantCode from the given REXML::Element instance. The Element’s name must be “gift-certificate-adjustment” or “coupon-adjustment”.
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/google4r/checkout/notifications.rb', line 363 def self.create_from_element(element) result = MerchantCode.new hash = Hash.new hash[:type] = case element.name when 'gift-certificate-adjustment' then GIFT_CERTIFICATE when 'coupon-adjustment' then COUPON else raise "Invalid tag name: #{element.name} in \n—-\n#{element.to_s}\n—-." end hash[:code] = element.elements['code'].text hash[:calculated_amount] = (element.elements['calculated-amount'].text.to_f * 100).to_i rescue nil # TODO: this will break for currencies where 100c != 1d hash[:calculated_amount_currency] = element.elements['calculated-amount/@currency'].value rescue nil hash[:applied_amount] = (element.elements['applied-amount'].text.to_f * 100).to_i # TODO: this will break for currencies where 100c != 1d hash[:applied_amount_currency] = element.elements['applied-amount/@currency'].value hash[:message] = element.elements['message'].text rescue nil result.type = hash[:type] result.code = hash[:code] if not hash[:calculated_amount].nil? then result.calculated_amount = Money.new(hash[:calculated_amount], hash[:calculated_amount_currency]) end result.applied_amount = Money.new(hash[:applied_amount], hash[:applied_amount_currency]) result. = hash[:message] unless hash[:message].nil? return result end |