Class: RefundGuaranteeClaimService
- Inherits:
-
BaseOperationService
- Object
- BaseOperationService
- RefundGuaranteeClaimService
- Includes:
- DefaultErrorContainer, ElasticAPM::SpanHelpers
- Defined in:
- app/services/refund_guarantee_claim_service.rb
Overview
Service to handle refund guarantee claim when user cancels reservation This service validates eligibility and processes the refund claim
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#reservation_id ⇒ Object
Returns the value of attribute reservation_id.
Attributes inherited from BaseOperationService
Instance Method Summary collapse
-
#execute ⇒ Boolean
Execute the refund claim process.
-
#initialize(reservation_id, actor) ⇒ RefundGuaranteeClaimService
constructor
A new instance of RefundGuaranteeClaimService.
-
#valid? ⇒ Boolean
Validate refund claim eligibility.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods inherited from BaseOperationService
Constructor Details
#initialize(reservation_id, actor) ⇒ RefundGuaranteeClaimService
Returns a new instance of RefundGuaranteeClaimService.
15 16 17 18 |
# File 'app/services/refund_guarantee_claim_service.rb', line 15 def initialize(reservation_id, actor) @reservation_id = reservation_id @actor = actor.to_sym end |
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
11 12 13 |
# File 'app/services/refund_guarantee_claim_service.rb', line 11 def actor @actor end |
#reservation_id ⇒ Object
Returns the value of attribute reservation_id.
10 11 12 |
# File 'app/services/refund_guarantee_claim_service.rb', line 10 def reservation_id @reservation_id end |
Instance Method Details
#execute ⇒ Boolean
Execute the refund claim process
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/refund_guarantee_claim_service.rb', line 22 def execute unless valid? BUSINESS_LOGGER.error( 'Refund guarantee claim validation failed', reservation_id: reservation_id, errors: errors., ) return false end process_refund_claim end |
#valid? ⇒ Boolean
Validate refund claim eligibility
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/services/refund_guarantee_claim_service.rb', line 38 def valid? unless reservation errors.add(:base, 'Reservation not found') return false end unless valid_refund_data? errors.add(:base, I18n.t('errors.refund_guarantee.not_available')) return false end if reservation.user_id.blank? errors.add(:base, 'Reservation has no associated user') return false end unless refund_guarantee.can_claim_refund? # Check if already claimed for prevent duplicate claims if refund_guarantee.status_as_symbol == ReservationRefundGuarantee::STATUS_CLAIMED errors.add(:base, I18n.t('errors.refund_guarantee.already_claimed')) return false end if by_admin? # skip the rest validations for admin-initiated claims return true end if refund_guarantee.refund_period_expired? errors.add(:base, I18n.t('errors.refund_guarantee.period_expired', refundable_until: format_refundable_until)) elsif refund_guarantee.status_as_symbol == ReservationRefundGuarantee::STATUS_EXPIRED errors.add(:base, I18n.t('errors.refund_guarantee.expired')) else errors.add(:base, I18n.t('errors.refund_guarantee.cannot_claim')) end return false end true end |