Sha256: 6cde65677e0fcb49866060d0306f2ee62e3d23eb88c1b75188f523d31537092a

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

module Spree
  CheckoutController.class_eval do
    before_filter :confirm_skrill, :only => [:update]

    def skrill_return

      unless @order.payments.where(:source_type => 'Spree::SkrillTransaction').present?
        payment_method = PaymentMethod.find(params[:payment_method_id])
        skrill_transaction = SkrillTransaction.new

        payment = @order.payments.create({:amount => @order.total,
                                         :source => skrill_transaction,
                                         :payment_method => payment_method},
                                         :without_protection => true)
        payment.started_processing!
        payment.pend!
      end

      @order.update_attributes({:state => "complete", :completed_at => Time.now}, :without_protection => true)

      until @order.state == "complete"
        if @order.next!
          @order.update!
          state_callback(:after)
        end
      end

      @order.finalize!

      flash.notice = Spree.t(:order_processed_successfully)
      redirect_to completion_route
    end

    def skrill_cancel
      flash[:error] = Spree.t(:payment_has_been_cancelled)
      redirect_to edit_order_path(@order)
    end

    private
    def confirm_skrill
      return unless (params[:state] == "payment") && params[:order][:payments_attributes]

      payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
      if payment_method.kind_of?(BillingIntegration::Skrill::QuickCheckout)
        #TODO confirming payment method
        redirect_to edit_order_checkout_url(@order, :state => 'payment'),
                    :notice => Spree.t(:complete_skrill_checkout)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_gateway-2.2.1 app/controllers/spree/checkout_controller_decorator.rb