Sha256: 3cb10808dee0a173366d49f869d94f33b061e24fcc558cce750d30d4f30fe7ba

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module CatarsePagarme
  class TransactionBase
    attr_accessor :attributes, :payment,
      :transaction, :user

    def initialize(attributes, payment)
      self.attributes = attributes
      self.payment = payment
      self.user = payment.user
    end

    def change_payment_state
      self.payment.update_attributes(attributes_to_payment)
      self.payment.save!
      delegator.update_fee
      self.payment.payment_notifications.create(contribution_id: self.payment.contribution_id, extra_data: self.transaction.to_json)
      delegator.change_status_by_transaction(self.transaction.status)
    end

    def payment_method
      PaymentType::CREDIT_CARD
    end

    def attributes_to_payment
      {
        payment_method: payment_method,
        gateway_id: self.transaction.id,
        gateway: 'Pagarme',
        gateway_data: self.transaction.to_json,
        installments: (self.transaction.installments || 1),
        installment_value: (delegator.value_for_installment(self.transaction.installments || 0) / 100.0).to_f
      }
    end

    def delegator
      self.payment.pagarme_delegator
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
catarse_pagarme-2.6.3 app/models/catarse_pagarme/transaction_base.rb
catarse_pagarme-2.6.2 app/models/catarse_pagarme/transaction_base.rb
catarse_pagarme-2.6.1 app/models/catarse_pagarme/transaction_base.rb
catarse_pagarme-2.6.0 app/models/catarse_pagarme/transaction_base.rb