Class: TresDelta::CreditCard

Inherits:
Object
  • Object
show all
Defined in:
lib/tres_delta/credit_card.rb,
lib/tres_delta/credit_card/address.rb

Defined Under Namespace

Classes: Address

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ CreditCard

Returns a new instance of CreditCard.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tres_delta/credit_card.rb', line 7

def initialize(params = {})
  @number           = params[:number] || params[:card_account_number]
  @expiration_month = params[:expiration_month]
  @expiration_year  = params[:expiration_year]
  @token            = params[:token]
  @name             = params[:name]
  @billing_address  = Address.new(params[:billing_address] || {})
  @type             = params[:type] || params[:card_type]
  @nickname         = params[:nickname]
  @customer         = params[:customer] || Customer.new
  @security_code    = params[:security_code]
end

Instance Attribute Details

#billing_addressObject (readonly)

Returns the value of attribute billing_address.



3
4
5
# File 'lib/tres_delta/credit_card.rb', line 3

def billing_address
  @billing_address
end

#customerObject (readonly)

Returns the value of attribute customer.



3
4
5
# File 'lib/tres_delta/credit_card.rb', line 3

def customer
  @customer
end

#expiration_monthObject

Returns the value of attribute expiration_month.



5
6
7
# File 'lib/tres_delta/credit_card.rb', line 5

def expiration_month
  @expiration_month
end

#expiration_yearObject

Returns the value of attribute expiration_year.



5
6
7
# File 'lib/tres_delta/credit_card.rb', line 5

def expiration_year
  @expiration_year
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/tres_delta/credit_card.rb', line 3

def name
  @name
end

#nicknameObject (readonly)

Returns the value of attribute nickname.



3
4
5
# File 'lib/tres_delta/credit_card.rb', line 3

def nickname
  @nickname
end

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/tres_delta/credit_card.rb', line 3

def number
  @number
end

#security_codeObject (readonly)

Returns the value of attribute security_code.



3
4
5
# File 'lib/tres_delta/credit_card.rb', line 3

def security_code
  @security_code
end

#tokenObject

Returns the value of attribute token.



5
6
7
# File 'lib/tres_delta/credit_card.rb', line 5

def token
  @token
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/tres_delta/credit_card.rb', line 3

def type
  @type
end

Class Method Details

.create(customer, params = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/tres_delta/credit_card.rb', line 33

def create(customer, params = {})
  CreditCard.new(params).tap do |credit_card|
    add_card = Vault.add_stored_credit_card(customer, credit_card)
    raise InvalidCreditCard unless add_card.success?

    credit_card.token = add_card.token
  end
end

.find(customer, token, load_number = false) ⇒ Object

Raises:



42
43
44
45
46
47
# File 'lib/tres_delta/credit_card.rb', line 42

def find(customer, token, load_number = false)
  stored_card_details = Vault.get_stored_credit_card(customer, token, load_number)
  raise CreditCardNotFound unless stored_card_details.success?

  CreditCard.new(stored_card_details.credit_card.merge(customer: customer))
end

Instance Method Details

#has_security_code?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/tres_delta/credit_card.rb', line 28

def has_security_code?
  security_code.to_s.strip.size > 0
end

#saveObject



20
21
22
23
24
25
26
# File 'lib/tres_delta/credit_card.rb', line 20

def save
  if token.nil?
    Vault.add_stored_credit_card(customer, self).success?
  else
    Vault.update_stored_credit_card(customer, self).success?
  end
end