Class: Parsec::Request::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/parsec/request/order.rb

Constant Summary

Constants inherited from Base

Base::DATE_FORMAT, Base::NAMESPACE, Base::RESOURCES

Instance Method Summary collapse

Methods inherited from Base

#client, #error, #initialize

Constructor Details

This class inherits a constructor from Parsec::Request::Base

Instance Method Details

#cancel(parsec_id) ⇒ Object



61
62
63
64
65
66
# File 'lib/parsec/request/order.rb', line 61

def cancel(parsec_id)
  response = cancel_request('Cancel', parsec_id)
  return error(response[:ota_cancel_rs]) if response.dig(:ota_cancel_rs, :errors).present?

  Parsec::Order.build(response[:ota_booking_info_rs])
end

#check_booking(booking_data) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/parsec/request/order.rb', line 22

def check_booking(booking_data)
  message = { hotel_res: { rooms: { room: rooms(booking_data) } } }
  response = booking_request('PreBooking', message)
  return error(response[:ota_booking_info_rs]) if response[:ota_booking_info_rs][:errors].present?

  { success: response[:ota_booking_info_rs][:success] }
end

#create(booking_data, client_id, customer_text = nil) ⇒ Object

booking_data = [{ booking_code1:, adults1:, children1: }, { booking_code2:, adults2:, children2: }, …]



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/parsec/request/order.rb', line 31

def create(booking_data, client_id, customer_text = nil)
  message = {
    unique_i_d: { '@Type' => 'ClientReference', '@ID' => client_id },
    hotel_res: { rooms: { room: rooms_with_guests(booking_data, client_id) } }
  }
  message[:hotel_res][:special_requests] = { text: customer_text } if customer_text.present?
  response = booking_request('Booking', message)
  return error(response[:ota_booking_info_rs]) if response[:ota_booking_info_rs][:errors].present?

  Parsec::Order.build(response[:ota_booking_info_rs])
end

#list(from_date, to_date, hotel_code = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/parsec/request/order.rb', line 6

def list(from_date, to_date, hotel_code = nil)
  attributes = { xmlns: NAMESPACE }
  booking_search = {
    date_range: {
      '@Start' => from_date.strftime(DATE_FORMAT),
      '@End' => to_date.strftime(DATE_FORMAT),
      '@DateType' => 'Arrival'
    }
  }
  booking_search[:hotel_ref] = { '@HotelCode' => hotel_code } if hotel_code.present?
  response = client(:list).call('OTA_BookingListRQ', attributes: attributes, message: { booking_search: booking_search })
  return error(response.body[:ota_booking_list_rs]) if response.body[:ota_booking_list_rs][:errors].present?

  response.body[:ota_booking_list_rs]
end

#pre_cancel(parsec_id) ⇒ Object



54
55
56
57
58
59
# File 'lib/parsec/request/order.rb', line 54

def pre_cancel(parsec_id)
  response = cancel_request('PreCancel', parsec_id)
  return error(response[:ota_cancel_rs]) if response.dig(:ota_cancel_rs, :errors).present?

  { fee_amount: response[:ota_cancel_rs][:cancel_info_rs][:cancellation_costs][:@amount].to_f }
end

#read(parsec_id) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/parsec/request/order.rb', line 43

def read(parsec_id)
  attributes = { xmlns: NAMESPACE, 'DetailLevel' => '1', 'RateDetails' => '1', 'Language' => 'EN' }
  message = { unique_i_d: { '@Type' => 'Locator', '@ID' => parsec_id } }
  response = client(:read).call('OTA_ReadRQ', attributes: attributes, message: message)
  return error(response.body[:ota_booking_info_rs]) if response.body[:ota_booking_info_rs][:errors].present?

  Parsec::Order.build(response.body[:ota_booking_info_rs])
rescue Savon::Error => e
  Xlog.and_raise_error(e)
end