Repository navigation
Conversation
# Conflicts: # frontend/src/routes/availability/+page.svelte
|
GitHub failed this run before it could start. Pullfrog runs on many other repositories failed to start at the same time, so nothing in this repository caused it. Nothing was billed for it. |
|
Heads up: your CI runs are failing to start, and it is not your code. Every workflow on this PR ended in Two things on our side, so you are not waiting on silence:
Could you rebase onto current If a fresh push still fails to start, tell me and I will keep digging, because that would point at something repo-level rather than at your branch. |
4ae6da3 to
656beaf
Compare
|
Well I borked that up. |
There was a problem hiding this comment.
Caution
This PR introduces an unauthenticated path to marking any pending booking as paid, and the MakeCommerce integration as written cannot confirm or refund a real payment. The payment code needs another pass before this merges.
Reviewed changes — the delta since the last reviewed commit (4ae6da3), which here is effectively the whole PR since no prior pullfrog review exists:
- Replaced the Stripe client with MakeCommerce — new
internal/makecommercepackage exposing a Stripe-shaped API, withhandlerandserverrepointed at it under thestripealias. - Rewrote the payment flow around it — form-encoded
json/macwebhook,notification_urlcarrying the booking id as a query parameter,customer.ipfrom a newclientIPhelper, env-var-only credentials. - Added event-type scoping to availability rules —
PATCH /v1/availability-rules/{id}now acceptsevent_type_id, and the admin availability page gained a per-blockSelect. - Centered the booking card —
margin-left/right: autoon.cardin the sharedbooking.css, plus page-local vertical auto-margins inbook.html. - Hardcoded
et-EEfor time formatting on the booking page and the embed widget, and addedEurope/Tallinnto the admin timezone list.
ℹ️ A payment-provider swap is riding along with a CSS fix
The title is "Center booking elements", but roughly 1,200 of the added lines replace the payment provider, add an availability feature, and change booking-page localization. Two consequences need a human decision rather than a patch: internal/stripe is now imported by nothing yet still built and tested, while docs/ARCHITECTURE.md continues to describe it as the payments client; and Settings → Payments still writes the stripe_secret_key_enc / stripe_webhook_secret_enc columns that the new client never reads. Either split the payment work into its own PR or update the docs and the settings surface in this one — as shipped, an operator who configures payments in the UI gets a silently dead integration.
Technical details
# Scope: payments replacement bundled with an unrelated CSS change
## Affected sites
- `internal/makecommerce/` — new package, referenced via `stripe "…/makecommerce"` in `internal/handler/handler.go:18`, `internal/handler/stripe_booking.go:9`, `internal/handler/stripe_settings.go`, `internal/server/server.go`
- `internal/stripe/` — no importers remain (`grep -r internal/stripe` matches only `docs/ARCHITECTURE.md:1144`)
- `internal/handler/stripe_settings.go` — `PatchStripeSettings` still persists `stripe_*` columns that `makecommerce.New` ignores
- `docs/ARCHITECTURE.md:1144` — still documents `internal/stripe` as the payments client
## Required outcome
- The repo documents one payments client, and the admin settings it writes are the ones the runtime reads.
- Reviewers can tell which behavior change belongs to the "center booking elements" intent.
## Open questions for the human
- Is the Stripe removal intended to land in this PR, or was it incidental to the local branch?
- If MakeCommerce is the new default, does the settings UI keep the Stripe labels/column names, or does it get renamed?deepseek-v4.1-flash | 𝕏
| formValues, err := url.ParseQuery(string(payload)) | ||
| if err != nil { | ||
| // If not form-encoded, try parsing as raw JSON (fallback for testing) | ||
| return c.verifyWebhookFromJSON(payload) | ||
| } |
There was a problem hiding this comment.
When url.ParseQuery fails, this hands the raw body to verifyWebhookFromJSON, which parses it and never checks a MAC (its own comment says so). That branch is reachable from the network: a body that is valid JSON but an invalid query string — e.g. {"status":"COMPLETED","transaction":"x","%zz":1} — reaches it, and VerifyWebhook then returns a checkout.session.completed event with payment_status=paid. Combined with the query-param booking id in StripeWebhook, that is a free-booking bypass. The fallback needs to go: return the parse error and require a valid json+mac pair.
Technical details
# Unsigned webhook fallback is remotely reachable
## Affected sites
- `internal/makecommerce/makecommerce.go:391-395` — `ParseQuery` error → `verifyWebhookFromJSON(payload)`
- `internal/makecommerce/makecommerce.go:481-525` — the fallback parser; no `mac` handling at all, `status` from the body drives `mapWebhookType`
- `internal/handler/stripe_booking.go:72-93` — consumes the returned event and confirms the booking
## Evidence
A throwaway test in the package:
```go
c := &Client{webhookSecret: "webhookSecret", secretKey: "realsecret"}
body := []byte(`{"%zz":"x","status":"COMPLETED","transaction":"txn_1","amount":"0","currency":"EUR"}`)
ev, err := c.VerifyWebhook(body, "", time.Now())
// err == nil; ev.Type == "checkout.session.completed"; sess.PaymentStatus == "paid"
```
## Required outcome
- A payload that cannot be parsed as `json`+`mac` form data is rejected, not re-parsed as trusted JSON.
- Tests can build signed form payloads with the existing `signMC` helper instead of needing an unsigned path — `TestVerifyWebhook*` already does exactly that.| // The secretKey is used for authentication and webhook verification. | ||
| // The publishableKey is optional and used for client-side operations if needed. | ||
| // The webhookSecret should be the same as secretKey for MakeCommerce. | ||
| func New(_, _, _ string) (*Client, error) { |
There was a problem hiding this comment.
New discards all three credentials it is given and requires MK_SHOPID, MK_SECRETKEY, MK_PUBLISHABLEKEY and MK_APIURL from the environment. That inverts this repo's rule that stored settings win over env: boot logs payment: init failed and leaves payments off even when credentials are saved, and PatchStripeSettings writes the row and then returns 500. It also breaks the tests added in this PR — go test ./internal/makecommerce/ panics on New("secret", …) returning nil, and TestRefundBookingPayment_failureRevertsClaim fails with makecommerce: shop ID required.
Technical details
# Credentials must come from the arguments, not MK_* env vars
## Affected sites
- `internal/makecommerce/makecommerce.go:51-81` — `func New(_, _, _ string)`, env-only config
- `internal/server/server.go` (~payments init) — `stripe.New(dbStripe.SecretKey, dbStripe.PublishableKey, dbStripe.WebhookSecret)`; non-nil error path logs and skips `SetStripe`
- `internal/handler/stripe_settings.go` — `PatchStripeSettings` persists credentials, then `stripe.New` fails → `failed to initialize payment client` after the write
- `internal/makecommerce/makecommerce_test.go` — `TestNew`/`TestPublishableKey`/`TestWebhookConfigured`/`TestSetAPIBase` all assume the args are honoured
- `internal/handler/stripe_refund_test.go` — fails via `refundTestClient`
## Observed
```
--- FAIL: TestNew New: makecommerce: shop ID required
--- FAIL: TestPublishableKey panic: nil pointer dereference (makecommerce.go:88)
--- FAIL: TestRefundBookingPayment_failureRevertsClaim makecommerce: shop ID required
```
## Required outcome
- `New(secretKey, publishableKey, webhookSecret)` honours its parameters, matching every other provider client in this repo and the tests as written.
- If `shopId` / `apiBase` must be configurable, add them as explicit parameters or a typed options struct sourced from the same stored settings — not a second, undocumented configuration channel.
- `go test ./internal/makecommerce/ ./internal/handler/` passes.| shopId: shopId, | ||
| secretKey: secretKey, | ||
| publicKey: publishableKey, | ||
| webhookSecret: "webhookSecret", |
There was a problem hiding this comment.
webhookSecret is set to the literal string "webhookSecret", so WebhookConfigured() reports true while every real notification fails MAC verification — MakeCommerce signs with the API secret (the MAC helper at :472 already uses c.secretKey). The result is that checkout.session.completed is always rejected and no paid booking ever leaves pending. It should be the secret key (or the stored webhook secret).
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, | ||
| c.apiBase+"/"+apiVersion+"/refunds", | ||
| bytes.NewReader(jsonBody)) | ||
| if err != nil { | ||
| return fmt.Errorf("makecommerce: create refund request: %w", err) | ||
| } | ||
|
|
||
| req.SetBasicAuth("f7741ab2-7445-45f9-9af4-0d0408ef1e4c", c.secretKey) |
There was a problem hiding this comment.
This refund calls POST /v1/refunds, which is MakeCommerce's list endpoint; creating one is POST /v1/transactions/{transaction_id}/refunds with a body of amount + comment. It also authenticates with a hardcoded shop id instead of c.shopId — f7741ab2-… is the demo shop from MakeCommerce's own SDK sample, whose secret is pasted in makecommerce_test.go:496/499, so a real shop's key is paired with a third party's shop. Refunds therefore 404 or 401, refundBookingPayment reverts the claim, and the money is never returned — while the mocked TestRefund pins the wrong contract as expected behaviour.
Technical details
# Refund contract does not match the vendor API
## Affected sites
- `internal/makecommerce/makecommerce.go:339-349` — path, headers, Basic auth
- `internal/makecommerce/makecommerce.go:327-332` — body: `transaction_id`/`amount`/`currency`/`description`
- `internal/makecommerce/makecommerce_test.go` `TestRefund` — asserts `POST /v1/refunds` and the `transaction_id` body field
- `internal/handler/stripe_booking.go:198-211` — treats a nil error as "refunded"
## Vendor contract
- https://developer.makecommerce.net/api/create-refund/ — `POST /v1/transactions/:transaction_id/refunds`, body `amount` + `comment` (+ optional `app_info`); `GET /v1/refunds` is the refund *list*.
## Required outcome
- Refunds hit the documented endpoint with the documented body, authenticated as `c.shopId`.
- The response's refund status is inspected: a 2xx can still carry `status: FAILED`, and `refundBookingPayment` currently records any 2xx as `refunded`.
- `amount` is sourced from the amount actually paid (`amount_paid_cents`) rather than from a transaction fetch.| bookingId := r.URL.Query().Get("booking_id") | ||
| if bookingId == "" { | ||
| h.writeError(w, http.StatusBadRequest, "param missing") | ||
| } |
There was a problem hiding this comment.
The booking being confirmed is taken from the unsigned query string, so nothing binds the (verified) transaction to that booking: a valid notification for transaction A can be replayed with ?booking_id=B and marks B paid, because confirmPaidBooking only requires payment_status = 'pending'. Read the booking id from the verified payload instead — MakeCommerce echoes merchant_data / the notification's reference — and fall back to the metadata path that was removed at :91. Also: the 400 branch at :81-83 has no return.
| const r = await api.post<AvailabilityRule>('/v1/availability-rules', { | ||
| day_of_week: day.day_of_week, | ||
| start_time: '09:00', | ||
| end_time: '17:00' | ||
| }); |
There was a problem hiding this comment.
day_of_week was dropped from this create payload, and CreateAvailabilityRule decodes a missing field as 0, so every block added from the UI is created on Sunday. Adding a block to Wednesday shows it on Sunday after refresh, and a second add collides with the (user_id, event_type_id, day_of_week, start_time, end_time) unique index and gets spliced back out with an error. Restore day_of_week: day.day_of_week.
| // Accept-Language differs from navigator.language, would see translated chrome next | ||
| // to month/day names in a different language. See internal-docs/i18n-plan.md. | ||
| function fmtTime(iso) { return BookingLogic.formatTime(iso, TZ, LOCALE); } | ||
| function fmtTime(iso) { return BookingLogic.formatTime(iso, TZ, "et-EE"); } |
There was a problem hiding this comment.
Hardcoding et-EE discards the server-resolved LOCALE and gives every visitor Estonian clock labels next to localized chrome — the exact regression the comment three lines above describes. The same change landed in internal/handler/embed.js:97-98, where timeLabel/shortDay still accept a locale argument and now ignore it, so that parameter is dead. Locale must stay server-resolved (LOCALE / this.locale); if a per-visitor override is wanted, it has a ?lang= path already.

This PR adds horizontal auto-margins to the booking page with the intention to target the embeddable widget. Also adds vertical centering to move the booking "island" to the center of the screen.
Before:

After:
