Class: DiscoApp::ChargesController

Inherits:
ApplicationController
  • Object
show all
Includes:
DiscoApp::Concerns::AuthenticatedController
Defined in:
app/controllers/disco_app/charges_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject

Attempt to activate a charge after a user has accepted or declined it. Redirect to the main application’s root URL immediately afterwards - if the charge wasn’t accepted, the flow will start again.



26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/disco_app/charges_controller.rb', line 26

def activate
  # First attempt to find a matching charge.
  if(charge = @subscription.charges.find_by(id: params[:id], shopify_id: params[:charge_id])).nil?
    redirect_to action: :new and return
  end
  if DiscoApp::ChargesService.activate(@shop, charge)
    redirect_to main_app.root_url
  else
    redirect_to action: :new
  end
end

#createObject

Attempt to create a new charge for the logged in shop and selected subscription. If successful, redirect to the (external) charge confirmation URL. If it fails, redirect back to the new charge page.



15
16
17
18
19
20
21
# File 'app/controllers/disco_app/charges_controller.rb', line 15

def create
  if(charge = DiscoApp::ChargesService.create(@shop, @subscription)).nil?
    redirect_to action: :new
  else
    redirect_to charge.confirmation_url
  end
end

#newObject

Display a “pre-charge” page, giving the opportunity to explain why a charge needs to be made.



9
10
# File 'app/controllers/disco_app/charges_controller.rb', line 9

def new
end