Sha256: e699b76403d60e65cd5df93be2e77a90d99121662aaca9ba468d5a5a42888632

Contents?: true

Size: 907 Bytes

Versions: 61

Compression:

Stored size: 907 Bytes

Contents

module CatarsePagarme
  class SaveCreditCardTransaction < TransactionBase
    def charge!
      installments = self.attributes.delete(:installments)
      amount = self.attributes.delete(:amount)

      self.subscription = PagarMe::Subscription.new(self.attributes)
      self.subscription.create

      self.subscription.charge(amount, installments)
      self.transaction = subscription.current_transaction

      save_user_credit_card
      change_contribution_state


      self.transaction
    end

    protected

    def save_user_credit_card
      credit_cards = self.user.credit_cards
      unless credit_cards.where(subscription_id: self.subscription.id.to_s).present?
        credit_cards.create!({
          last_digits: self.subscription.card_last_digits,
          card_brand: self.subscription.card_brand,
          subscription_id: self.subscription.id
        })
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
catarse_pagarme-2.4.10 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.9 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.8 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.7 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.6 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.5 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.4 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.3 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.2 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.5.3 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.5.2 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.1 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.5.1 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.5.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.4.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.3.10 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.4.9 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.3.9 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.4.8 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.3.8 app/models/catarse_pagarme/save_credit_card_transaction.rb