Skip to content

Commit

Permalink
Create transaction.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Sep 20, 2024
1 parent 397022a commit 19e4f81
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions global_business/business/models/transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Transaction < ApplicationRecord
# Encryption and decryption of sensitive data
encrypts :amount

# Associations
belongs_to :account
belongs_to :user

# Validations
validates :amount, presence: true, numericality: { greater_than: 0.01, less_than: 100000.00 }
validates :transaction_type, presence: true, inclusion: { in: %w[deposit withdrawal] }

# Callbacks
before_save :hash_amount
after_create :send_transaction_email

private

def hash_amount
self.amount = Encryption.hash(self.amount)
end

def send_transaction_email
TransactionMailer.transaction_email(self).deliver_now
end
end

0 comments on commit 19e4f81

Please sign in to comment.