Class: StripeWrapper::Customer

Inherits:
ApplicationRecord show all
Defined in:
app/models/stripe_wrapper/customer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_stripe_customer(stripe_customer) ⇒ Object



15
16
17
# File 'app/models/stripe_wrapper/customer.rb', line 15

def self.build_stripe_customer(stripe_customer)
  return Customer.new(Customer.white_params(stripe_customer))
end

.find_or_create_customer(token, user) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/stripe_wrapper/customer.rb', line 19

def self.find_or_create_customer(token,user)
  customer = Customer.get_customer(user)
  
  return customer if customer.present?()

  # If the customer is not present, we create it

  stripe_customer = StripeWrapper.create_customer(token,user)

  customer = Customer.build_stripe_customer(stripe_customer)

  customer.customer_id = stripe_customer.id
  customer.user_id = user.id

  customer.save

  return customer
end

.get_customer(user) ⇒ Object



11
12
13
# File 'app/models/stripe_wrapper/customer.rb', line 11

def self.get_customer(user)
  Customer.find_by_user_id(user.id) rescue nil
end

Instance Method Details

#process_new_charge(amount, metadata = {}, currency = 'clp', description = '') ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/stripe_wrapper/customer.rb', line 38

def process_new_charge(amount,={},currency='clp',description='')
  begin
    stripe_charge = StripeWrapper.create_charge(self.customer_id,nil,amount,currency,,description)
    charge = Charge.build_stripe_charge(stripe_charge)
    charge.customer_id = self.id
    if charge.save
      return charge        
    else
      return nil
    end
  end
end

#to_sObject



7
8
9
# File 'app/models/stripe_wrapper/customer.rb', line 7

def to_s
  self.user.to_s
end