Class: Bistrochat::Reservations::Create
- Inherits:
-
Object
- Object
- Bistrochat::Reservations::Create
- Includes:
- ApiHelpers, DefaultErrorContainer, ElasticAPM::SpanHelpers
- Defined in:
- app/services/bistrochat/reservations/create.rb
Instance Attribute Summary collapse
-
#blockage_id ⇒ Object
readonly
Returns the value of attribute blockage_id.
-
#reservation ⇒ Object
readonly
Returns the value of attribute reservation.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(reservation_id = nil, actor = nil, is_vendor_prepaid_reservation = false, reference_id = nil, reseller_reference_id = nil) ⇒ Create
constructor
A new instance of Create.
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods included from ApiHelpers
#api_call, #channel, #find_bistrochat_vendor_application, #get_purpose, #headers, #parse_phone_number, #parse_user_or_guest_full_name, #parsed_vendor_name, #reservation_start_at, #send_error_availability_notification_to_staff
Constructor Details
#initialize(reservation_id = nil, actor = nil, is_vendor_prepaid_reservation = false, reference_id = nil, reseller_reference_id = nil) ⇒ Create
Returns a new instance of Create.
13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/bistrochat/reservations/create.rb', line 13 def initialize(reservation_id = nil, actor = nil, is_vendor_prepaid_reservation = false, reference_id = nil, reseller_reference_id = nil) @reservation = Reservation.find(reservation_id).decorate if reservation_id.present? if actor.is_a?(String) && actor.to_sym == :user @blockage_id = @reservation&.inventory_bistrochat_blockage&.blockage_id end @is_vendor_prepaid_reservation = is_vendor_prepaid_reservation @reference_id = reference_id @reseller_reference_id = reseller_reference_id BUSINESS_LOGGER.set_business_context({ reservation_id: reservation_id, blockage_id: @blockage_id }) end |
Instance Attribute Details
#blockage_id ⇒ Object (readonly)
Returns the value of attribute blockage_id.
11 12 13 |
# File 'app/services/bistrochat/reservations/create.rb', line 11 def blockage_id @blockage_id end |
#reservation ⇒ Object (readonly)
Returns the value of attribute reservation.
11 12 13 |
# File 'app/services/bistrochat/reservations/create.rb', line 11 def reservation @reservation end |
Instance Method Details
#execute ⇒ Object
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/services/bistrochat/reservations/create.rb', line 24 def execute errors.clear = Bistrochat::ErrorMessages::DEFAULT_ERROR # Check if reservation is blank if reservation.blank? = 'Reservation is blank' APMErrorHandler.report("BISTROCHAT: #{self.class} #{}") unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?() errors.add(:base, ) return ServiceResult.new errors: errors, message: end # Check if restaurant is using Bistrochat inventory source inv_source = reservation.restaurant.inventory_source&.inv_source if inv_source.blank? || inv_source != ApiVendorV1::Constants::BISTROCHAT_INV_SOURCE_NAME = "Restaurant #{reservation.restaurant_id} is not using Bistrochat inventory source" unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("BISTROCHAT: #{self.class} #{}", reservation_id: reservation.id, restaurant_id: reservation.restaurant_id) end errors.add(:base, ) BUSINESS_LOGGER.error('BISTROCHAT: Restaurant is not using Bistrochat inventory source', restaurant_id: reservation.restaurant_id) return ServiceResult.new errors: errors, message: end shop_id = reservation.restaurant&.bistrochat_restaurant&.shop_id shop_slug = reservation.restaurant&.bistrochat_restaurant&.shop_slug if shop_id.blank? || shop_slug.blank? = "Invalid shop id: #{shop_id} or shop slug: #{shop_slug} of restaurant #{reservation.restaurant_id}" unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("BISTROCHAT: #{self.class} #{}", reservation_id: reservation.id, restaurant_id: reservation.restaurant_id) end errors.add(:base, ) BUSINESS_LOGGER.error('BISTROCHAT: Invalid shop id or shop slug', restaurant_id: reservation.restaurant_id) return ServiceResult.new errors: errors, message: end if blockage_id.present? blockage_is_valid = validate_blockage unless blockage_is_valid.success? = blockage_is_valid. errors.add(:base, ) BUSINESS_LOGGER.error('BISTROCHAT: Blockage ID is exist but not valid', error_message: ) return ServiceResult.new errors: errors, message: end end BUSINESS_LOGGER.info('BISTROCHAT: Blockage ID is present, continue to create bistrochat\'s reservation') # skip create reservation if payment is not confirmed (for prepaid reservation) # commented out because we want to create reservation in Bistrochat even if payment is not confirmed # return ServiceResult.new data: nil unless reservation.payment_is_confirmed? # Create reservation in Bistrochat bistrochat_reservation = create_reservation(shop_id, reservation_params) unless bistrochat_reservation.success? = bistrochat_reservation. errors.add(:base, ) # send notif to ops team if error related to inventory send_notification_to_error_staff() if reservation.created_by.to_sym == :user BUSINESS_LOGGER.error('BISTROCHAT: Error creating reservation in Bistrochat', error_message: ) return ServiceResult.new errors: errors, message: end # Create InventoryBistrochatBlockage inventory_bistrochat_blockage = create_inventory_bistrochat_blockage if inventory_bistrochat_blockage.blank? = "Error creating InventoryBistrochatBlockage reservation #{bistrochat_reservation.data['reservation_id']} for reservation #{reservation.id}" unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("BISTROCHAT: #{self.class} #{}", reservation_id: reservation.id, restaurant_id: reservation.restaurant_id) end errors.add(:base, ) BUSINESS_LOGGER.error('BISTROCHAT: Error creating InventoryBistrochatBlockage', error_message: ) return ServiceResult.new errors: errors, message: end # Create VendorReservation result = create_bistrochat_reservation(bistrochat_reservation.data) if result.blank? = "Error creating Bistrochat reservation #{bistrochat_reservation.data['reservation_id']} for reservation #{reservation.id}" unless Bistrochat::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("BISTROCHAT: #{self.class} #{}", reservation_id: reservation.id, restaurant_id: reservation.restaurant_id) end errors.add(:base, ) BUSINESS_LOGGER.error('BISTROCHAT: Error creating VendorReservation', error_message: ) return ServiceResult.new errors: errors, message: end BUSINESS_LOGGER.info('BISTROCHAT: Reservation created successfully in Bistrochat', bistrochat_reservation: bistrochat_reservation) ServiceResult.new data: result end |