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.1.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.2.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.0.3 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.0.2 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.0.1 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.1.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-2.0.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.0.1 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-1.0.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.8 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.7 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.6 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.5 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.4 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.2.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.3 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.2 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.1 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.1.0 app/models/catarse_pagarme/save_credit_card_transaction.rb
catarse_pagarme-0.0.2 app/models/catarse_pagarme/save_credit_card_transaction.rb