---
# System prepended metadata

title: 'Booking Flow:'

---

# Bookin Flow

## User Flow:
* The user will book a session will select number of seats with 
  * Number of seats
  * amount (session price for 1 seat will be **amount / number of seats**)
  
  
### During booking:
  * Backend will recieve booking details and do validate amount and session price
  * Calculate the price in case of discount or gift card in an endpoint to provide the mobile with it
  * The mobile will call another endpoint to create order and retrun the callback URL to the mobile to call Moyasar with the calculated amount after disocunts/gift cards to pay the amount using Cards/Apple Pay (Steratgy pattaren)
  * After Moyasar calls the callback URL with its paramaters.
     * the Order status will be updated in a transaction to be paid/pending/failed.
     * create an Invoice to the User with Zatca QR code.
     * generate PDF invoice to google storage.
     * generate event calander file to send to the user in the response.
     * Send SMS to the user with booking details.
     * Send Email to the user with the booking details.
     * Send Slack notifications with the booking details.
  * in case if there is a user refund
    * the invoice should be deleted and increament the sessions seats with the number of canceled seats.
    * Send sms with refunded amount and session details.
    * Send email to the user with refunded amount and session details.
    * Send Slack message with booking cancelation

## Coach Flow

* missing design and we will hold on it.
* There is no taking attandance anymore why is it back again?
* Race conditions for session management into two databases firebase and postgreSQL (Not in my experience dealing with that without third party like queue system while we are on a tight budget!).
*  generate invoice if requested, what details should appear? (same as user invoice who booked the session)
*  What messages may send by the coach to the learner?
*  What Filters are needed and what search paramaters are needed?
*  Coach Balance will be driven and saved into the database
   * session Price
   * amount paid (with vat)
   * discount applied
   * gift card applied
   * Coach shares:
      * his amount after cutting suplift sahre amount and its vat and his vat too (if there is)
      * tracking non paid sessions for him (total unpaid amount)
      * tracking total sales (total paid amount by the users for a specifiec sessions)

## Admin Flow
   * Missing the design and we will hold on it.
   * adding/removing seats or managing session in two databases duering booking is a big problem (Not in my experience handling race conditions within two databases without third party like queue system while we are on a tight budget!)
   * What custome message that admin can send to the booked user?
   * what filtrs and what search will be needed to list booking and searching?
   * What data is needed to export from booking or order table noting that user details will come from firebase and this will push us to create custome script to process this and it will take sometime to generate a report so we need less data that will make this script faster.
   * what action/logs that is meant?

# Notes

* Need more details about exports requried for all points mentioned an export and split it into sub task to be created later.
* What is After booking (BI) Point in technologies?

* Creating sub tasks for below points with more details and user stories please.
  * Manage Bookings
  * Manage Booked Sessions
  * Payouts
    * Exports
      * Unpaid sessions
      * Payouts for closed sessions
      * Bookings
