class Withdrawable

Public Instance Methods

withdraw() click to toggle source

To withdraw amount.

# File app/models/withdrawable.rb, line 26
def withdraw
  if self.valid?
    user = User.find(self.user_id)
    if Payment.withdraw(user, amount, description)
      amount_payable = user.withdrawable_balance.amount_cents - self.amount.cents
      AccountBalance.debit(user, self, false, amount_payable, account = nil)
    end
  end
end
withdrawable_amount() click to toggle source

Returns the amount which user can withdraw.

# File app/models/withdrawable.rb, line 17
def withdrawable_amount
  user = User.find(self.user_id)
  unless self.amount <= user.withdrawable_amount
    self.errors.add :amount, "should be equal to or less than #{user.withdrawable_amount}"
    return false
  end
end