Module: Shoppe::Stripe::OrderExtensions

Defined in:
lib/shoppe/stripe/order_extensions.rb

Instance Method Summary collapse

Instance Method Details

#accept_stripe_token(token) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/shoppe/stripe/order_extensions.rb', line 5

def accept_stripe_token(token)
  if token =~ /\Atok/
    customer = ::Stripe::Customer.create({:description => "Customer for order #{number}", :card => token}, Shoppe.settings.stripe_api_key)
    self.properties['stripe_customer_token'] = customer.id
    self.save
  elsif token =~ /\Acus/ && self.properties[:stripe_customer_token] != token
    self.properties['stripe_customer_token'] = token
    self.save
  elsif self.properties['stripe_customer_token'] && self.properties['stripe_customer_token'] =~ /\Acus/
    true
  else
    false
  end
end