Sha256: 324db4b5cca8b7ec4d3a499e74f79468b4905ef9cf3018ab17d383d06c84059b

Contents?: true

Size: 975 Bytes

Versions: 21

Compression:

Stored size: 975 Bytes

Contents

module CatarsePagarme
  class CreditCardTransaction < TransactionBase

    def charge!
      save_card = self.attributes.delete(:save_card)

      self.transaction = PagarMe::Transaction.new(self.attributes)

      payment.update_attributes({
        gateway: 'Pagarme',
        payment_method: payment_method
      })
      payment.save!

      self.transaction.charge

      VerifyPagarmeWorker.perform_in(5.minutes, payment.key)

      change_payment_state

      if self.transaction.status == 'refused'
        raise ::PagarMe::PagarMeError.new(I18n.t('projects.contributions.edit.transaction_error'))
      end

      save_user_credit_card if save_card
      self.transaction
    end

    def save_user_credit_card
      card = self.transaction.card

      credit_card = self.user.credit_cards.find_or_initialize_by(card_key: card.id)
      credit_card.last_digits = card.last_digits
      credit_card.card_brand = card.brand

      credit_card.save!
    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
catarse_pagarme-2.10.6 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.5 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.4 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.2 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.1 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.0 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.13 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.12 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.11 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.10 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.9 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.8 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.7 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.6 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.5 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.4 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.3 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.2 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.9.0 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.8.10 app/models/catarse_pagarme/credit_card_transaction.rb