Sha256: c89c50a236bc3fa3582b5faceae98e7c18730f53210081aa8875f85419b0c3ac

Contents?: true

Size: 914 Bytes

Versions: 4

Compression:

Stored size: 914 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

      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

4 entries across 4 versions & 1 rubygems

Version Path
catarse_pagarme-2.7.5 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.7.4 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.7.3 app/models/catarse_pagarme/credit_card_transaction.rb
catarse_pagarme-2.7.2 app/models/catarse_pagarme/credit_card_transaction.rb