module StripeWrapper

Constants

VERSION

Public Class Methods

create_charge(customer=nil,source=nil,amount=nil,currency='clp',metadata={},description='') click to toggle source

Source is either a customer or a token

# File lib/stripe_wrapper.rb, line 8
def self.create_charge(customer=nil,source=nil,amount=nil,currency='clp',metadata={},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: metadata
  }
  # , { idempotency_key: "oSTGoYvkC1kaczHw"}
  )
end
create_customer(token,user,description='') click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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