Class: Colt::CreditCard

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

Class Method Summary collapse

Class Method Details

.add(stripe_customer_id, stripe_token) ⇒ Object

Adds a new credit card as the active default card for an existing customer



7
8
9
10
11
12
13
# File 'lib/colt/credit_card.rb', line 7

def self.add(stripe_customer_id, stripe_token)
  customer = Stripe::Customer.retrieve(stripe_customer_id)
  card = customer.sources.create(source: stripe_token)
  customer.default_card = card.id
  customer.save
  card
end

.save(stripe_token, description) ⇒ Object

Create a new credit card for a customer



18
19
20
# File 'lib/colt/credit_card.rb', line 18

def self.save(stripe_token, description)
  Stripe::Customer.create(card: stripe_token, description: description)
end

.update_expiration_date(stripe_customer_id, card_month, card_year) ⇒ Object

Update expiration date of an existing credit card for a customer



25
26
27
28
29
30
31
# File 'lib/colt/credit_card.rb', line 25

def self.update_expiration_date(stripe_customer_id, card_month, card_year)
  customer = Stripe::Customer.retrieve(stripe_customer_id)
  card = customer.sources.first
  card.exp_month = card_month
  card.exp_year = card_year
  card.save      
end