mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-07 01:54:16 +01:00
30 lines
946 B
Ruby
30 lines
946 B
Ruby
class WalletService
|
|
def initialize(user: nil, wallet: nil)
|
|
@user = user
|
|
@wallet = wallet
|
|
end
|
|
|
|
def credit(amount)
|
|
if @wallet.credit(amount)
|
|
transaction = WalletTransaction.create(user: @user, wallet: @wallet, transaction_type: 'credit', amount: amount)
|
|
|
|
NotificationCenter.call type: 'notify_user_wallet_is_credited',
|
|
receiver: @wallet.user,
|
|
attached_object: transaction
|
|
NotificationCenter.call type: 'notify_admin_user_wallet_is_credited',
|
|
receiver: User.admins,
|
|
attached_object: transaction
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
def debit(amount, transactable)
|
|
if @wallet.debit(amount)
|
|
WalletTransaction.create(user: @user, wallet: @wallet, transaction_type: 'debit', amount: amount, transactable: transactable)
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
end
|