Sha256: 59d3123a1371e275213b70f579868d5216b4e25518aca769595b3e2325e82cc0

Contents?: true

Size: 1.51 KB

Versions: 48

Compression:

Stored size: 1.51 KB

Contents

class DiscoApp::ChargesController < ApplicationController
  include DiscoApp::Concerns::AuthenticatedController

  skip_before_action :check_active_charge
  before_action :find_subscription

  # Display a "pre-charge" page, giving the opportunity to explain why a charge
  # needs to be made.
  def new
  end

  # 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.
  def create
    if(charge = DiscoApp::ChargesService.create(@shop, @subscription)).nil?
      redirect_to action: :new
    else
      redirect_to charge.confirmation_url
    end
  end

  # 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.
  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

  private

    def find_subscription
      @subscription = @shop.subscriptions.find_by_id!(params[:subscription_id])
      unless @subscription.requires_active_charge? and not @subscription.active_charge?
        redirect_to main_app.root_url
      end
    end

end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
disco_app-0.16.1.pre.sidekiq.pre.6.pre.release app/controllers/disco_app/charges_controller.rb
disco_app-0.8.8 app/controllers/disco_app/charges_controller.rb
disco_app-0.8.9 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.0 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.1 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.2 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.3 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.4 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.5 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.6 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.7 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.8 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.9 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.10 app/controllers/disco_app/charges_controller.rb
disco_app-0.9.11 app/controllers/disco_app/charges_controller.rb
disco_app-0.10.0 app/controllers/disco_app/charges_controller.rb
disco_app-0.10.1 app/controllers/disco_app/charges_controller.rb
disco_app-0.10.2 app/controllers/disco_app/charges_controller.rb
disco_app-0.10.3 app/controllers/disco_app/charges_controller.rb
disco_app-0.10.4 app/controllers/disco_app/charges_controller.rb