# @tutorbook/payments

> Tutorbook PWA (Progressive Web App) sub-package that manages client-side payment operations (primarily for tutors to manage their business(es)).

Latest version **0.6.5** (published 2020-04-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install @tutorbook/payments
pnpm add @tutorbook/payments
yarn add @tutorbook/payments
bun add @tutorbook/payments
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.5 |
| Published | 2020-04-01 |
| First published | 2019-12-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 28.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 60 |
| Maintainers | nicholaschiang |

## Links

- npm: https://www.npmjs.com/package/@tutorbook/payments
- Repository: https://github.com/tutorbookapp/tutorbook
- Homepage: https://github.com/tutorbookapp/tutorbook#readme
- Issues: https://github.com/tutorbookapp/tutorbook/issues
- npm.io page: https://npm.io/package/@tutorbook/payments

## Dependencies (6)

- [@tutorbook/card](https://npm.io/package/@tutorbook/card.md) ^0.6.5
- [@tutorbook/data](https://npm.io/package/@tutorbook/data.md) ^0.6.5
- [@tutorbook/utils](https://npm.io/package/@tutorbook/utils.md) ^0.6.5
- [@tutorbook/dialogs](https://npm.io/package/@tutorbook/dialogs.md) ^0.6.5
- [@tutorbook/profile](https://npm.io/package/@tutorbook/profile.md) ^0.6.5
- [@tutorbook/schedule](https://npm.io/package/@tutorbook/schedule.md) ^0.6.5

## Recent versions

- 0.6.5 (latest) — 2020-04-01
- 0.6.4 — 2020-03-29
- 0.6.3 — 2020-03-28
- 0.6.1 — 2020-03-27
- 0.6.0 — 2020-03-26
- 0.5.8 — 2020-03-23
- 0.5.7 — 2020-03-21
- 0.5.6 — 2020-03-20
- 0.5.6-alpha.1 — 2020-03-20
- 0.5.6-alpha.0 — 2020-03-20
- 0.5.5 — 2020-03-19
- 0.5.4 — 2020-03-19
- 0.5.3 — 2020-03-17
- 0.5.2 — 2020-03-05
- 0.5.1 — 2020-03-03
- … 38 more at https://npm.io/package/@tutorbook/payments/versions

## README

# 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`](https://npmjs.com/package/@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`](https://npmjs.com/package/@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`](https://npmjs.com/package/@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.

---
_Source: https://npm.io/package/@tutorbook/payments · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
