Skip to content

feat(payments): let users pay for bookings and catering through a payment driver - #748

Merged
MrYuion merged 13 commits into
developfrom
feat/payments-driver
Nov 23, 2026
Merged

MrYuion merged 13 commits into
developfrom
feat/payments-driver

Conversation

@MrYuion

@MrYuion MrYuion commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

The apps had no real way to charge for bookings or catering. The old payments lib sent raw card numbers to a Stripe-specific driver, and it only ran on the booking form.

This adds a provider-neutral payment driver contract and uses it when a zone has a payments binding. Without the binding, nothing changes.

  • Checkout: in Workplace, new desk, parking, locker and room bookings, and the catering of new meetings, ask for payment. Other apps do not opt in (PAYMENT_CHECKOUT), so booking panels and staff bookings in Concierge are not charged. The user pays on the provider's hosted page, so the app never handles card data. The driver prices every item and refuses a checkout whose total differs from the one the user accepted.
  • Authorize, then capture: the payment is held before the booking saves and taken after it. A failed save, or failed asset requests, releases it. If that release fails, the error shows the payment ID in place of the save error, so support can release it. If every room of a meeting declines, the payment is released and the catering is not ordered. Rooms that decline while another room accepts are not charged (exclude_resource_ids on capture_payment). A failed capture is tried 3 times. After that, staff can select Take payment on the booking's payment in the Concierge list. For an event, Take payment also leaves out the rooms that declined. If the user closes the payment window, they can reopen the page (get_payment_link) or cancel. create_checkout gets an idempotency_key, so a retry after a lost response does not start a second payment.
  • Refunds: refund_payment takes an optional request_id. The details make a new ID when the refund view opens. After a failed request, the amount and reason stay fixed, so a retry sends the same request and a lost response does not refund twice. Opening the refund view again loads the payment first. feat(stripe/payments): take booking and catering payments through Stripe drivers#654 supports it.
  • Workplace: a Payments page lists the user's payments, invoices and saved payment methods. Users can request invoices. The page loads again when the user changes building.
  • Concierge: pages for privileged staff to find and refund payments, send or create invoices, and manage products and services. The driver decides who is privileged.
  • Booking lists: the Concierge room, desk, parking and locker lists show a Payment column. A paid booking shows an icon that opens its payment. Events now store payment_id like bookings do.
  • Accessibility: payment status badges and the placeholders of all apps have 4.5:1 contrast in the light and dark themes. The placeholder change is in the shared stylesheet.
  • Secure context only: payments are off on pages that are not HTTPS, as if no binding exists. localhost, 127.0.0.1 and [::1] still work over HTTP for development.
  • Mock driver: implements the same TypeScript interface, so contract drift fails the build. It is off by default so mock booking flows are unchanged. Turn it on with PLACEOS.mock_payments.

docs/payments.md has the full contract, pricing rules and notes for building the Stripe driver. The first real driver uses Stripe; other providers implement the same methods.

Not covered yet: changes to saved bookings, group bookings, recurring series (charged as one booking), external catering, and automatic refunds on cancel.

Testing: focused specs for the service, the checkout modal, the payment details, line items, amounts, the mock driver, the booking and meeting capture and release paths, and the Workplace and Concierge payment pages. nx affected -t test build passed for all 29 affected projects. I also checked the Workplace and Concierge pages in mock mode.

Council review

Rounds: 6 with gpt-6.2-sol on high. Verdict: approved

The items that stayed disputed after round 6 are fixed in ad532fd (now e5857aa after the rebase onto develop). The two findings from the second PR review are fixed in 5360f09, the three Greptile findings in 4a204a5, the refund request_id and the release message in 7ee8a9a, and the refund retry findings in 577a147, 3c632ef and 462e258. No council round has reviewed these commits.

Aspect R1 R2 R3 R4 R5 R6
Correctness 5 7 7 8 8 9
Simplicity 7 — — — — —
Readability 7 — — — — —
Coverage 5 6 7 8 10 —
Accessibility 7 7 7 8 9 —
UX 6 — — — — —
Security 4 7 8 9 8 —
Errors 5 6 6 9 8 —
Concurrency 5 6 7 8 10 —
Data integrity 4 5 6 7 8 —

Reviewed with sol-loop: 1 round with gpt-6.2-sol on xhigh. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code (T3 Code).

🤖 Generated with Claude Code

@MrYuion MrYuion left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Claude Opus 5.5 responding on behalf of Alex Sorafumo

I reviewed the full diff against develop. nx run-many -t test lint -p payments bookings mocks passes locally.

The contract and the authorize then capture order are easy to follow. The problems are at the edges, all inline:

  1. A booking with asset requests stays charged after its rollback.
  2. Group desk bookings open one checkout per member, and rollback leaves those payments captured.
  3. A payment that authorizes more than about 6 seconds after the popup closes can be orphaned, and the user can pay twice.
  4. A blocked popup in Complete payment hides the link and ends in a cancel 15 minutes later.
  5. The checkout also runs in Concierge and on booking panels.

I left out the partial capture for declined rooms, because the PR already lists it under "Not covered yet".

@MrYuion
MrYuion force-pushed the feat/payments-driver branch from 4b5cf31 to a6a1f44 Compare November 19, 2026 01:03

@MrYuion MrYuion left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Claude Opus 5.5 responding on behalf of Alex Sorafumo

I re-reviewed the changes since my last review (737e6404..ad532fdb). The branch was rebased: git range-diff shows that the first two commits changed only in locale conflicts, so this review covers a6a1f44, 4e45ce9, 7d3a28d, 69f7435 and ad532fd.

Earlier fix claims. All 5 are true in the current code:

  1. Asset requests: postForm captures after _saveAssetRequests and cancels the payment when they fail.
  2. Group bookings: _takePayment returns null when _options().group is set, and postFormForGroup requires group.
  3. Late authorization: _resume calls get_payment before get_payment_link, and resolves with a payment that is already complete. One change since the reply: a failed reopen now stays on the closed view with the open payment instead of cancelling it. This also stops a second payment.
  4. Blocked popup: completePayment throws PAYMENTS.POPUP_BLOCKED before it calls the driver.
  5. Opt-in checkout: only apps/workplace/src/app/app.config.ts provides PAYMENT_CHECKOUT: true.

The secure-context check is in one place. _module returns null outside a secure context, and call, enabled, is_enabled and can_checkout all use it.

New findings, inline:

  1. Take payment captures the rooms that declined.
  2. Nit: a 15-minute timeout in Complete payment shows "Payment cancelled" for a payment that is still open.

nx run-many -t test lint -p payments bookings mocks events concierge workplace passes (12 of 12 tasks). tsc --noEmit passes for payments, bookings, concierge and workplace. events has one TS4029 error in space-map.component.ts, which this PR does not change. It is also on develop.

- Define a provider-neutral payment driver contract. The first driver
  uses Stripe, and the mock driver implements the same type.
- Ask for payment on new desk, parking, locker and room bookings, and on
  the catering of new meetings. The driver prices all items and rejects
  a checkout when its total is not the total that the user accepted.
- Authorize before the save and capture after it. A failed save
  releases the payment.
- Pay on the hosted page of the provider. Remove the card input field,
  which sent card numbers to the driver.
- Add a Workplace page for the payments, invoices and saved payment
  methods of the user.
- Add Concierge pages to find and refund payments, send and make
  invoices, and manage products and services.
- Only show payments when the zone has a `payments` binding.
- Add `get_payment_link` to the driver contract. It returns a new link
  to the hosted page of a pending payment, with the same payment ID.
- Keep the payment open when the user closes the payment window. The
  checkout modal offers to reopen the page or cancel the payment.
- Let users complete an open payment of their own from the payment
  details when it has a reference, then capture it for that reference.
- Only Workplace asks for payment. Apps opt in with the PAYMENT_CHECKOUT
  token, so booking panels and Concierge staff bookings do not.
- Capture a booking payment after its asset requests save, and release
  it when they fail and the booking is removed.
- Do not charge group bookings, which save one booking for each member.
- Check the payment before a new link to the hosted page. A payment that
  went through after the window closed completes with no second charge.
- Cancel the open payment when a reopen fails, so it is not left behind.
- Show an error when the browser blocks the window for Complete payment,
  instead of a 15 minute wait that ends in a cancel.
The room, desk, parking and locker booking lists get a Payment column
when the building has a payment driver. A booking with a payment shows
an icon that opens the payment details. The lists do not load each
payment, so that a long list sends no request for each row.

New events now keep `extension_data.payment_id`, as bookings do, so that
room bookings can show their payment. In mock mode, every third mock
booking and event links to a paid payment.
Payments need HTTPS, so that no other party can change the payment
pages. On an insecure page the service acts as if no payment driver is
bound. Local hosts are excluded, so local development over HTTP works.
- Never auto-cancel a saved booking's payment. Stop a checkout after
  three failed checks, keep a payment open when cancel fails, and only
  save a booking for authorized or succeeded payments.
- Release the payment when every priced room declines, and skip the
  catering order then.
- Show popup-blocked and cancel errors in the checkout modal and move
  focus to the active action.
- Label the Concierge filters and fields, scroll wide tables, and hide
  the invoices page without the invoices capability.
- Make the mock capture idempotent and price catering from assets.
- Try a failed capture 3 times. Staff can take an authorized payment
  that has no reference from the booking list.
- Send an idempotency key with create_checkout, so a retry after a lost
  response does not start a second payment.
- Do not take the rooms that declined a meeting when another room
  accepts it. capture_payment gets exclude_resource_ids.
- Check a reopened payment again when the new link fails, as it can
  complete between the requests.
- Keep a sent invoice sent when an older list response arrives.
- Give the status badges and the placeholders 4.5:1 contrast in both
  themes, and name the invoice User field from its label.
- Add specs for the payment pages, the payment details and the checkout
  items of a meeting.
Take payment now leaves out the rooms of the payment that the event
does not have as accepted. Complete payment shows a payment that is
still open when its wait times out, instead of "Payment cancelled".
@MrYuion
MrYuion force-pushed the feat/payments-driver branch from ad532fd to 5360f09 Compare November 23, 2026 04:20
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The changes since the last review appear safe to merge.

Summary

Adds hosted payments for Workplace bookings and catering, plus payment pages and staff tools in Concierge.

  • A payment driver prices checkouts and sends users to a hosted payment page.
  • Workplace booking checkouts link a payment to the saved booking.
  • New Workplace meetings can charge for rooms and catering together.
  • Workplace users can find their payments, invoices, and saved methods.
  • Privileged Concierge staff can manage payments, invoices, and products.
  • Concierge booking lists show a link to each booking’s payment.
  • Developers can test payment flows with an opt-in mock driver.
  • Payment badges and app placeholders have stronger light and dark contrast.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Open refund] --> B{Already loading?}
    B -->|Yes| C[Ignore repeated click]
    B -->|No| D{Previous refund unsettled?}
    D -->|Yes| E[Show loading view and reload payment]
    E --> F{Reload succeeded?}
    F -->|No| G[Show error and keep previous refund state]
    F -->|Yes| H{Still refundable?}
    H -->|No| I[Keep payment details]
    H -->|Yes| J[Create new refund ID]
    D -->|No| J
    J --> K[Show refund form]
Loading

Reviews (5) · Last reviewed commit: "fix(payments): load the payment once bef..." · Reviewed by Greptile

Comment thread libs/mocks/src/lib/realtime/payments.ts Resolved
The Workplace Payments page now clears its lists and loads again when
the building changes, and ignores the replies of older loads. A failed
release after a failed save now shows the payment ID. New mock products
keep their generated ID.
@MrYuion

MrYuion commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Note

🤖 Claude Opus 5.5 responding on behalf of Alex Sorafumo

refund_payment is not safe to retry. I propose an optional 4th argument, request_id.

Problem: the driver can make the refund, but the response can fail to get to the UI (a timeout or a dropped websocket). The modal then shows an error, staff select Refund again, and the driver makes a second refund. The contract has no value that connects the two calls, so the driver cannot tell a retry from a new refund.

Proposal

/** Privileged. Refund all of a payment when `amount` is `null`. A retry with the same `request_id` does not refund again */
refund_payment(id: string, amount: number | null, reason: string, request_id?: string | null): Payment;
  • payment-details-modal.component.ts: make a request ID (crypto.randomUUID()) when the refund view opens. Send that ID in refund() and keep it for retries from the same view. Make a new ID only when the view opens again.
  • docs/payments.md: add request_id to the refund_payment row (maximum 100 characters).
  • The mock $refund_payment can ignore the argument.

Driver side (done): PlaceOS/drivers#654 accepts request_id now. It is optional, so the call in this PR still works. The driver keeps the ID in the Stripe refund metadata. On a retry, if a refund with that ID exists and did not fail, the driver returns the payment and does not refund again. Refunds run one at a time in the driver, so two calls with the same ID at the same time also refund only once.

…nd a refund request ID

The failed release message from the last commit was replaced at once by
the save error toast of the booking flows. A failed release is now the
error that postForm throws, so the user sees the payment ID.

refund_payment takes an optional request_id. The payment details make a
new ID when the refund view opens and send the same ID on a retry, so a
lost response does not refund twice.
Comment thread libs/mocks/src/lib/realtime/payments.ts Resolved
A retry with a changed amount or reason now gets a new request_id, so
the driver does not skip it as a repeat. The mock driver refunds once
for a repeated request_id, like the contract says.
A new request ID for changed values could refund twice when the lost
request had refunded. After a failed refund, the amount and the reason
now stay fixed, so a retry sends the same request. Opening the refund
view again loads the payment first, then starts a new refund.
Show the loading view while the refund view reloads the payment, and
ignore a second click, so a late reply cannot change the refund ID of
an open refund.
@MrYuion
MrYuion merged commit 8bef489 into develop Nov 23, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant