Sha256: d98104742a2b9cd3d5f44d54535b867de5c65a688f92a9fcff9ad1d8c0cb2064

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

module CatarsePagarme
  class CreditCardTransaction < TransactionBase

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

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

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

        raise ::PagarMe::PagarMeError.new(
          payment.errors.messages.values.flatten.to_sentence)
      end

      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

10 entries across 10 versions & 1 rubygems

Version Path
catarse_pagarme-2.13.0 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.12.0 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.11.0 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.15 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.14 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.13 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.12 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.11 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.10 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.10.9 app/models/catarse_pagarme/credit_card_transaction.rb