7
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
|
# File 'app/controllers/api/vendor/v1/dianping/concerns/reservation_error_responses.rb', line 7
def render_error(data = {})
ota_order_status = if [:occupy, :query, nil, ''].include?(data[:method])
ApiVendorV1::Constants::DIANPING_OCCUPY_FAILED_STATUS
elsif data[:method] == :release
ApiVendorV1::Constants::DIANPING_RELEASE_FAILED_STATUS
elsif data[:method] == :confirm
ApiVendorV1::Constants::DIANPING_CONFIRM_FAILED_STATUS
elsif data[:method] == :cancel
ApiVendorV1::Constants::DIANPING_CANCEL_FAILED_STATUS
else
raise NotImplementedError
end
order_data = {
msg: data[:msg],
code: data[:code],
vendor_reference_id: vendor_reference_id,
is_success: false,
vendor_reservation_id: vendor_reservation&.id,
ota_order_status: ota_order_status,
refund_id: data[:refund_id],
}
report_error(order_data.merge(params: parsed_data, method: data[:method]))
if %i[confirm cancel].include?(data[:method])
worker_data = order_data.slice(:vendor_reference_id, :vendor_reservation_id, :ota_order_status, :refund_id)
worker_data[:method] = data[:method]
worker_data[:reservation_id] = reservation&.id
Vendors::Dianping::ReservationWebhookWorker.perform_async(worker_data)
end
serialized_data = Api::Vendor::V1::Dianping::ReservationSerializer.new(OpenStruct.new(order_data))
VendorLogger.log_event(:response, params[:route], payload: serialized_data)
render json: serialized_data, status: :ok
end
|