Sha256: d00ac33a70e48fc83141026097abfb8ba7c9613a5f52a8894c9c66f18a53078d

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module Spree
  class PaymentMethod::PagSeguroMethod < PaymentMethod
    preference :email, :string
    preference :token, :string
    has_many :payments, :as => :source
    
    def actions
      %w{capture void}
    end

    # Indicates whether its possible to capture the payment
    def can_capture?(payment)
      ['checkout', 'pending'].include?(payment.state)
    end

    # Indicates whether its possible to void the payment.
    def can_void?(payment)
      payment.state != 'void'
    end

    def capture(*args)
      ActiveMerchant::Billing::Response.new(true, "", {}, {})
    end

    def void(*args)
      ActiveMerchant::Billing::Response.new(true, "", {}, {})
    end
    
    def payment_source_class
      self.class
    end

    def source_required?
      false
    end
    
    def code(payment)
      if payment.pag_seguro_payment.present?
        payment.pag_seguro_payment.code
      else
        pag_seguro_payment = Spree::PagSeguroPayment.new
        pag_seguro_payment.process!(payment)
        pag_seguro_payment.code
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_pag_seguro-1.0.6 app/models/spree/payment_method/pag_seguro_method.rb
spree_pag_seguro-1.0.5 app/models/spree/payment_method/pag_seguro_method.rb
spree_pag_seguro-1.0.4 app/models/spree/payment_method/pag_seguro_method.rb