@tutorbook/payments

0.6.5 • Public • Published

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:

  1. 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).
  2. 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:

  1. Pupils create paid requests via a PCI-compliant Stripe Element (included in the StripeRequestDialog in @tutorbook/dialogs) that returns a payment method token which is sent to the server in the newRequest data REST API request.
  2. The server's data cloud function then creates a sentPayment Firestore document which triggers the processAuthPayment cloud function.
  3. The processAuthPayment cloud function:
    • Adds a payment method to the Stripe Customer using the token generated by the Stripe Element.
    • Ensures that the payment.from user has a valid stripeCustomer document and the payment.to user has a valid stripeAccount document.
    • Authorizes payment from the Stripe Customer to the Stripe Connect Account while deducting a 10% fee.
    • Creates authPayment documents in both user's authPayments subcollections and one document (that contains the Stripe Payment object) in the stripeCustomer authPayments subcollection.
    • Deletes the original sentPayment document.
    • Note: If anything errors, the function deletes the requestOut, requestIn, and sentPayment documents and sends an email to the fromUser asking for a valid form of payment.

After the tutoring lesson, tutors are able to request payments from their pupils by creating pastAppointment documents:

  1. The tutor clicks a FAB on the ViewApptDialog (included in @tutorbook/dialogs) indicating that they are ready to "Request Payment".
  2. Clicking that button creates a requestedPayment document (via the data REST API) that asks the pupil to confirm the lesson occurred (via a dialog created in @tutorbook/listener).
  3. Once payment approval has been granted by the pupil (which leads to the creation of approvedPayment documents), our server's processPayment cloud function captures the correct amount from the original authorizedPayment.
  4. Capturing the payment leads to the creation of pastPayment documents 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.

Readme

Keywords

none

Package Sidebar

Install

npm i @tutorbook/payments

Weekly Downloads

5

Version

0.6.5

License

ISC

Unpacked Size

29 kB

Total Files

3

Last publish

Collaborators

  • nicholaschiang