Class: Tablecheck::Reservations::Cancel
- Inherits:
-
Object
- Object
- Tablecheck::Reservations::Cancel
- Includes:
- DefaultErrorContainer, ApiHelpers
- Defined in:
- app/services/tablecheck/reservations/cancel.rb
Instance Attribute Summary collapse
-
#reservation ⇒ Object
readonly
Returns the value of attribute reservation.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(reservation_id) ⇒ Cancel
constructor
A new instance of Cancel.
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) ⇒ Cancel
Returns a new instance of Cancel.
11 12 13 |
# File 'app/services/tablecheck/reservations/cancel.rb', line 11 def initialize(reservation_id) @reservation = Reservation.find_by(id: reservation_id) end |
Instance Attribute Details
#reservation ⇒ Object (readonly)
Returns the value of attribute reservation.
9 10 11 |
# File 'app/services/tablecheck/reservations/cancel.rb', line 9 def reservation @reservation end |
Instance Method Details
#execute ⇒ Object
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 |
# File 'app/services/tablecheck/reservations/cancel.rb', line 15 def execute errors.clear = Tablecheck::ErrorMessages::DEFAULT_ERROR validation_result = validate_reservation(reservation) unless validation_result.success? = validation_result. errors.add(:base, ) return ServiceResult.new errors: errors, message: end tablecheck_reservation_id = reservation.vendor_reservation&.supplier_reservation_id if tablecheck_reservation_id.blank? = "TableCheck reservation id is blank for reservation #{reservation.id}" unless Tablecheck::ErrorMessages::KNOWN_ERRORS.include?() APMErrorHandler.report("#{self.class} #{}", reservation_id: reservation.id) end errors.add(:base, ) return ServiceResult.new errors: errors, message: end # no need to call cancellation TC API if status TC has cancelled tc_reservation_detail = Tablecheck::Reservations::Detail.new(reservation.id).show if tc_reservation_detail.success? && tc_reservation_detail.data['status'] == 'cancelled' return ServiceResult.new data: tc_reservation_detail.data end VendorsService::UpdateMemoService.new(reservation).execute result = cancel_reservation(tablecheck_reservation_id, reservation) unless result.success? = result. errors.add(:base, ) return ServiceResult.new errors: errors, message: end ServiceResult.new data: result.data end |