Class: VaultedBilling::CreditCard

Inherits:
Object
  • Object
show all
Defined in:
lib/vaulted_billing/credit_card.rb

Overview

Intermediary class used to translate your local credit card information into data which VaultedBilling can recognize and use.

Generally - and this is gateway specific - the only data which is actually required is the card number and expiration date (expires_on). Most of the other data is optional and may or may not be stored by your gateway.

Note: The vault_id is the unique identifier generated by your gateway when you initially store the customer information. This should be kept and stored locally, related to your local credit card information. If you generate a CreditCard object with a vault_id, it is assumed that the card is already stored on the gateway and is not new information.

Defined Under Namespace

Classes: Country

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ CreditCard

You may define any of the CreditCard attributes by passing a hash with the attribute name as the key:

CreditCard.new(:card_number => '4111....')


56
57
58
59
60
61
# File 'lib/vaulted_billing/credit_card.rb', line 56

def initialize(attributes = {})
  attributes = HashWithIndifferentAccess.new(attributes)
  attributes.each_pair do |key, value|
    send("#{key}=", value) if respond_to?("#{key}=")
  end
end

Instance Attribute Details

#card_numberObject

The customer’s credit card number



36
37
38
# File 'lib/vaulted_billing/credit_card.rb', line 36

def card_number
  @card_number
end

#countryObject

The country of the credit card address.



37
38
39
# File 'lib/vaulted_billing/credit_card.rb', line 37

def country
  @country
end

#currencyObject

The currency used by the credit card.



38
39
40
# File 'lib/vaulted_billing/credit_card.rb', line 38

def currency
  @currency
end

#cvv_numberObject

The verification number (CVV2) on the card.



39
40
41
# File 'lib/vaulted_billing/credit_card.rb', line 39

def cvv_number
  @cvv_number
end

#expires_onObject

The date on which the credit card expires.



40
41
42
# File 'lib/vaulted_billing/credit_card.rb', line 40

def expires_on
  @expires_on
end

#first_nameObject

The first name of the cardholder.



41
42
43
# File 'lib/vaulted_billing/credit_card.rb', line 41

def first_name
  @first_name
end

#last_nameObject

The last name of the cardholder.



42
43
44
# File 'lib/vaulted_billing/credit_card.rb', line 42

def last_name
  @last_name
end

#localityObject

The “city” of the address on the card.



43
44
45
# File 'lib/vaulted_billing/credit_card.rb', line 43

def locality
  @locality
end

#phoneObject

A phone number for the cardholder.



44
45
46
# File 'lib/vaulted_billing/credit_card.rb', line 44

def phone
  @phone
end

#postal_codeObject

The postal code (zipcode) for the card.



45
46
47
# File 'lib/vaulted_billing/credit_card.rb', line 45

def postal_code
  @postal_code
end

#regionObject

The “state” of the address on the card.



46
47
48
# File 'lib/vaulted_billing/credit_card.rb', line 46

def region
  @region
end

#street_addressObject

The house number and street name of the card address.



47
48
49
# File 'lib/vaulted_billing/credit_card.rb', line 47

def street_address
  @street_address
end

#vault_idObject

The unique, gateway-generated identifier for this credit card.



48
49
50
# File 'lib/vaulted_billing/credit_card.rb', line 48

def vault_id
  @vault_id
end

Instance Method Details

#==(o) ⇒ Object



63
64
65
# File 'lib/vaulted_billing/credit_card.rb', line 63

def ==(o)
  self.attributes == o.attributes
end

#attributesObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vaulted_billing/credit_card.rb', line 67

def attributes
  {
    :vault_id => vault_id,
    :currency => currency,
    :card_number => card_number,
    :cvv_number => cvv_number,
    :expires_on => expires_on,
    :first_name => first_name,
    :last_name => last_name,
    :street_address => street_address,
    :locality => locality,
    :region => region,
    :postal_code => postal_code,
    :country => country,
    :phone => phone
  }
end

#name_on_cardObject



89
90
91
# File 'lib/vaulted_billing/credit_card.rb', line 89

def name_on_card
  [first_name, last_name].compact.join(" ")
end

#to_vaulted_billingObject



93
# File 'lib/vaulted_billing/credit_card.rb', line 93

def to_vaulted_billing; self; end