Class: DPay::CardData

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

Constant Summary collapse

PAN =

Returns:

  • (Regexp)
/\A\d{12,19}\z/
CVV =

Returns:

  • (Regexp)
/\A\d{3,4}\z/
EXPIRY =

Returns:

  • (Regexp)
%r{\A(0[1-9]|1[0-2])/\d{2}\z}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pan, cvv, expiry) ⇒ CardData

Returns a new instance of CardData.

Parameters:

  • pan (String)
  • cvv (String)
  • expiry (String)

Raises:



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

def initialize(pan, cvv, expiry)
  normalized = pan.to_s.delete(" ")

  raise InvalidArgumentError, "Card number must be 12-19 digits" unless PAN.match?(normalized)
  raise InvalidArgumentError, "CVV must be 3-4 digits" unless CVV.match?(cvv.to_s)
  raise InvalidArgumentError, "Expiry must be in MM/YY format" unless EXPIRY.match?(expiry.to_s)

  @pan = normalized
  @cvv = cvv
  @expiry = expiry
  freeze
end

Instance Attribute Details

#cvvString (readonly)

Returns the value of attribute cvv.

Returns:

  • (String)


9
10
11
# File 'lib/dpay/card/card_data.rb', line 9

def cvv
  @cvv
end

#expiryString (readonly)

Returns the value of attribute expiry.

Returns:

  • (String)


9
10
11
# File 'lib/dpay/card/card_data.rb', line 9

def expiry
  @expiry
end

#panString (readonly)

Returns the value of attribute pan.

Returns:

  • (String)


9
10
11
# File 'lib/dpay/card/card_data.rb', line 9

def pan
  @pan
end

Instance Method Details

#inspectString Also known as: to_s

Returns:

  • (String)


24
25
26
# File 'lib/dpay/card/card_data.rb', line 24

def inspect
  "#<DPay::CardData pan=[FILTERED] cvv=[FILTERED] expiry=[FILTERED]>"
end