Class: DPay::DccOffer

Inherits:
Object
  • Object
show all
Defined in:
lib/dpay/card/dcc_offer.rb,
sig/dpay/card/dcc_offer.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ DccOffer

Returns a new instance of DccOffer.

Parameters:

  • data (Hash[String, untyped])


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_amountMoney (readonly)

Returns the value of attribute converted_amount.

Returns:



5
6
7
# File 'lib/dpay/card/dcc_offer.rb', line 5

def converted_amount
  @converted_amount
end

#currency_conversion_idString (readonly)

Returns the value of attribute currency_conversion_id.

Returns:

  • (String)


5
6
7
# File 'lib/dpay/card/dcc_offer.rb', line 5

def currency_conversion_id
  @currency_conversion_id
end

#declaration_textString (readonly)

Returns the value of attribute declaration_text.

Returns:

  • (String)


5
6
7
# File 'lib/dpay/card/dcc_offer.rb', line 5

def declaration_text
  @declaration_text
end

#exchange_rateFloat (readonly)

Returns the value of attribute exchange_rate.

Returns:

  • (Float)


5
6
7
# File 'lib/dpay/card/dcc_offer.rb', line 5

def exchange_rate
  @exchange_rate
end

#markupArray[DccMarkup] (readonly)

Returns the value of attribute markup.

Returns:



5
6
7
# File 'lib/dpay/card/dcc_offer.rb', line 5

def markup
  @markup
end

#original_amountMoney (readonly)

Returns the value of attribute original_amount.

Returns:



5
6
7
# File 'lib/dpay/card/dcc_offer.rb', line 5

def original_amount
  @original_amount
end

#rawHash[String, untyped] (readonly)

Returns the value of attribute raw.

Returns:

  • (Hash[String, untyped])


5
6
7
# File 'lib/dpay/card/dcc_offer.rb', line 5

def raw
  @raw
end

#valid_untilString (readonly)

Returns the value of attribute valid_until.

Returns:

  • (String)


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

Parameters:

  • data (Hash[String, untyped])

Returns:



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

Parameters:

  • value (Object)

Returns:

  • (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

Returns:

  • (Boolean)


26
27
28
# File 'lib/dpay/card/dcc_offer.rb', line 26

def european_economic_area?
  @european_economic_area
end