in src/backend/booking/src/reserve-booking/reserve.py [0:0]
def reserve_booking(booking):
"""Creates a new booking as UNCONFIRMED
Parameters
----------
booking: dict
chargeId: string
pre-authorization charge ID
stateExecutionId: string
Step Functions Process Booking Execution ID
chargeId: string
Pre-authorization payment token
customer: string
Customer unique identifier
bookingOutboundFlightId: string
Outbound flight unique identifier
Returns
-------
dict
bookingId: string
"""
try:
booking_id = str(uuid.uuid4())
state_machine_execution_id = booking["name"]
outbound_flight_id = booking["outboundFlightId"]
customer_id = booking["customerId"]
payment_token = booking["chargeId"]
booking_item = {
"id": booking_id,
"stateExecutionId": state_machine_execution_id,
"__typename": "Booking",
"bookingOutboundFlightId": outbound_flight_id,
"checkedIn": False,
"customer": customer_id,
"paymentToken": payment_token,
"status": "UNCONFIRMED",
"createdAt": str(datetime.datetime.now()),
}
logger.debug(
{"operation": "reserve_booking", "details": {"outbound_flight_id": outbound_flight_id}}
)
ret = table.put_item(Item=booking_item)
logger.info({"operation": "reserve_booking", "details": ret})
tracer.put_metadata(booking_id, booking_item, "booking")
return {"bookingId": booking_id}
except ClientError as err:
logger.exception({"operation": "reserve_booking"})
raise BookingReservationException(details=err)