You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat(billing): refund packId + attachUsageHeader + admin endpoints (PR-N7)
P1.4 + P1.5 + P1.6 — round out the billing surface required for safe meter mode.
- P1.4: refund correlation now uses packId from charge.metadata when present
(no more ambiguous_pack_match silently failing). Legacy fallback to
meterUnits heuristic preserved for topups created before the change.
createExtrasCheckout already stamped packId in both session.metadata
and payment_intent_data.metadata, so no session-side change needed.
- P1.5: new billing.attachUsageHeader config flag (default false). When true
and meterMode also true, billing routes mount attachUsageContext
middleware → emits X-Meter-Remaining header.
- P1.6: new admin endpoints, gated by existing CASL platform-admin grant:
- POST /api/admin/billing/refund → BillingRefundService.refundCharge
- POST /api/admin/billing/plans/bump → BillingPlanService.bumpVersion
Zod-validated bodies (invalid → 422 per existing model.isValid).
* fix(billing): address review — guard order, reason enum, amountCents optional, bumpVersionWithRetry
- billing.routes.js: move attachUsageContext after policy.isAllowed to avoid
unnecessary DB reads on unauthorized requests
- billing.subscription.schema.js: constrain AdminRefundRequest.reason to Stripe
enum ['duplicate','fraudulent','requested_by_customer']; make amountCents
optional to support full refunds; require meterQuota in AdminBumpPlanRequest
(mirrors Mongoose schema required:true + BillingPlanBump Zod schema)
- billing.admin.controller.js: use bumpVersionWithRetry (retry on E11000 race);
return 502 Bad Gateway for unexpected errors instead of 422
- billing.extra.service.js: update refundPartial @returns JSDoc to include
optional reason field in early-exit paths
- tests: mock bumpVersionWithRetry, add tests for reason enum validation,
full refund without amountCents, and bump without meterQuota (422)
* test(billing): add error-path coverage for admin controller (502 + 422)
Cover the upstream error (502 Bad Gateway) and invalid-argument error (422)
branches in both adminRefundCharge and adminBumpPlanVersion to restore
codecov/project coverage to pre-PR baseline.
0 commit comments