Class: StripeHelper::StripeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/stripe_helper/stripe_controller.rb

Instance Method Summary collapse

Instance Method Details

#handleObject



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 'app/controllers/stripe_helper/stripe_controller.rb', line 5

def handle
  # Determine the amount to charge (or if the token is invalid)
  amount = do_call(:charge_amount, self, params[:token])

  # If the amount is invalid (ie: token is invalid), then we fail
  if amount == nil || !amount.is_a?(Integer)
    redirect_to do_call(:charge_failure, self, params[:token],
                        'Invalid charge; potential security error.')
    return
  end

  # Get the credit card details submitted by the form
  token = params[:stripeToken]

  # Set options for charge
  opts = {
    amount:      amount,
    currency:    "cad",
    description: params[:desc]
  }

  ret = StripeHelper.charge_from_token(token, opts)
  if ret
    redirect_to do_call(:charge_success, self, params[:token], token)
  else
    redirect_to do_call(:charge_failure, self, params[:token],
                        'Card declined.')
  end
end