Repository navigation
feat(payments): let users pay for bookings and catering through a payment driver - #748
Conversation
MrYuion
left a comment
There was a problem hiding this comment.
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:
- A booking with asset requests stays charged after its rollback.
- Group desk bookings open one checkout per member, and rollback leaves those payments captured.
- A payment that authorizes more than about 6 seconds after the popup closes can be orphaned, and the user can pay twice.
- A blocked popup in Complete payment hides the link and ends in a cancel 15 minutes later.
- 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".
4b5cf31 to
a6a1f44
Compare
MrYuion
left a comment
There was a problem hiding this comment.
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:
- Asset requests:
postFormcaptures after_saveAssetRequestsand cancels the payment when they fail. - Group bookings:
_takePaymentreturnsnullwhen_options().groupis set, andpostFormForGrouprequiresgroup. - Late authorization:
_resumecallsget_paymentbeforeget_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. - Blocked popup:
completePaymentthrowsPAYMENTS.POPUP_BLOCKEDbefore it calls the driver. - Opt-in checkout: only
apps/workplace/src/app/app.config.tsprovidesPAYMENT_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:
- Take payment captures the rooms that declined.
- 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".
ad532fd to
5360f09
Compare
[Critical impact] The changes since the last review appear safe to merge. SummaryAdds hosted payments for Workplace bookings and catering, plus payment pages and staff tools in Concierge.
|
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.
|
Note 🤖 Claude Opus 5.5 responding on behalf of Alex Sorafumo
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;
Driver side (done): PlaceOS/drivers#654 accepts |
…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.
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.
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
paymentsbinding. Without the binding, nothing changes.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.exclude_resource_idsoncapture_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_checkoutgets anidempotency_key, so a retry after a lost response does not start a second payment.refund_paymenttakes an optionalrequest_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.payment_idlike bookings do.localhost,127.0.0.1and[::1]still work over HTTP for development.PLACEOS.mock_payments.docs/payments.mdhas 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 buildpassed 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 refundrequest_idand the release message in 7ee8a9a, and the refund retry findings in 577a147, 3c632ef and 462e258. No council round has reviewed these commits.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