Sha256: 1777951a8f54534061768f9bedddb9b87e9ecc3c7972677210a3a61abe29c141

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 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)
      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_service_fee: delegator.get_fee(payment_method, self.transaction.acquirer_name),
        payment_id: self.transaction.id,
        payment_method: 'Pagarme',
        slip_url: self.transaction.boleto_url,
        installments: (self.transaction.installments || 1)
      }
    end

    def delegator
      self.contribution.pagarme_delegator
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
catarse_pagarme-2.0.3 app/models/catarse_pagarme/transaction_base.rb
catarse_pagarme-2.0.2 app/models/catarse_pagarme/transaction_base.rb
catarse_pagarme-2.0.1 app/models/catarse_pagarme/transaction_base.rb
catarse_pagarme-1.1.0 app/models/catarse_pagarme/transaction_base.rb
catarse_pagarme-2.0.0 app/models/catarse_pagarme/transaction_base.rb
catarse_pagarme-1.0.1 app/models/catarse_pagarme/transaction_base.rb