Class: Tablecheck::Reservations::Create
- Inherits:
-
Object
- Object
- Tablecheck::Reservations::Create
- Includes:
- DefaultErrorContainer, ApiHelpers
- Defined in:
- app/services/tablecheck/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_tablecheck_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/tablecheck/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? @is_vendor_prepaid_reservation = is_vendor_prepaid_reservation @reference_id = reference_id @reseller_reference_id = reseller_reference_id if actor.is_a?(String) && actor.to_sym == :user @blockage_id = @reservation&.inventory_tablecheck_blockage&.blockage_id end 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/tablecheck/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/tablecheck/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 128 129 |
# File 'app/services/tablecheck/reservations/create.rb', line 24 def execute errors.clear = Tablecheck::ErrorMessages::DEFAULT_ERROR # Check if reservation is blank if reservation.blank? = 'Reservation is blank' APMErrorHandler.report("TABLECHECK: #{self.class} #{}") unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?() errors.add(:base, ) return ServiceResult.new errors: errors, message: end # Check if restaurant is using TableCheck inventory source inv_source = reservation.restaurant.inventory_source&.inv_source if inv_source.blank? || inv_source != ApiVendorV1::Constants::TABLECHECK_INV_SOURCE_NAME = "Restaurant #{reservation.restaurant_id} is not using TableCheck inventory source" unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("TABLECHECK: #{self.class} #{}", reservation_id: reservation.id, restaurant_id: reservation.restaurant_id) end errors.add(:base, ) BUSINESS_LOGGER.error('TABLECHECK: Restaurant is not using TableCheck inventory source', restaurant_id: reservation.restaurant_id) return ServiceResult.new errors: errors, message: end shop_id = reservation.restaurant&.tablecheck_restaurant&.shop_id shop_slug = reservation.restaurant&.tablecheck_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 Tablecheck::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("TABLECHECK: #{self.class} #{}", reservation_id: reservation.id, restaurant_id: reservation.restaurant_id) end errors.add(:base, ) BUSINESS_LOGGER.error('TABLECHECK: 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('TABLECHECK: Blockage ID is exist but not valid', error_message: ) return ServiceResult.new errors: errors, message: end end BUSINESS_LOGGER.info('TABLECHECK: Blockage ID is present, continue to create tablecheck\'s reservation') # skip create reservation if payment is not confirmed (for prepaid reservation) # commented out because we want to create reservation in Tablecheck even if payment is not confirmed # return ServiceResult.new data: nil unless reservation.payment_is_confirmed? # Create reservation in Tablecheck tablecheck_reservation = create_reservation(shop_id, reservation_params) unless tablecheck_reservation.success? = tablecheck_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('TABLECHECK: Error creating reservation in Tablecheck', error_message: ) return ServiceResult.new errors: errors, message: end # Create InventoryTablecheckBlockage inventory_tablecheck_blockage = create_inventory_tablecheck_blockage if inventory_tablecheck_blockage.blank? = "Error creating InventoryTablecheckBlockage reservation #{tablecheck_reservation.data['reservation_id']} for reservation #{reservation.id}" unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("TABLECHECK: #{self.class} #{}", reservation_id: reservation.id, restaurant_id: reservation.restaurant_id) end errors.add(:base, ) BUSINESS_LOGGER.error('TABLECHECK: Error creating InventoryTablecheckBlockage', error_message: ) return ServiceResult.new errors: errors, message: end # Create VendorReservation result = create_tablecheck_reservation(tablecheck_reservation.data) if result.blank? = "Error creating TableCheck reservation #{tablecheck_reservation.data['reservation_id']} for reservation #{reservation.id}" unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("TABLECHECK: #{self.class} #{}", reservation_id: reservation.id, restaurant_id: reservation.restaurant_id) end errors.add(:base, ) BUSINESS_LOGGER.error('TABLECHECK: Error creating VendorReservation', error_message: ) return ServiceResult.new errors: errors, message: end VendorsService::VendorPaymentService.new(reservation).save_vendor_payment if [:admin, :owner].include?(reservation.created_by.to_sym) BUSINESS_LOGGER.info('TABLECHECK: Reservation created successfully in Tablecheck', tablecheck_reservation: tablecheck_reservation) ServiceResult.new data: result end |