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
# File 'lib/bodega/payment_method/stripe.rb', line 10

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

#complete!(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/bodega/payment_method/stripe.rb', line 16

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