feat(hardlink): unify kiosk payments and finalize legacy cleanup
This commit is contained in:
+18
-12
@@ -17,14 +17,20 @@ import (
|
||||
// ReadHotel gets the hotel record from CMS and returns its reservation system
|
||||
// configuration if the record has been updated since the last read.
|
||||
func ReadHotel(hotelCode, CMSBaseURL string) (cmstypes.ReservationSystemRec, error) {
|
||||
var reservationSystem cmstypes.ReservationSystemRec
|
||||
hotel, err := ReadHotelDetails(hotelCode, CMSBaseURL)
|
||||
return hotel.ReservationSystem, err
|
||||
}
|
||||
|
||||
// ReadHotelDetails retains the complete hotel response, including its currency.
|
||||
func ReadHotelDetails(hotelCode, CMSBaseURL string) (cmstypes.Hotel, error) {
|
||||
var hotel cmstypes.Hotel
|
||||
|
||||
if hotelCode == "" {
|
||||
return reservationSystem, errors.New("hotel code is empty")
|
||||
return hotel, errors.New("hotel code is empty")
|
||||
}
|
||||
|
||||
if CMSBaseURL == "" {
|
||||
return reservationSystem, errors.New("CMS base URL is empty")
|
||||
return hotel, errors.New("CMS base URL is empty")
|
||||
}
|
||||
|
||||
var request cmstypes.RequestRec
|
||||
@@ -36,7 +42,7 @@ func ReadHotel(hotelCode, CMSBaseURL string) (cmstypes.ReservationSystemRec, err
|
||||
|
||||
requestData, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return reservationSystem, fmt.Errorf(
|
||||
return hotel, fmt.Errorf(
|
||||
"marshal CMS hotel request: %w",
|
||||
err,
|
||||
)
|
||||
@@ -46,7 +52,7 @@ func ReadHotel(hotelCode, CMSBaseURL string) (cmstypes.ReservationSystemRec, err
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, requestURL, bytes.NewReader(requestData))
|
||||
if err != nil {
|
||||
return reservationSystem, fmt.Errorf(
|
||||
return hotel, fmt.Errorf(
|
||||
"create CMS hotel request: %w",
|
||||
err,
|
||||
)
|
||||
@@ -61,7 +67,7 @@ func ReadHotel(hotelCode, CMSBaseURL string) (cmstypes.ReservationSystemRec, err
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return reservationSystem, fmt.Errorf(
|
||||
return hotel, fmt.Errorf(
|
||||
"perform CMS hotel request: %w",
|
||||
err,
|
||||
)
|
||||
@@ -70,7 +76,7 @@ func ReadHotel(hotelCode, CMSBaseURL string) (cmstypes.ReservationSystemRec, err
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return reservationSystem, fmt.Errorf(
|
||||
return hotel, fmt.Errorf(
|
||||
"read CMS hotel response: %w",
|
||||
err,
|
||||
)
|
||||
@@ -78,7 +84,7 @@ func ReadHotel(hotelCode, CMSBaseURL string) (cmstypes.ReservationSystemRec, err
|
||||
|
||||
if resp.StatusCode < http.StatusOK ||
|
||||
resp.StatusCode >= http.StatusMultipleChoices {
|
||||
return reservationSystem, fmt.Errorf(
|
||||
return hotel, fmt.Errorf(
|
||||
"CMS hotel request returned HTTP %s: %s",
|
||||
resp.Status,
|
||||
string(body),
|
||||
@@ -88,26 +94,26 @@ func ReadHotel(hotelCode, CMSBaseURL string) (cmstypes.ReservationSystemRec, err
|
||||
var hotelResponse cmstypes.HotelResponseRec
|
||||
|
||||
if err := json.Unmarshal(body, &hotelResponse); err != nil {
|
||||
return reservationSystem, fmt.Errorf(
|
||||
return hotel, fmt.Errorf(
|
||||
"unmarshal CMS hotel response: %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
if hotelResponse.Status.Code != cmstypes.StatusSuccessCode {
|
||||
return reservationSystem, fmt.Errorf(
|
||||
return hotel, fmt.Errorf(
|
||||
"CMS hotel request failed: %s",
|
||||
hotelResponse.Status.Message,
|
||||
)
|
||||
}
|
||||
|
||||
if hotelResponse.TheHotel.Updated <= -1 {
|
||||
return reservationSystem, errors.New(
|
||||
return hotel, errors.New(
|
||||
"hotel record not updated since last read",
|
||||
)
|
||||
}
|
||||
|
||||
return hotelResponse.TheHotel.ReservationSystem, nil
|
||||
return hotelResponse.TheHotel, nil
|
||||
}
|
||||
|
||||
func PaymentSystemIndex(name string) int {
|
||||
|
||||
Reference in New Issue
Block a user