Class: Bodega::PaymentMethod::Stripe

Inherits:
Base
  • Object
show all
Defined in:
lib/bodega/payment_method/stripe.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #order

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Optional

#options

Constructor Details

This class inherits a constructor from Bodega::PaymentMethod::Base

Instance Method Details

#checkout_url(success_url, cancel_url, params = {}) ⇒ Object

Redirect to /cart/complete?stripe=tokenToVerifyPayment



10
11
12
13
14
15
16
17
18
19
# File 'lib/bodega/payment_method/stripe.rb', line 10

def checkout_url(success_url, cancel_url, params = {})
  if params[:stripe]
    uri = Addressable::URI.heuristic_parse(success_url)
    uri.query_hash[:stripe] = params[:stripe]
  else
    uri = Addressable::URI.heuristic_parse(cancel_url)
    uri.query_hash[:stripe] = 'yes'
  end
  uri.to_s
end

#complete!(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/bodega/payment_method/stripe.rb', line 21

def complete!(options = {})
  ::Stripe.api_key = Bodega.config.stripe.secret_key
  charge = ::Stripe::Charge.create(
    amount: order.total_cents,
    currency: 'usd',
    card: options[:stripe],
    description: order.summary
  )
  charge.id
end

#shipping?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/bodega/payment_method/stripe.rb', line 32

def shipping?
  false
end