Class: DPay::DccOffer
- Inherits:
-
Object
- Object
- DPay::DccOffer
- Defined in:
- lib/dpay/card/dcc_offer.rb,
sig/dpay/card/dcc_offer.rbs
Instance Attribute Summary collapse
-
#converted_amount ⇒ Money
readonly
Returns the value of attribute converted_amount.
-
#currency_conversion_id ⇒ String
readonly
Returns the value of attribute currency_conversion_id.
-
#declaration_text ⇒ String
readonly
Returns the value of attribute declaration_text.
-
#exchange_rate ⇒ Float
readonly
Returns the value of attribute exchange_rate.
-
#markup ⇒ Array[DccMarkup]
readonly
Returns the value of attribute markup.
-
#original_amount ⇒ Money
readonly
Returns the value of attribute original_amount.
-
#raw ⇒ Hash[String, untyped]
readonly
Returns the value of attribute raw.
-
#valid_until ⇒ String
readonly
Returns the value of attribute valid_until.
Class Method Summary collapse
Instance Method Summary collapse
- #currency(value) ⇒ String
- #european_economic_area? ⇒ Boolean
-
#initialize(data) ⇒ DccOffer
constructor
A new instance of DccOffer.
Constructor Details
#initialize(data) ⇒ DccOffer
Returns a new instance of DccOffer.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dpay/card/dcc_offer.rb', line 12 def initialize(data) @raw = data @currency_conversion_id = Internal::Coerce.string(data["currencyConversionId"]) || "" @original_amount = Internal::Coerce.money(data["originalAmount"], currency(data["originalCurrency"])) @converted_amount = Internal::Coerce.money(data["convertedAmount"], currency(data["convertedCurrency"])) exchange_rate = data["exchangeRate"] @exchange_rate = exchange_rate.is_a?(Integer) || exchange_rate.is_a?(Float) ? exchange_rate.to_f : 0.0 @valid_until = Internal::Coerce.string(data["validUntil"]) || "" @declaration_text = Internal::Coerce.string(data["declarationText"]) || "" @european_economic_area = Internal::Coerce.boolean(data["europeanEconomicArea"]) @markup = Internal::Coerce.list(data["markup"]).map { |markup| DccMarkup.from_api(markup) } freeze end |
Instance Attribute Details
#converted_amount ⇒ Money (readonly)
Returns the value of attribute converted_amount.
5 6 7 |
# File 'lib/dpay/card/dcc_offer.rb', line 5 def converted_amount @converted_amount end |
#currency_conversion_id ⇒ String (readonly)
Returns the value of attribute currency_conversion_id.
5 6 7 |
# File 'lib/dpay/card/dcc_offer.rb', line 5 def currency_conversion_id @currency_conversion_id end |
#declaration_text ⇒ String (readonly)
Returns the value of attribute declaration_text.
5 6 7 |
# File 'lib/dpay/card/dcc_offer.rb', line 5 def declaration_text @declaration_text end |
#exchange_rate ⇒ Float (readonly)
Returns the value of attribute exchange_rate.
5 6 7 |
# File 'lib/dpay/card/dcc_offer.rb', line 5 def exchange_rate @exchange_rate end |
#markup ⇒ Array[DccMarkup] (readonly)
Returns the value of attribute markup.
5 6 7 |
# File 'lib/dpay/card/dcc_offer.rb', line 5 def markup @markup end |
#original_amount ⇒ Money (readonly)
Returns the value of attribute original_amount.
5 6 7 |
# File 'lib/dpay/card/dcc_offer.rb', line 5 def original_amount @original_amount end |
#raw ⇒ Hash[String, untyped] (readonly)
Returns the value of attribute raw.
5 6 7 |
# File 'lib/dpay/card/dcc_offer.rb', line 5 def raw @raw end |
#valid_until ⇒ String (readonly)
Returns the value of attribute valid_until.
5 6 7 |
# File 'lib/dpay/card/dcc_offer.rb', line 5 def valid_until @valid_until end |
Class Method Details
.from_api(data) ⇒ DccOffer
8 9 10 |
# File 'lib/dpay/card/dcc_offer.rb', line 8 def self.from_api(data) new(data) end |
Instance Method Details
#currency(value) ⇒ String
32 33 34 |
# File 'lib/dpay/card/dcc_offer.rb', line 32 def currency(value) Currency.valid?(value) ? value : Currency::PLN end |
#european_economic_area? ⇒ Boolean
26 27 28 |
# File 'lib/dpay/card/dcc_offer.rb', line 26 def european_economic_area? @european_economic_area end |