Class: Spree::PagseguroController

Inherits:
StoreController
  • Object
show all
Defined in:
app/controllers/spree/pagseguro_controller.rb

Instance Method Summary collapse

Instance Method Details

#confirmObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/spree/pagseguro_controller.rb', line 24

def confirm
  pagseguro_checkout = Spree::PagseguroCheckout.create! transaction_id: transaction_id

  @order.payments.create!(
    {
      :source => pagseguro_checkout,
      :amount => @order.total,
      :payment_method => payment_method
    }
  )

  unless @order.next
    flash[:error] = @order.errors.full_messages.join("\n")
    redirect_to checkout_state_path(@order.state) and return
  end

  pagseguro_checkout.process!

  if @order.completed?
    session[:order_id] = nil
    flash.notice = Spree.t(:order_processed_successfully).html_safe
    redirect_to spree.order_path(@order)
  else
    redirect_to checkout_state_path(@order.state)
  end
end

#init_transactionObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/spree/pagseguro_controller.rb', line 7

def init_transaction
  begin
    response = provider.init_transaction!

    if response.errors.any?
      flash[:error] = Spree.t('flash.payment_with_pagseguro', reasons: response.errors.join("\n"))
      redirect_to checkout_state_path(@order.state)
    else
      redirect_to response.url
    end

  rescue SocketError
    flash[:error] = Spree.t('flash.connection_failed')
    redirect_to checkout_state_path(@order.state)
  end
end

#notifyObject



51
52
53
54
55
# File 'app/controllers/spree/pagseguro_controller.rb', line 51

def notify
  checkout_worker.perform notification_code

  render nothing: true, status: 200
end