Sha256: 97ef983113155b7f6f8b04d74bb17c9fe549e1e491a82e40c8c488dd21aa90a4

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 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.purchase_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

14 entries across 14 versions & 1 rubygems

Version Path
effective_orders-3.2.3 app/controllers/effective/providers/cheque.rb
effective_orders-3.2.2 app/controllers/effective/providers/cheque.rb
effective_orders-3.2.1 app/controllers/effective/providers/cheque.rb
effective_orders-3.2.0 app/controllers/effective/providers/cheque.rb
effective_orders-3.1.7 app/controllers/effective/providers/cheque.rb
effective_orders-3.1.6 app/controllers/effective/providers/cheque.rb
effective_orders-3.1.4 app/controllers/effective/providers/cheque.rb
effective_orders-3.1.3 app/controllers/effective/providers/cheque.rb
effective_orders-3.1.0 app/controllers/effective/providers/cheque.rb
effective_orders-3.0.4 app/controllers/effective/providers/cheque.rb
effective_orders-3.0.3 app/controllers/effective/providers/cheque.rb
effective_orders-3.0.2 app/controllers/effective/providers/cheque.rb
effective_orders-3.0.1 app/controllers/effective/providers/cheque.rb
effective_orders-3.0.0 app/controllers/effective/providers/cheque.rb