Sha256: b9cffe83c037ccdd180fb39c1a9df4e3e3cb3d02206c64e5d43e9a72dcd82c95

Contents?: true

Size: 655 Bytes

Versions: 61

Compression:

Stored size: 655 Bytes

Contents

module CatarsePagarme
  class SubscriptionTransaction < TransactionBase
    def charge!
      validate_subscription_id

      self.subscription = PagarMe::Subscription.find_by_id(self.attributes[:subscription_id])
      self.subscription.charge(self.attributes[:amount], self.attributes[:installments])
      self.transaction = subscription.current_transaction

      change_contribution_state

      self.transaction
    end

    def validate_subscription_id
      unless self.user.credit_cards.where(subscription_id: self.attributes[:subscription_id]).present?
        raise PagarMe::PagarMeError.new('invalid subscription')
      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/subscription_transaction.rb
catarse_pagarme-2.4.9 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.8 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.7 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.6 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.5 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.4 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.3 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.2 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-1.5.3 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-1.5.2 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.1 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-1.5.1 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-1.5.0 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.4.0 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.3.10 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-1.4.9 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.3.9 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-1.4.8 app/models/catarse_pagarme/subscription_transaction.rb
catarse_pagarme-2.3.8 app/models/catarse_pagarme/subscription_transaction.rb