Class: Workers::Reservations::CancelLaterWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- Workers::Reservations::CancelLaterWorker
- Defined in:
- app/workers/workers/reservations/cancel_later_worker.rb
Overview
This worker is used to cancel reservations that are not paid within a certain time frame. After the temporary reservation is created, the client app locks the reservation for a specific period to continue the payment process. If the user does not complete the payment within X time, this worker will cancel the reservation. It checks if the reservation is active and valid for cancellation, and if there are no successful charges. If the conditions are met, it cancels the reservation, updates the cancel reason, marks the voucher as inactive, and cancels the reservation on the supplier's platform (TableCheck, SevenRooms, or Weeloy). It also invalidates the ShopeePay invoice if applicable. It then schedules the CheckPaymentWorker to run at intervals of 1, 5, 7, and 10 minutes to check the payment status of the reservation. # @param reservation_id [Integer] The ID of the reservation to be canceled.
Instance Method Summary collapse
Methods inherited from ApplicationWorker
Instance Method Details
#perform(reservation_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/workers/workers/reservations/cancel_later_worker.rb', line 21 def perform(reservation_id) reservation = Reservation.find(reservation_id) return unless reservation.active? return unless reservation.valid_to_cancel_temporary_booking? return if reservation.charges.success_scope.present? reservation.audit_comment = 'cancel booking because didnt pay' reservation.cancel_reason = 'Payment canceled' reservation.mark_as_canceled! reservation.mark_voucher_as_inactive! reservation.save!(validate: false) # Trigger sync for payment timeout cancellation (critical status change) reservation.trigger_priority_sync # Cancel reservation on TableCheck or SevenRooms if not paid cancel_supplier_reservation(reservation_id) if reservation.shopee_pay_provider? && reservation.charges.success_scope.blank? service = ShopeePayService::InvalidateInvoice.new(reservation) service.execute end [1, 5, 7, 10].each do |number| Workers::Reservations::CheckPaymentWorker.perform_in(number.to_i.minutes, reservation.id) end end |