Sha256: 7959dd59e9c6f7a40411f4cd5e15c791aeb8573f9212be144dc85be17a7cdb47

Contents?: true

Size: 1.3 KB

Versions: 45

Compression:

Stored size: 1.3 KB

Contents

module Effective
  module Providers
    module Cheque
      extend ActiveSupport::Concern

      def pay_by_cheque
        @order ||= Order.find(params[:id])
        @page_title = 'Payment Required'

        EffectiveOrders.authorize!(self, :update, @order)

        @order.state = EffectiveOrders::PENDING
        @order.payment_provider = 'cheque'

        begin
          @order.save!
          @order.send_pending_order_invoice_to_buyer!

          Effective::Cart.where(user_id: @order.user_id).destroy_all

          message = "Successfully indicated order will be payed by cheque. A pending order invoice has been sent to #{@order.user.email}"

          # When posted from admin form, there will be a redirect url
          if params[:purchased_url].present?
            flash[:success] = message
            redirect_to params[:purchased_url].gsub(':id', @order.to_param.to_s)
          else
            # Otherwise this is the user flow
            flash.now[:success] = message
            render 'effective/orders/cheque/pay_by_cheque'
          end
        rescue => e
          flash[:danger] = "Unable to save your order: #{@order.errors.full_messages.to_sentence}. Please try again."
          redirect_to params[:declined_url].presence || effective_orders.order_path(@order)
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
effective_orders-4.4.1 app/controllers/effective/providers/cheque.rb
effective_orders-4.4.0 app/controllers/effective/providers/cheque.rb
effective_orders-4.3.2 app/controllers/effective/providers/cheque.rb
effective_orders-4.3.1 app/controllers/effective/providers/cheque.rb
effective_orders-4.3.0 app/controllers/effective/providers/cheque.rb
effective_orders-4.2.7 app/controllers/effective/providers/cheque.rb
effective_orders-4.2.6 app/controllers/effective/providers/cheque.rb
effective_orders-4.2.5 app/controllers/effective/providers/cheque.rb
effective_orders-4.2.4 app/controllers/effective/providers/cheque.rb
effective_orders-4.2.3 app/controllers/effective/providers/cheque.rb
effective_orders-4.2.2 app/controllers/effective/providers/cheque.rb
effective_orders-4.2.1 app/controllers/effective/providers/cheque.rb
effective_orders-4.2.0 app/controllers/effective/providers/cheque.rb
effective_orders-4.1.5 app/controllers/effective/providers/cheque.rb
effective_orders-4.1.4 app/controllers/effective/providers/cheque.rb
effective_orders-4.1.3 app/controllers/effective/providers/cheque.rb
effective_orders-4.1.2 app/controllers/effective/providers/cheque.rb
effective_orders-4.1.1 app/controllers/effective/providers/cheque.rb
effective_orders-4.1.0 app/controllers/effective/providers/cheque.rb
effective_orders-4.0.6 app/controllers/effective/providers/cheque.rb