Class: Agents::Confirm

Inherits:
Update show all
Defined in:
app/my_lib/agents/confirm.rb

Overview

Only Owner or admin can Confirm

Constant Summary

Constants inherited from Base

Base::WORKER_DELAY_TIME

Instance Attribute Summary

Attributes inherited from Base

#audit_comment, #errors, #executor, #force_update, #owner, #reservation, #reservation_params, #restaurant, #user, #vendor_booking_id

Instance Method Summary collapse

Methods inherited from Update

#after_initialize, #execute!, #update_booking

Methods included from ErrorType

#fatal_error?, #inventory_error?, #normal_error?, #overwrite_error_type!

Methods inherited from Base

#error_message, #hotline, #inventory_available?, #save_reservation!, #status=

Methods included from SharedJobs

#give_campaign_reward, #send_rating_email

Constructor Details

#initialize(reservation, reservation_params = nil) ⇒ Confirm

Returns a new instance of Confirm.



12
13
14
15
# File 'app/my_lib/agents/confirm.rb', line 12

def initialize(reservation, reservation_params = nil)
  super(reservation, reservation_params)
  @reservation.ack = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Agents::Base

Instance Method Details

#send_notificationObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/my_lib/agents/confirm.rb', line 54

def send_notification
  return unless notification_rule_passed?

  # USER
  NotificationService::Email.new(receiver: :user, reservation: reservation).send_confirmation_email
  NotificationService::Sms.new(phones: reservation.phone, reservation: reservation).send_confirmation_msg_to_user

  # Send notification to owner also, because mostly every booking is confirmed
  # by hungry hub staff
  NotificationService::Email.new(receiver: :owner, reservation: reservation).send_confirmation_email
  NotificationService::Sms.new(phones: owner.phone, reservation: reservation).send_confirmation_msg_to_restaurant
end

#update_booking!Object



17
18
19
20
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
49
50
51
52
# File 'app/my_lib/agents/confirm.rb', line 17

def update_booking!
  reservation.mark_as_valid_reservation!
  if reservation.confirmed_by.blank?
    reservation.confirmed_by = :owner
    reservation.confirmed_at = Time.zone.now
  end
  save_reservation! :sneaky
  @reservation.touch
  @reservation.run_callbacks :update

  # Trigger sync for confirmation (owner/admin operation)
  reservation.trigger_immediate_sync

  BUSINESS_LOGGER.set_business_context({ reservation_id: @reservation.id })

  send_notification

  Netcore::EventWorker.perform_in(Netcore::EventWorker::DELAY, :reservation_event, reservation.id)

  if reservation.aoa_reservation.present? && reservation.aoa_channel?
    BUSINESS_LOGGER.info(
      "#{self.class}: Aoa::WebhookWorker called from update_booking! method with status: :pending_arrival", status: status
    )
    Aoa::WebhookWorker.default_perform_async(reservation.id, :pending_arrival)
  end

  if reservation.by_marketplace? && reservation.tagthai_channel?
    status = ApiVendorV1::Constants::PENDING_ARRIVAL
    BUSINESS_LOGGER.info(
      "#{self.class}: Vendors::TagThai::WebhookWorker called from update_booking! method with status: #{status}", status: status
    )
    Vendors::TagThai::WebhookWorker.perform_async reservation.id, status
  end

  true
end