def transition_state(state)
      authorize @contribution
      @initiative = @contribution.initiative
      @user = @contribution.user
      state = state.to_sym
      transition = @contribution.transition_by_state(state)
      initial_state = @contribution.state_name
      resource_name = @contribution.class.model_name.human
      if @contribution.send("can_#{transition}?")
        begin
          if @contribution.state_on_gateway != state
            if @contribution.update_state_on_gateway!(state)
              @contribution.send("#{transition}!")
            else
              flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
            end
          else
            @contribution.send("#{transition}!")
          end
        rescue
          flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
        end
      else
        flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
      end
      if flash[:alert].present?
        render 'initiatives/contributions/show'
      else
        if initial_state == :pending
          flash[:notice] = t('flash.actions.create.notice', resource_name: resource_name)
        else
          flash[:notice] = t('flash.actions.update.notice', resource_name: resource_name)
        end
        redirect_to initiative_contribution_path(@contribution.initiative.id, @contribution)
      end
    end
def transition_state(state)
      authorize @contribution
      @initiative = @contribution.initiative
      @user = @contribution.user
      state = state.to_sym
      transition = @contribution.transition_by_state(state)
      initial_state = @contribution.state_name
      resource_name = @contribution.class.model_name.human
      if @contribution.send("can_#{transition}?")
        begin
          if @contribution.state_on_gateway != state
            if @contribution.update_state_on_gateway!(state)
              @contribution.send("#{transition}!")
            else
              flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
            end
          else
            @contribution.send("#{transition}!")
          end
        rescue
          flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
        end
      else
        flash[:alert] = t('flash.actions.update.alert', resource_name: resource_name)
      end
      if flash[:alert].present?
        render 'initiatives/contributions/show'
      else
        if initial_state == :pending
          flash[:notice] = t('flash.actions.create.notice', resource_name: resource_name)
        else
          flash[:notice] = t('flash.actions.update.notice', resource_name: resource_name)
        end
        redirect_to initiative_contribution_path(@contribution.initiative.id, @contribution)
      end
    end
This method authorizes @contribution, checks if the contribution can be transitioned to the desired state, calls Contribution#update_state_on_gateway!, transition the contribution's state, and return the proper JSON for Unlock's AJAX calls