Class: DPay::CardPaymentResult

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CardPaymentResult

Returns a new instance of CardPaymentResult.

Parameters:

  • data (Hash[String, untyped])


11
12
13
14
15
16
17
18
19
20
# File 'lib/dpay/card/card_payment_result.rb', line 11

def initialize(data)
  @raw = data
  message = data["message"].is_a?(Hash) ? data["message"] : {}

  @redirect_type = message["redirectType"].is_a?(String) ? message["redirectType"] : nil
  text = message["redirectText"]
  @redirect_text = text.is_a?(String) && !text.empty? ? text : nil
  @dcc_offer = message["dccOffer"].is_a?(Hash) ? DccOffer.from_api(message["dccOffer"]) : nil
  freeze
end

Instance Attribute Details

#dcc_offerDccOffer? (readonly)

Returns the value of attribute dcc_offer.

Returns:



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

def dcc_offer
  @dcc_offer
end

#rawHash[String, untyped] (readonly)

Returns the value of attribute raw.

Returns:

  • (Hash[String, untyped])


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

def raw
  @raw
end

#redirect_textString? (readonly)

Returns the value of attribute redirect_text.

Returns:

  • (String, nil)


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

def redirect_text
  @redirect_text
end

#redirect_typeString? (readonly)

Returns the value of attribute redirect_type.

Returns:

  • (String, nil)


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

def redirect_type
  @redirect_type
end

Class Method Details

.from_api(data) ⇒ CardPaymentResult

Parameters:

  • data (Hash[String, untyped])

Returns:



7
8
9
# File 'lib/dpay/card/card_payment_result.rb', line 7

def self.from_api(data)
  new(data)
end

Instance Method Details

#dcc_offer?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dpay/card/card_payment_result.rb', line 34

def dcc_offer?
  @redirect_type == RedirectType::DCC_OFFER
end

#decodeString?

Returns:

  • (String, nil)


48
49
50
51
52
53
54
55
56
# File 'lib/dpay/card/card_payment_result.rb', line 48

def decode
  text = @redirect_text
  return nil if text.nil?

  decoded = text.unpack1("m0")
  decoded.is_a?(String) ? decoded : nil
rescue ArgumentError
  nil
end

#redirect_urlString?

Returns:

  • (String, nil)


42
43
44
# File 'lib/dpay/card/card_payment_result.rb', line 42

def redirect_url
  requires_redirect? ? decode : nil
end

#requires_redirect?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/dpay/card/card_payment_result.rb', line 30

def requires_redirect?
  @redirect_type == RedirectType::URL
end

#success?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dpay/card/card_payment_result.rb', line 22

def success?
  @redirect_type == RedirectType::SUCCESS
end

#three_ds_form?Boolean

Returns:

  • (Boolean)


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

def three_ds_form?
  @redirect_type == RedirectType::FORM
end

#three_ds_form_htmlString?

Returns:

  • (String, nil)


38
39
40
# File 'lib/dpay/card/card_payment_result.rb', line 38

def three_ds_form_html
  three_ds_form? ? decode : nil
end