Class: Vantiv::TestCard

Inherits:
Object
  • Object
show all
Defined in:
lib/vantiv/test_card.rb

Defined Under Namespace

Classes: CardNotFound

Constant Summary collapse

CARDS =
[
  {
    name: "valid_account",
    card_number: "4457010000000009",
    expiry_month: "01",
    expiry_year: "21",
    cvv: "349",
    mocked_sandbox_payment_account_id: "1111111111110009",
    network: "VI"
  },
  {
    name: "invalid_card_number",
    card_number: "4457010010900010",
    expiry_month: "01",
    expiry_year: "21",
    cvv: "349",
    mocked_sandbox_payment_account_id: nil,
    network: "VI"
  },
  {
    name: "invalid_account_number",
    card_number: "5112001600000006",
    expiry_month: "01",
    expiry_year: "20",
    cvv: "349",
    mocked_sandbox_payment_account_id: "1111111111130006",
    network: "MC"
  },
  {
    name: "insufficient_funds",
    card_number: "4457002100000005",
    expiry_month: "01",
    expiry_year: "20",
    cvv: "349",
    mocked_sandbox_payment_account_id: "1111111111120005",
    network: "VI"
  },
  {
    name: "expired_card",
    card_number: "5112001900000003",
    expiry_month: "01",
    expiry_year: "20",
    cvv: "349",
    mocked_sandbox_payment_account_id: "1111111111140003",
    network: "MC"
  },
  {
    name: "account_updater",
    card_number: "4457000300000007",
    expiry_month: "01",
    expiry_year: "15",
    cvv: "123",
    mocked_sandbox_payment_account_id: "1111111111120007",
    network: "VI"
  },
  {
    name: "account_updater_account_closed",
    card_number: "5112000101110009",
    expiry_month: "11",
    expiry_year: "99",
    cvv: "123",
    mocked_sandbox_payment_account_id: "1111111111160009",
    network: "MC"
  },
  {
    name: "account_updater_contact_cardholder",
    card_number: "4457000301100004",
    expiry_month: "11",
    expiry_year: "99",
    cvv: "123",
    mocked_sandbox_payment_account_id: "1111111111130004",
    network: "VI"
  },
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(card_number:, expiry_month:, expiry_year:, cvv:, mocked_sandbox_payment_account_id:, network:, name:, temporary_token:) ⇒ TestCard

Returns a new instance of TestCard.



116
117
118
119
120
121
122
123
124
125
# File 'lib/vantiv/test_card.rb', line 116

def initialize(card_number:, expiry_month:, expiry_year:, cvv:, mocked_sandbox_payment_account_id:, network:, name:, temporary_token:)
  @card_number = card_number
  @expiry_month = expiry_month
  @expiry_year = expiry_year
  @cvv = cvv
  @mocked_sandbox_payment_account_id = 
  @network = network
  @name = name
  @temporary_token = temporary_token
end

Instance Attribute Details

#card_numberObject (readonly)

Returns the value of attribute card_number.



114
115
116
# File 'lib/vantiv/test_card.rb', line 114

def card_number
  @card_number
end

#cvvObject (readonly)

Returns the value of attribute cvv.



114
115
116
# File 'lib/vantiv/test_card.rb', line 114

def cvv
  @cvv
end

#expiry_monthObject (readonly)

Returns the value of attribute expiry_month.



114
115
116
# File 'lib/vantiv/test_card.rb', line 114

def expiry_month
  @expiry_month
end

#expiry_yearObject (readonly)

Returns the value of attribute expiry_year.



114
115
116
# File 'lib/vantiv/test_card.rb', line 114

def expiry_year
  @expiry_year
end

#mocked_sandbox_payment_account_idObject (readonly)

Returns the value of attribute mocked_sandbox_payment_account_id.



114
115
116
# File 'lib/vantiv/test_card.rb', line 114

def 
  @mocked_sandbox_payment_account_id
end

#nameObject (readonly)

Returns the value of attribute name.



114
115
116
# File 'lib/vantiv/test_card.rb', line 114

def name
  @name
end

#networkObject (readonly)

Returns the value of attribute network.



114
115
116
# File 'lib/vantiv/test_card.rb', line 114

def network
  @network
end

#temporary_tokenObject (readonly)

Returns the value of attribute temporary_token.



114
115
116
# File 'lib/vantiv/test_card.rb', line 114

def temporary_token
  @temporary_token
end

Class Method Details

.allObject



86
87
88
89
90
# File 'lib/vantiv/test_card.rb', line 86

def self.all
  CARDS.map do |raw_card|
    new(raw_card)
  end
end

.find(card_number) ⇒ Object

Raises:



98
99
100
101
102
103
104
# File 'lib/vantiv/test_card.rb', line 98

def self.find(card_number)
  card = CARDS.find do |card_data|
    card_data[:card_number] == card_number
  end
  raise CardNotFound.new("No card with account number #{card_number}") unless card
  new(card)
end

.find_by_payment_account_id(payment_account_id) ⇒ Object

Raises:



106
107
108
109
110
111
112
# File 'lib/vantiv/test_card.rb', line 106

def self.()
  card = CARDS.find do |card_data|
    card_data[:mocked_sandbox_payment_account_id] == 
  end
  raise CardNotFound.new("No card with mocked sandbox payment account id #{}") unless card
  new(card)
end

Instance Method Details

#!=(other_object) ⇒ Object



135
136
137
# File 'lib/vantiv/test_card.rb', line 135

def !=(other_object)
  !(self == other_object)
end

#==(other_object) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/vantiv/test_card.rb', line 127

def ==(other_object)
  if other_object.is_a?(TestCard)
    name == other_object.name
  else
    super
  end
end

#tokenizable?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/vantiv/test_card.rb', line 139

def tokenizable?
  self != TestCard.invalid_card_number
end