Module: StripeWrapper

Defined in:
lib/stripe_wrapper.rb,
lib/stripe_wrapper/engine.rb,
lib/stripe_wrapper/version.rb,
app/models/stripe_wrapper/charge.rb,
app/models/stripe_wrapper/customer.rb,
app/jobs/stripe_wrapper/application_job.rb,
app/helpers/stripe_wrapper/customers_helper.rb,
lib/stripe_wrapper/main_app_route_delegator.rb,
app/models/stripe_wrapper/application_record.rb,
app/mailers/stripe_wrapper/application_mailer.rb,
app/helpers/stripe_wrapper/stripe_wrapper_helper.rb,
app/controllers/stripe_wrapper/charges_controller.rb,
app/controllers/stripe_wrapper/customers_controller.rb,
app/controllers/stripe_wrapper/application_controller.rb,
lib/generators/stripe_wrapper/install/install_generator.rb,
lib/generators/stripe_wrapper/file_copy/file_copy_generator.rb

Defined Under Namespace

Modules: CustomersHelper, MainAppRouteDelegator, StripeWrapperHelper Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Charge, ChargesController, Customer, CustomersController, Engine, FileCopyGenerator, InstallGenerator

Constant Summary collapse

VERSION =
'0.1.6'

Class Method Summary collapse

Class Method Details

.create_charge(customer = nil, source = nil, amount = nil, currency = 'clp', metadata = {}, description = '') ⇒ Object

Source is either a customer or a token



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stripe_wrapper.rb', line 8

def self.create_charge(customer=nil,source=nil,amount=nil,currency='clp',={},description='')
  #Metadata must be a hash. Example: :metadata => {'order_id' => '6735'}
  return false if amount.blank?()
  Stripe::Charge.create({
    amount: amount,
    currency: currency,
    customer: customer,
    source: source, # obtained with Stripe.js
    description: description,
    metadata: 
  }
  # , { idempotency_key: "oSTGoYvkC1kaczHw"}
  )
end

.create_customer(token, user, description = '') ⇒ Object



23
24
25
26
27
28
29
# File 'lib/stripe_wrapper.rb', line 23

def self.create_customer(token,user,description='')
  Stripe::Customer.create(
   :description => description,
   :email => user.email,
   :source => token # obtained with Stripe.js
  )
end

.get_customer(user) ⇒ Object



31
32
33
34
# File 'lib/stripe_wrapper.rb', line 31

def self.get_customer(user)
  customer = StripeCustomer.find_by_user_id(user.id)
  customer = Customer.parse(Stripe::Customer.retrieve(customer.stripe_id)) rescue nil #TODO implement customer model
end

.update_customer(user, customer_params) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/stripe_wrapper.rb', line 35

def self.update_customer(user,customer_params)
  customer = StripeCustomer.find_by_user_id(user.id)
  stripe_customer = Stripe::Customer.retrieve(customer.stripe_id)
  customer_params.each do |param|
    stripe_customer.send("#{param[0]}=",param[1])
  end
  stripe_customer.save

end