Class: Kiosque::Checkin
- Inherits:
-
Object
- Object
- Kiosque::Checkin
- Defined in:
- app/services/kiosque/checkin.rb
Overview
typed: ignore frozen_string_literal: true
Instance Attribute Summary collapse
-
#reservation ⇒ Object
readonly
Returns the value of attribute reservation.
Instance Method Summary collapse
- #custom_menu_id_is_valid ⇒ Object
- #generate_reservation_data ⇒ Object
- #hh_checkin ⇒ Object
-
#initialize(reservation_id = nil) ⇒ Checkin
constructor
A new instance of Checkin.
- #refresh_authorization_if_expired(kind) ⇒ Object
- #validate_table_number ⇒ Object
Constructor Details
#initialize(reservation_id = nil) ⇒ Checkin
Returns a new instance of Checkin.
7 8 9 |
# File 'app/services/kiosque/checkin.rb', line 7 def initialize(reservation_id = nil) @reservation = Reservation.find(reservation_id).decorate if reservation_id.present? end |
Instance Attribute Details
#reservation ⇒ Object (readonly)
Returns the value of attribute reservation.
5 6 7 |
# File 'app/services/kiosque/checkin.rb', line 5 def reservation @reservation end |
Instance Method Details
#custom_menu_id_is_valid ⇒ Object
60 61 62 63 64 65 |
# File 'app/services/kiosque/checkin.rb', line 60 def reservation_data = generate_reservation_data = reservation_data['attributes']['packages'].pluck('kiosque_menu_id') !.include?('') end |
#generate_reservation_data ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/kiosque/checkin.rb', line 49 def generate_reservation_data reservation_data = Api::Kiosque::V1::ReservationSerializer.new(reservation).as_json data = reservation_data['data'] data_without_packages = data.dup data_without_packages['attributes'] = data['attributes'].except('packages') data_without_packages['attributes']['packages'] = data_without_packages['attributes'].delete('kiosque_packages') data_without_packages end |
#hh_checkin ⇒ Object
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 |
# File 'app/services/kiosque/checkin.rb', line 11 def hh_checkin return false if reservation.nil? = 'token' () # Refresh token if it's expired = KiosqueCode.where(kind: ).last if .present? url = "#{kiosque_host}/HHCheckin" reservation_data = generate_reservation_data payload = { access_token: .code, data: reservation_data, }.to_json api_response, response_body = api_call(url, payload) if api_response.status != 200 if ! error_msg = "kiosque_menu_id (Custom Menu ID of package) is empty #{api_response.status}" elsif response_body.present? error_msg = "#{response_body['error']}, #{response_body['error_description']} [HHCheckin Kiosque]" else error_msg = "API call failed with status #{api_response.status}" end handle_error('HHCheckin', error_msg, payload, response_body) false else save_kiosque_reservation(payload, response_body.to_json) true end else false end end |
#refresh_authorization_if_expired(kind) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/services/kiosque/checkin.rb', line 67 def (kind) = KiosqueCode.where(kind: kind).last if .nil? send("kiosque_request_#{kind}") else expire_in = Time.at(.expire_in).in_time_zone('Asia/Bangkok') - 7.hours now = Time.zone.now.in_time_zone('Asia/Bangkok') if expire_in.to_i < now.to_i # remove if the code/token has expired .destroy send("kiosque_request_#{kind}") end end end |
#validate_table_number ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/services/kiosque/checkin.rb', line 85 def validate_table_number reservation.reload checkin_setting = self_checkin_setting if checkin_setting.present? if checkin_setting.require_table_number reservation.table.present? else true end else false end end |