Sha256: d00d07a29d9f63ccaff926bcc887b74e149f9b6afc671d4d689bf4abe0664156

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

module Spree
  class PagseguroController < Spree::StoreController
    skip_before_action :verify_authenticity_token, only: :notify

    def callback
      @order = Spree::Order.find_by_number(params[:order])

      pagseguro_transaction = Spree::PagseguroTransaction.find_by_order_id(@order.id.to_s)
      pagseguro_transaction.update_attribute :status, 'waiting'

      redirect_to spree.order_path(@order)
    end

    def notify
      notification = Spree::PagseguroTransaction.update_last_transaction(params)
      payment_method = Spree::PaymentMethod.where(type: 'Spree::BillingIntegration::Pagseguro::Checkout').first

      @order = Spree::Order.find(notification.id)
      payment = @order.payments.where(:state => "pending",
                                      :payment_method_id => payment_method.id).last

      if notification.approved?
        payment.complete!
      else
        payment.failure!
      end

      render nothing: true, head: :ok
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_pagseguro-2.1.3 app/controllers/spree/pagseguro_controller.rb