Class: Supercharged::ChargesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/supercharged/charges_controller.rb

Instance Method Summary collapse

Instance Method Details

#completeObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/supercharged/charges_controller.rb', line 30

def complete
  params.require(:token)

  @charge = Charge.with_token(params[:token])

  if @charge
    @charge.complete(params)

    redirect_to root_url
  else
    head :not_found
  end
end

#createObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/supercharged/charges_controller.rb', line 6

def create
  charge = Charge.new(charge_params)
  charge.user = current_user

  if charge.save
    render json: { charge: charge.as_json(only: [:id]) }
  else
    render json: { errors: charge.errors }, status: :unprocessable_entity
  end
end

#newObject



3
4
# File 'app/controllers/supercharged/charges_controller.rb', line 3

def new
end

#setup_purchaseObject

For example for PayPal Express, which requires getting token before purchase action.



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/supercharged/charges_controller.rb', line 18

def setup_purchase
  charge = Charge.find(params[:charge_id])

  token = charge.setup_purchase(
    ip: request.remote_ip,
    return_url: complete_charges_url,
    cancel_return_url: new_charge_url
  )

  redirect_to charge.gateway.redirect_url_for(token)
end