From 0f8cc3388823581c33e073f0f33f918d5d8e399a Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:23:05 +0100 Subject: [PATCH 1/3] feat(trial): GET /v1/trial-offers/{id} for the waiting page The page that sent the offer waits for the e-mail confirmation. When the link is opened on another device (a phone), that page stayed put (portal#159, item 1). The status read lets it follow: the state and, once active, the workspace slug and the trial dates. No e-mail or company data in the answer; the offer id, which only the sending browser has, is the key. Same authz group as the other offer routes. Co-Authored-By: Claude Opus 5.5 --- internal/server/server.go | 1 + internal/server/trialoffers.go | 37 +++++++++++++++++++++++++++++ internal/server/trialoffers_test.go | 36 ++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/internal/server/server.go b/internal/server/server.go index e006209..b70cdb5 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -146,6 +146,7 @@ func NewRouter(s *Server) http.Handler { mux.HandleFunc("POST /v1/trial-offers", s.createTrialOffer) mux.HandleFunc("POST /v1/trial-offers/verify", s.verifyTrialOffer) mux.HandleFunc("POST /v1/trial-offers/{id}/resend", s.resendTrialOffer) + mux.HandleFunc("GET /v1/trial-offers/{id}", s.trialOfferStatus) mux.HandleFunc("GET /v1/tenants/{id}/contracts/trial/terms.pdf", s.tenantTrialTermsPDF) // Contract documents (AGB, AVV, TOM, Leistungsbeschreibungen): ".pdf". mux.HandleFunc("GET /v1/tenants/{id}/contracts/documents/{file}", s.tenantContractDocumentPDF) diff --git a/internal/server/trialoffers.go b/internal/server/trialoffers.go index 6a185c8..e497128 100644 --- a/internal/server/trialoffers.go +++ b/internal/server/trialoffers.go @@ -306,6 +306,43 @@ func (s *Server) resendTrialOffer(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusAccepted, trialOfferResp{OfferID: o.ID, State: o.State, Email: o.Email, OfferedAt: o.OfferedAt, ReceiptMailSent: sent}) } +// trialOfferStatus is GET /v1/trial-offers/{id} (portal-svc): where the offer +// stands, so the page that sent it can follow a confirmation made on another +// device (the link opened on a phone) instead of waiting for a reload. The +// offer id, which only the sending browser has, is the key; the answer holds +// nothing beyond the state and, once active, the workspace and the dates. +func (s *Server) trialOfferStatus(w http.ResponseWriter, r *http.Request) { + ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) + defer cancel() + o, err := s.Store.GetTrialOffer(ctx, r.PathValue("id")) + if err != nil { + if mapStoreError(w, err) { + return + } + writeError(w, http.StatusInternalServerError, "internal", err.Error()) + return + } + resp := trialOfferStatusResp{OfferID: o.ID, State: o.State} + if o.State == store.OfferActivated { + resp.TrialStartedAt, resp.TrialExpiresAt = o.TrialStartedAt, o.TrialExpiresAt + if t, err := s.Store.GetTenant(ctx, o.TenantID); err == nil { + resp.TenantSlug = t.Slug + if t.TrialEndsAt != nil && o.TrialExpiresAt != nil && t.TrialEndsAt.After(*o.TrialExpiresAt) { + resp.TrialExpiresAt = t.TrialEndsAt // extended by staff + } + } + } + writeJSON(w, http.StatusOK, resp) +} + +type trialOfferStatusResp struct { + OfferID string `json:"offer_id"` + State string `json:"state"` + TenantSlug string `json:"tenant_slug,omitempty"` + TrialStartedAt *time.Time `json:"trial_started_at,omitempty"` + TrialExpiresAt *time.Time `json:"trial_expires_at,omitempty"` +} + // ─── confirmation and activation ─────────────────────────────────────────── type verifyReq struct { diff --git a/internal/server/trialoffers_test.go b/internal/server/trialoffers_test.go index 2838630..a07432e 100644 --- a/internal/server/trialoffers_test.go +++ b/internal/server/trialoffers_test.go @@ -262,6 +262,42 @@ func TestTrialOffer_expiredLinkAndResend(t *testing.T) { }) } +func TestTrialOffer_status(t *testing.T) { + eachStore(t, func(t *testing.T, h *testHarness) { + rec := &mail.Recorder{} + h.app.Mail = rec + _, raw := h.do("POST", "/v1/trial-offers", trialOffer("phone@firma.de")) + var offer map[string]string + _ = json.Unmarshal(raw, &offer) + id := offer["offer_id"] + + resp, raw := h.do("GET", "/v1/trial-offers/"+id, nil) + var st map[string]any + _ = json.Unmarshal(raw, &st) + if resp.StatusCode != 200 || st["state"] != "email_verification_pending" || st["tenant_slug"] != nil || st["trial_expires_at"] != nil { + t.Fatalf("pending %d %s", resp.StatusCode, raw) + } + if strings.Contains(string(raw), "phone@firma.de") { + t.Fatalf("status leaks the e-mail address: %s", raw) + } + + // confirmed on another device: the sending page sees it + if resp, raw = h.do("POST", "/v1/trial-offers/verify", map[string]string{"token": lastToken(t, rec)}); resp.StatusCode != 200 { + t.Fatalf("verify %d %s", resp.StatusCode, raw) + } + resp, raw = h.do("GET", "/v1/trial-offers/"+id, nil) + st = map[string]any{} + _ = json.Unmarshal(raw, &st) + if resp.StatusCode != 200 || st["state"] != "activated" || st["tenant_slug"] == nil || st["tenant_slug"] == "" || st["trial_expires_at"] == nil { + t.Fatalf("activated %d %s", resp.StatusCode, raw) + } + + if resp, _ = h.do("GET", "/v1/trial-offers/does-not-exist", nil); resp.StatusCode != 404 { + t.Fatalf("unknown offer %d", resp.StatusCode) + } + }) +} + func TestTrialOffer_slugCollisionAndFailedActivation(t *testing.T) { eachStore(t, func(t *testing.T, h *testHarness) { rec := &mail.Recorder{} From d0b1287afb1ec529afc3a5346174301bbd39b7c4 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:34:46 +0100 Subject: [PATCH 2/3] feat(trial): offer address in the contract overview GET /v1/tenants/{id}/contracts carries street, postcode, city and country of the trial offer, so the company profile can suggest the registration address as the master data (portal#159, item 3; read by portal#161). Only for the tenant's own activated offer, as the rest of the trial block. Co-Authored-By: Claude Opus 5.5 --- internal/server/trialoffers.go | 7 +++++++ internal/server/trialoffers_test.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/internal/server/trialoffers.go b/internal/server/trialoffers.go index e497128..0401575 100644 --- a/internal/server/trialoffers.go +++ b/internal/server/trialoffers.go @@ -613,6 +613,12 @@ type trialContract struct { AcceptingPersonName string `json:"accepting_person_name"` AcceptingEmail string `json:"accepting_email"` CompanyName string `json:"company_name"` + // The address the offer was made with, so the company profile can + // suggest it as the master data (portal#159, item 3). + Street string `json:"street"` + Postcode string `json:"postcode"` + City string `json:"city"` + Country string `json:"country"` } type contractStatus struct { @@ -659,6 +665,7 @@ func (s *Server) listTenantContracts(w http.ResponseWriter, r *http.Request) { TrialStartedAt: o.TrialStartedAt, TrialExpiresAt: end, TermsVersion: o.TermsVersion, TermsDate: date, TermsSHA256: o.TermsSHA256, AcceptingPersonName: o.FirstName + " " + o.LastName, AcceptingEmail: o.Email, CompanyName: o.CompanyName, + Street: o.Street, Postcode: o.Postcode, City: o.City, Country: o.Country, } } else if err != nil && !errors.Is(err, store.ErrNotFound) { writeError(w, http.StatusInternalServerError, "internal", err.Error()) diff --git a/internal/server/trialoffers_test.go b/internal/server/trialoffers_test.go index a07432e..f692e9a 100644 --- a/internal/server/trialoffers_test.go +++ b/internal/server/trialoffers_test.go @@ -201,6 +201,12 @@ func TestTrialOffer_offerConfirmActivate(t *testing.T) { c.AVV.Status != "not_concluded" || c.TOMs.Status != "pending" || c.SaaS.Status != "not_concluded" { t.Fatalf("contracts %d %s", resp.StatusCode, raw) } + // the address of the offer, for the company profile's suggestions + for _, want := range []string{`"street":"Hauptstr. 1"`, `"postcode":"78224"`, `"city":"Singen"`, `"country":"DE"`} { + if !strings.Contains(string(raw), want) { + t.Fatalf("contracts lack %s: %s", want, raw) + } + } resp, raw = h.do("GET", "/v1/tenants/"+tn.ID+"/contracts/trial/terms.pdf", nil) if resp.StatusCode != 200 || !bytes.Equal(raw, v.PDF) || !strings.HasPrefix(resp.Header.Get("Content-Disposition"), "attachment") { t.Fatalf("contract pdf %d %v", resp.StatusCode, resp.Header) From 2e6f360751a47195a6ccb7bf11cb8a44d7c7b804 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:42:48 +0100 Subject: [PATCH 3/3] test(trial): status read shows a staff-extended trial end Co-Authored-By: Claude Opus 5.5 --- internal/server/trialoffers_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/server/trialoffers_test.go b/internal/server/trialoffers_test.go index f692e9a..1592a08 100644 --- a/internal/server/trialoffers_test.go +++ b/internal/server/trialoffers_test.go @@ -2,6 +2,7 @@ package server_test import ( "bytes" + "context" "encoding/json" "io" "net/http" @@ -301,6 +302,27 @@ func TestTrialOffer_status(t *testing.T) { if resp, _ = h.do("GET", "/v1/trial-offers/does-not-exist", nil); resp.StatusCode != 404 { t.Fatalf("unknown offer %d", resp.StatusCode) } + + // staff extended the trial: the status shows the later end + before, _ := st["trial_expires_at"].(string) + tn, err := h.store.GetTenantBySlug(context.Background(), st["tenant_slug"].(string)) + if err != nil { + t.Fatal(err) + } + req, _ := http.NewRequest("POST", h.srv.URL+"/v1/admin/tenants/"+tn.ID+"/trial", strings.NewReader(`{"days":30}`)) + req.Header.Set("Content-Type", "application/json") + req.Header.Set("X-Portal-User-Email", "staff@breakpilot.com") + ext, err := http.DefaultClient.Do(req) + if err != nil || ext.StatusCode != 200 { + t.Fatalf("extend %v %v", err, ext) + } + _ = ext.Body.Close() + _, raw = h.do("GET", "/v1/trial-offers/"+id, nil) + st = map[string]any{} + _ = json.Unmarshal(raw, &st) + if after, _ := st["trial_expires_at"].(string); after == "" || after <= before { + t.Fatalf("extended end not shown: before %q, now %s", before, raw) + } }) }