Class: SevenRooms::Reservations::Cancel
- Inherits:
-
Object
- Object
- SevenRooms::Reservations::Cancel
- Includes:
- DefaultErrorContainer, ApiHelpers
- Defined in:
- app/services/seven_rooms/reservations/cancel.rb
Instance Attribute Summary collapse
-
#reservation ⇒ Object
readonly
Returns the value of attribute reservation.
Instance Method Summary collapse
-
#execute ⇒ Object
Executes the cancellation of a reservation in SevenRooms.
-
#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_uri, #auth_headers, #common_headers, #find_seven_rooms_vendor_application, #parse_user_or_guest_full_name, #parsed_vendor_name, #send_error_availability_notification_to_staff, #sevenrooms_credit_card_error?, #standardize_or_default_phone
Constructor Details
#initialize(reservation_id) ⇒ Cancel
Returns a new instance of Cancel.
11 12 13 |
# File 'app/services/seven_rooms/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/seven_rooms/reservations/cancel.rb', line 9 def reservation @reservation end |
Instance Method Details
#execute ⇒ Object
Executes the cancellation of a reservation in SevenRooms.
Returns a ServiceResult object with the following attributes:
-
data: The result of creating the SevenRoomsReservation record.
-
errors: Any errors that occurred during the execution.
-
message: A message indicating the result of the execution.
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 |
# File 'app/services/seven_rooms/reservations/cancel.rb', line 21 def execute errors.clear = SevenRooms::ErrorMessages::DEFAULT_ERROR # Validate reservation validation_result = validate_reservation unless validation_result.success? = validation_result. errors.add(:base, ) return ServiceResult.new errors: errors, message: end # Skip cancel action if the reservation is already canceled in SevenRooms return ServiceResult.new data: nil if skip_cancel?(reservation.id) VendorsService::UpdateMemoService.new(reservation).execute result = cancel_reservation(validation_result.data[:concierge_id], validation_result.data[:seven_rooms_reservation_id]) unless result.success? = result. errors.add(:base, ) return ServiceResult.new errors: errors, message: end ServiceResult.new data: result.data end |