Class: DiscoApp::ChargesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- DiscoApp::ChargesController
- Defined in:
- app/controllers/disco_app/charges_controller.rb
Instance Method Summary collapse
-
#activate ⇒ Object
Attempt to activate a charge (locally) after a user has accepted or declined it.
-
#create ⇒ Object
Attempt to create a new charge for the logged in shop and selected subscription.
-
#new ⇒ Object
Display a “pre-charge” page, giving the opportunity to explain why a charge needs to be made.
Instance Method Details
#activate ⇒ Object
Attempt to activate a charge (locally) 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.
Previously, the activation of a charge also required updating Shopify via the API, but that requirement has been removed.
See shopify.dev/changelog/auto-activation-of-charges-and-subscriptions
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/disco_app/charges_controller.rb', line 32 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) && return end if DiscoApp::ChargesService.activate(@shop, charge) redirect_to main_app.root_url else redirect_to action: :new end end |
#create ⇒ Object
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.
16 17 18 19 20 21 22 |
# File 'app/controllers/disco_app/charges_controller.rb', line 16 def create if (charge = DiscoApp::ChargesService.create(@shop, @subscription)).nil? redirect_to action: :new else redirect_to charge.confirmation_url end end |
#new ⇒ Object
Display a “pre-charge” page, giving the opportunity to explain why a charge needs to be made.
10 11 |
# File 'app/controllers/disco_app/charges_controller.rb', line 10 def new end |