Class: ReservationRefundGuarantee
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ReservationRefundGuarantee
- Extended by:
- Enumerize
- Defined in:
- app/models/reservation_refund_guarantee.rb
Overview
Schema Information
Table name: reservation_refund_guarantees
id :bigint not null, primary key
refund_currency :string(191) default("THB")
refund_fee_cents :integer default(0), not null
refundable_amount_cents :integer default(0), not null
refundable_until :datetime
status :string(191)
created_at :datetime not null
updated_at :datetime not null
reservation_id :integer
Indexes
index_reservation_refund_guarantees_on_refundable_until (refundable_until)
index_reservation_refund_guarantees_on_reservation_id (reservation_id)
index_reservation_refund_guarantees_on_status (status)
Foreign Keys
fk_rails_... (reservation_id => reservations.id)
Constant Summary collapse
- STATUS_PENDING =
Constants
:pending- STATUS_CLAIMED =
:claimed- STATUS_EXPIRED =
:expired- CANCEL_REASON =
'refund guarantee'.freeze
Instance Method Summary collapse
-
#can_claim_refund? ⇒ Boolean
Check if refund guarantee can be claimed Refund can be claimed if: 1.
-
#formatted_refundable_until ⇒ String
Get formatted refundable_until in restaurant's local time zone.
-
#mark_as_claimed! ⇒ Boolean
Mark refund guarantee as claimed This should be called when user successfully claims the refund.
-
#mark_as_expired! ⇒ Boolean
Mark refund guarantee as expired This can be called by a background job to update expired refund guarantees.
-
#refund_period_expired? ⇒ Boolean
Check if refund period has expired.
-
#status_as_symbol ⇒ Symbol
Get refund guarantee status as symbol.
Methods inherited from ApplicationRecord
Instance Method Details
#can_claim_refund? ⇒ Boolean
Check if refund guarantee can be claimed Refund can be claimed if:
-
Status is pending
-
Current time is before refundable_until deadline
Note: refundable_until is stored in UTC, using Time.current.utc for explicit UTC comparison
69 70 71 72 73 74 |
# File 'app/models/reservation_refund_guarantee.rb', line 69 def can_claim_refund? return false if status_as_symbol != STATUS_PENDING return false if refundable_until.blank? Time.current.utc < refundable_until end |
#formatted_refundable_until ⇒ String
Get formatted refundable_until in restaurant's local time zone
55 56 57 58 59 60 |
# File 'app/models/reservation_refund_guarantee.rb', line 55 def formatted_refundable_until restaurant_tz = reservation.restaurant.time_zone || HungryHub::Time::DEFAULT_ZONE local_time = refundable_until.in_time_zone(restaurant_tz) local_time.strftime('%A, %-d %B %Y at %H:%M') end |
#mark_as_claimed! ⇒ Boolean
Mark refund guarantee as claimed This should be called when user successfully claims the refund
90 91 92 |
# File 'app/models/reservation_refund_guarantee.rb', line 90 def mark_as_claimed! update!(status: STATUS_CLAIMED) end |
#mark_as_expired! ⇒ Boolean
Mark refund guarantee as expired This can be called by a background job to update expired refund guarantees
98 99 100 |
# File 'app/models/reservation_refund_guarantee.rb', line 98 def mark_as_expired! update!(status: STATUS_EXPIRED) end |
#refund_period_expired? ⇒ Boolean
Check if refund period has expired
Note: refundable_until is stored in UTC, using Time.current.utc for explicit UTC comparison
80 81 82 83 84 |
# File 'app/models/reservation_refund_guarantee.rb', line 80 def refund_period_expired? return false if refundable_until.blank? Time.current.utc >= refundable_until end |
#status_as_symbol ⇒ Symbol
Get refund guarantee status as symbol
48 49 50 |
# File 'app/models/reservation_refund_guarantee.rb', line 48 def status_as_symbol status.to_sym end |