Sha256: dc8c829e54f1f1374843f2799a4e672f1b9597cd1fbefd8fe248599c6d03d354

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module CatarsePagarme
  class TransactionBase
    attr_accessor :attributes, :contribution,
      :transaction, :user, :subscription

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

    def change_contribution_state
      self.contribution.update_attributes(attributes_to_contribution)
      delegator.update_fee
      self.contribution.payment_notifications.create(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_contribution
      {
        payment_choice: payment_method,
        payment_id: self.transaction.id,
        payment_method: 'Pagarme',
        slip_url: self.transaction.boleto_url,
        installments: (self.transaction.installments || 1),
        installment_value: (delegator.value_for_installment(self.transaction.installments || 0) / 100.0).to_f
      }
    end

    def delegator
      self.contribution.pagarme_delegator
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
catarse_pagarme-2.4.10 app/models/catarse_pagarme/transaction_base.rb