Added code to support Order-based Booking Server
diff --git a/README.md b/README.md index 76bbbeb..c3814f6 100644 --- a/README.md +++ b/README.md
@@ -48,13 +48,14 @@ [Booking test utility](https://maps-booking.googlesource.com/maps-booking-v3/). To install it, follow the provided installation instructions in its README page. -For the tests, you need to create a text file to store your credentials. -Put your username and password there in one line, e.g. cred.txt file: +For the tests, you need to create a text file to store your credentials. Put +your username and password there in one line, e.g. cred.txt file: -username:password + username:password You also need an availability feed for your test merchants. In our sample -commands below, we saved it as avail.json filename. +commands below, we saved it with the filename avail.json. For Order-based test +client, you also need a services feed. Now, you can test your Booking Server with these commands: @@ -70,6 +71,11 @@ bin/bookingClient -server_addr="localhost:8080" -booking_test=true -availability_feed="./avail.json" -credentials_file="./cred.txt" -As you are working on implementing your own Booking Server, you may need to -run additional tests against it (e.g. list_bookings_test, rescheduling_test, -etc) with the goal of eventually passing all tests (-all_tests=true). +* Test calls to CheckOrderFulfillability and CreateOrder methods for + Order-based Booking Server: + + bin/orderClient -server_addr="localhost:8080" -check_order_test=true -create_order_test=true -output_dir="/tmp" -availability_feed="./availability.json" -service_feed="./services.json" -credentials_file="./cred.txt" + +As you are working on implementing your own Booking Server, you may need to run +additional tests against it (e.g. list_bookings_test, rescheduling_test, etc) +with the goal of eventually passing all tests (-all_tests=true).
diff --git a/apiv3methods.js b/apiv3methods.js index 9c96027..f135f4d 100644 --- a/apiv3methods.js +++ b/apiv3methods.js
@@ -152,14 +152,93 @@ // TO-DO: add code to fetch all bookings for the user_id // ... // ListBookingsResponse - var resp = {bookings: {}}; + var resp = {bookings: [{}]}; const responseBody = JSON.stringify(resp); return responseBody; } + +/** + * CheckOrderFulfillability method (Order-based Booking Server only) + * https://developers.google.com/maps-booking/reference/rest-api-v3/checkorderfulfillability-method + * @param {string} requestBody - HTTP request body + * @return {string} HTTP response body + */ +function CheckOrderFulfillability(requestBody) { + // CheckOrderFulfillabilityRequest + const req = JSON.parse(requestBody); + // TO-DO: validate req, e.g. (req.merchant_id !== null) + // TO-DO: add code to validate individual items and calculate the total price + // ... + // CheckOrderFulfillabilityResponse + var resp = { + fulfillability: { + result: 'CAN_FULFILL', + item_fulfillability: [{}] // individual item fullfilability + }, + fees_and_taxes: { + price_micros: 1000000, // total price in micros, e.g. 1USD = 1000000 + currency_code: 'USD' + } + }; + const responseBody = JSON.stringify(resp); + return responseBody; +} + +/** + * CreateOrder method (Order-based Booking Server only) + * https://developers.google.com/maps-booking/reference/rest-api-v3/createorder-method + * @param {string} requestBody - HTTP request body + * @return {string} HTTP response body + */ +function CreateOrder(requestBody) { + // CreateOrderRequest + const req = JSON.parse(requestBody); + // TO-DO: validate req, e.g. (req.user_information !== null) + // TO-DO: check for req.idempotency_token uniqueness + // TO-DO: create and process the order + // ... + // CreateOrderResponse + var resp = { + order: { + order_id: '123', // new order id + merchant_id: req.order.mercant_id, + item: [{}] // populate individual LineItems, etc. + } + }; + const responseBody = JSON.stringify(resp); + return responseBody; +} + +/** + * ListOrders method (Order-based Booking Server only) + * https://developers.google.com/maps-booking/reference/rest-api-v3/listorders-method + * @param {string} requestBody - HTTP request body + * @return {string} HTTP response body + */ +function ListOrders(requestBody) { + // ListOrdersRequest + const req = JSON.parse(requestBody); + // TO-DO: validate req, e.g. if ("user_id" in req || "order_ids" in req) + // TO-DO: fetch orders for req.user_id or a list of req.order_ids + // ... + // ListOrdersResponse + var resp = { + order: [{}] // populate all orders for the user_id or order_ids + }; + const responseBody = JSON.stringify(resp); + return responseBody; +} + + module.exports.HealthCheck = HealthCheck; +// Booking-flow Booking Server methods module.exports.CheckAvailability = CheckAvailability; module.exports.CreateBooking = CreateBooking; module.exports.UpdateBooking = UpdateBooking; module.exports.GetBookingStatus = GetBookingStatus; module.exports.ListBookings = ListBookings; +// Order-based Booking Server methods +module.exports.CheckOrderFulfillability = CheckOrderFulfillability; +module.exports.CreateOrder = CreateOrder; +module.exports.ListOrders = ListOrders;
diff --git a/bookingserver.js b/bookingserver.js index 849a6de..51d2f42 100644 --- a/bookingserver.js +++ b/bookingserver.js
@@ -166,6 +166,39 @@ console.log(`Error: ${e}`); } break; + // POST /v3/CheckOrderFulfillability/ + // (this method is only for Order-based Booking Server) + case '/v3/checkorderfulfillability': + try { + responseBody = apiv3.CheckOrderFulfillability(requestBody); + } catch (e) { + // TO-DO: add a specific error handling if necessary + httpCode = 500; // Internal Server Error + console.log(`Error: ${e}`); + } + break; + // POST /v3/CreateOrder/ + // (this method is only for Order-based Booking Server) + case '/v3/createorder': + try { + responseBody = apiv3.CreateOrder(requestBody); + } catch (e) { + // TO-DO: add a specific error handling if necessary + httpCode = 500; // Internal Server Error + console.log(`Error: ${e}`); + } + break; + // POST /v3/ListOrders/ + // (this method is only for Order-based Booking Server) + case '/v3/listorders': + try { + responseBody = apiv3.ListOrders(requestBody); + } catch (e) { + // TO-DO: add a specific error handling if necessary + httpCode = 500; // Internal Server Error + console.log(`Error: ${e}`); + } + break; // some unknown request default: httpCode = 400; // Bad Request