@tutorbook/payments v0.6.5
Tutorbook Payments
Tutorbook PWA (Progressive Web App) sub-package that manages client-side payment operations (primarily for tutors to manage their business(es)).
Payment Flow
We use Stripe Connect to process all of the payments on Tutorbook. Paid tutors setup their accounts as follows:
- Paid tutors are prompted by a dashboard card to setup a Stripe Connect payouts account. A link is generated using our unique Stripe Client ID that sends the user to https://connect.stripe.com to complete their account setup. Upon completion, they are sent back to our return URI (usually https://tutorbook.app/app) with their auth token included as a query param (e.g. https://tutorbook.app/app/home?token=ABCDEFG).
- That token is then sent to our server via an HTTPS GET request that triggers
the creation of a Firestore document containing that new Stripe Account's
information. Our server then sends an
accountURL(where the tutor can view and manage their payout settings) back to the client.
Once the paid tutor has finished setting up their account, they can then receive paid lesson requests as follows:
- Pupils create paid requests via a PCI-compliant Stripe Element (included in
the
StripeRequestDialogin@tutorbook/dialogs) that returns a payment method token which is sent to the server in thenewRequestdataREST API request. - The server's
datacloud function then creates asentPaymentFirestore document which triggers theprocessAuthPaymentcloud function. - The
processAuthPaymentcloud function:- Adds a payment method to the Stripe Customer using the token generated by the Stripe Element.
- Ensures that the
payment.fromuser has a validstripeCustomerdocument and thepayment.touser has a validstripeAccountdocument. - Authorizes payment from the Stripe Customer to the Stripe Connect Account while deducting a 10% fee.
- Creates
authPaymentdocuments in both user'sauthPaymentssubcollections and one document (that contains the Stripe Payment object) in thestripeCustomerauthPaymentssubcollection. - Deletes the original
sentPaymentdocument. - Note: If anything errors, the function deletes the
requestOut,requestIn, andsentPaymentdocuments and sends an email to thefromUserasking for a valid form of payment.
After the tutoring lesson, tutors are able to request payments from their pupils
by creating pastAppointment documents:
- The tutor clicks a FAB on the
ViewApptDialog(included in@tutorbook/dialogs) indicating that they are ready to "Request Payment". - Clicking that button creates a
requestedPaymentdocument (via thedataREST API) that asks the pupil to confirm the lesson occurred (via a dialog created in@tutorbook/listener). - Once payment approval has been granted by the pupil (which leads to the
creation of
approvedPaymentdocuments), our server'sprocessPaymentcloud function captures the correct amount from the originalauthorizedPayment. - Capturing the payment leads to the creation of
pastPaymentdocuments which triggers another function to increase the tutor's balance (in their Firestore profile document) to match their Stripe Account balance.
Tutors then receive payouts from Stripe (that trigger a webhook that lowers their account balance in their Firestore profile document) on a daily basis.
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago