8
9
10
11
12
13
14
15
16
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/workers/vendors/open_rice/webhook_worker.rb', line 8
def perform(reservation_id, vendor_reservation_id, status, date = nil, time = nil, adult = nil, child = nil,
is_auto_arrive = false)
reservation = Reservation.fetch(reservation_id)
current_restaurant_time = Time.use_zone reservation.restaurant.time_zone do
Time.zone.now
end
RequestStore.store[:reservation_id] ||= reservation_id
RequestStore.store[:restaurant_id] ||= reservation.restaurant_id
case status
when ApiVendorV1::Constants::UPDATE
wait_until_reservation_status_has_changed(reservation_id, [:pending_arrival, :pending_confirmation])
VendorsService::OpenRice::WebhookService.new(reservation_id, vendor_reservation_id, status).
update_reservation_status(date, time, adult, child)
when ApiVendorV1::Constants::CONFIRM
if is_auto_arrive
return VendorsService::OpenRice::WebhookService.new(reservation_id, vendor_reservation_id,
status).auto_arrive_reservation
end
if current_restaurant_time < reservation.reservation_time.twenty_four_hours_later
::Vendors::OpenRice::WebhookWorker.
perform_at(reservation.reservation_time.twenty_four_hours_later + 1.hour,
reservation_id, vendor_reservation_id, status, nil, nil, nil, nil, false)
end
return if reservation.vendor_reservation.webhook_reservation_status == status
wait_until_reservation_status_has_changed(reservation_id, [:arrived])
VendorsService::OpenRice::WebhookService.new(reservation_id, vendor_reservation_id,
status).update_reservation_status
when ApiVendorV1::Constants::NO_SHOW
if current_restaurant_time < reservation.reservation_time.twenty_four_hours_later
::Vendors::OpenRice::WebhookWorker.
perform_at(reservation.reservation_time.twenty_four_hours_later + 1.hour,
reservation_id, vendor_reservation_id, status)
end
return if reservation.vendor_reservation.webhook_reservation_status == status
wait_until_reservation_status_has_changed(reservation_id, [:no_show])
VendorsService::OpenRice::WebhookService.new(reservation_id, vendor_reservation_id,
status).update_reservation_status
when ApiVendorV1::Constants::CANCEL
return if reservation.vendor_reservation.webhook_reservation_status == status
wait_until_reservation_status_has_changed(reservation_id, [:cancelled, :rejected])
VendorsService::OpenRice::WebhookService.new(reservation_id, vendor_reservation_id,
status).update_reservation_status
else
raise NotImplementedError
end
end
|