feat(pay-v2): P8 Task5 订阅取消(API+入站)+ past_due 状态
This commit is contained in:
@@ -105,6 +105,31 @@ func (h *GatewayHandler) GetStatus(c *gin.Context) {
|
||||
util.RespondSuccess(c, v)
|
||||
}
|
||||
|
||||
// GetSubscription GET /api/v2/subscriptions/:sub_id —— 查订阅状态 + 续费锚点。
|
||||
func (h *GatewayHandler) GetSubscription(c *gin.Context) {
|
||||
v, err := h.g.GetSubscription(c.Param("sub_id"))
|
||||
if err != nil {
|
||||
util.RespondError(c, http.StatusNotFound, "subscription_not_found", "订阅不存在")
|
||||
return
|
||||
}
|
||||
util.RespondSuccess(c, v)
|
||||
}
|
||||
|
||||
// CancelSubscription POST /api/v2/subscriptions/:sub_id/cancel —— 主动取消:查订阅 → 渠道
|
||||
// 取消 → 本地翻 canceled + 入队 subscription.canceled(幂等,重复调用 no-op)。
|
||||
func (h *GatewayHandler) CancelSubscription(c *gin.Context) {
|
||||
if err := h.g.CancelSubscription(c.Request.Context(), c.Param("sub_id")); err != nil {
|
||||
if errors.Is(err, store.ErrSubNotFound) {
|
||||
util.RespondError(c, http.StatusNotFound, "subscription_not_found", "订阅不存在")
|
||||
return
|
||||
}
|
||||
log.Printf("[v2 subscription] 取消失败 sub_id=%s: %v", c.Param("sub_id"), err)
|
||||
util.RespondError(c, http.StatusInternalServerError, "cancel_failed", "取消失败,请稍后重试")
|
||||
return
|
||||
}
|
||||
util.RespondSuccess(c, gin.H{"canceled": true})
|
||||
}
|
||||
|
||||
type retryRequest struct {
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user