feat: confirm an agency plan switch only from the price and billing period its preview was made for, let a switch Stripe already holds be previewed and completed, hold keyed requests on agency routes to the agency's staff before any answer is recorded or replayed, and bound the switch locks

This commit is contained in:
Matthew Meszaros
2026-11-11 09:18:27 +01:00
parent a170997c17
commit 72c0777c33
14 changed files with 148 additions and 26 deletions
+6 -3
View File
@@ -10,6 +10,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/warmbly/warmbly/internal/api/middleware"
"github.com/warmbly/warmbly/internal/app/agency"
"github.com/warmbly/warmbly/internal/errx"
"github.com/warmbly/warmbly/internal/models"
)
@@ -536,8 +537,9 @@ func (h *Handler) ChangeAgencyPlan(c *gin.Context) {
var req struct {
PlanID string `json:"plan_id"`
Interval string `json:"interval"`
// ProrationDate is the preview's, so the switch bills what was shown.
ProrationDate int64 `json:"proration_date"`
// ProrationDate and FromPriceID are the preview's, so the switch bills what was shown.
ProrationDate int64 `json:"proration_date"`
FromPriceID string `json:"from_price_id"`
}
if err := c.ShouldBindJSON(&req); err != nil {
errx.JSON(c, errx.InvalidBody(err))
@@ -551,7 +553,8 @@ func (h *Handler) ChangeAgencyPlan(c *gin.Context) {
errx.JSON(c, errx.New(errx.BadRequest, "proration_date must be the value a preview returned"))
return
}
a, xerr := h.AgencyService.ChangePlan(c.Request.Context(), agencyID, userID, planID, yearly, req.ProrationDate)
a, xerr := h.AgencyService.ChangePlan(c.Request.Context(), agencyID, userID, planID, yearly,
agency.PlanChangeQuote{ProrationDate: req.ProrationDate, FromPriceID: strings.TrimSpace(req.FromPriceID)})
if xerr != nil {
errx.JSON(c, xerr)
return