Class: Stripe::CheckoutsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/boring/payments/stripe/install/templates/controllers/stripe/checkouts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/boring/payments/stripe/install/templates/controllers/stripe/checkouts_controller.rb', line 4

def create
  begin
    @stripe_session = Stripe::Checkout::Session.create(checkout_payload)

    respond_to :js
  rescue Stripe::CardError => e
    puts "Status is: #{e.http_status}"
    puts "Type is: #{e.error.type}"
    puts "Charge ID is: #{e.error.charge}"
    # The following fields are optional
    puts "Code is: #{e.error.code}" if e.error.code
    puts "Decline code is: #{e.error.decline_code}" if e.error.decline_code
    puts "Param is: #{e.error.param}" if e.error.param
    puts "Message is: #{e.error.message}" if e.error.message
  rescue Stripe::RateLimitError => e
    # Too many requests made to the API too quickly
  rescue Stripe::InvalidRequestError => e
    # Invalid parameters were supplied to Stripe's API
  rescue Stripe::AuthenticationError => e
    # Authentication with Stripe's API failed
    # (maybe you changed API keys recently)
  rescue Stripe::APIConnectionError => e
    # Network communication with Stripe failed
  rescue Stripe::StripeError => e
    # Display a very generic error to the user, and maybe send
    # yourself an email
  rescue => e
    # Something else happened, completely unrelated to Stripe
  end
end

#showObject



35
36
37
# File 'lib/generators/boring/payments/stripe/install/templates/controllers/stripe/checkouts_controller.rb', line 35

def show
  render
end