Class: TresDelta::CreditCard
- Inherits:
-
Object
- Object
- TresDelta::CreditCard
- Defined in:
- lib/tres_delta/credit_card.rb,
lib/tres_delta/credit_card/address.rb
Defined Under Namespace
Classes: Address
Instance Attribute Summary collapse
-
#billing_address ⇒ Object
readonly
Returns the value of attribute billing_address.
-
#customer ⇒ Object
readonly
Returns the value of attribute customer.
-
#expiration_month ⇒ Object
Returns the value of attribute expiration_month.
-
#expiration_year ⇒ Object
Returns the value of attribute expiration_year.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#security_code ⇒ Object
readonly
Returns the value of attribute security_code.
-
#token ⇒ Object
Returns the value of attribute token.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #has_security_code? ⇒ Boolean
-
#initialize(params = {}) ⇒ CreditCard
constructor
A new instance of CreditCard.
- #save ⇒ Object
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_address ⇒ Object (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 |
#customer ⇒ Object (readonly)
Returns the value of attribute customer.
3 4 5 |
# File 'lib/tres_delta/credit_card.rb', line 3 def customer @customer end |
#expiration_month ⇒ Object
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_year ⇒ Object
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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/tres_delta/credit_card.rb', line 3 def name @name end |
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
3 4 5 |
# File 'lib/tres_delta/credit_card.rb', line 3 def nickname @nickname end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/tres_delta/credit_card.rb', line 3 def number @number end |
#security_code ⇒ Object (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 |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/tres_delta/credit_card.rb', line 5 def token @token end |
#type ⇒ Object (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
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
28 29 30 |
# File 'lib/tres_delta/credit_card.rb', line 28 def has_security_code? security_code.to_s.strip.size > 0 end |
#save ⇒ Object
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 |