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).
543 544 545 |
# File 'lib/google4r/checkout/notifications.rb', line 543 def applied_amount @applied_amount end |
#calculated_amount ⇒ Object
The amount of money that has been calculated as the adjustment's worth (Money, optional).
540 541 542 |
# File 'lib/google4r/checkout/notifications.rb', line 540 def calculated_amount @calculated_amount end |
#code ⇒ Object
The adjustment's code (String).
537 538 539 |
# File 'lib/google4r/checkout/notifications.rb', line 537 def code @code end |
#message ⇒ Object
The message associated with the direct adjustment (String, optional).
546 547 548 |
# File 'lib/google4r/checkout/notifications.rb', line 546 def end |
#type ⇒ Object
The type of the adjustment. Can be one of GIFT_CERTIFICATE and COUPON.
534 535 536 |
# File 'lib/google4r/checkout/notifications.rb', line 534 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".
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/google4r/checkout/notifications.rb', line 550 def self.create_from_element(element) result = MerchantCode.new result.type = case element.name when 'gift-certificate-adjustment' then GIFT_CERTIFICATE when 'coupon-adjustment' then COUPON else raise ArgumentError, "Invalid tag name: #{element.name} in \n—-\n#{element.to_s}\n—-." end result.code = element.elements['code'].text amount = (element.elements['calculated-amount'].text.to_f*100).to_i rescue nil currency = element.elements['calculated-amount'].attributes['currency'] rescue nil result.calculated_amount = Money.new(amount, currency) unless amount.nil? amount = (element.elements['applied-amount'].text.to_f*100).to_i currency = element.elements['applied-amount'].attributes['currency'] result.applied_amount = Money.new(amount, currency) result. = element.elements['message'].text rescue nil return result end |