feat(payment): support user-bound seven-discount offers

This commit is contained in:
Codex
2026-07-23 16:11:20 +08:00
parent 64ba720121
commit 6721b6eb43
39 changed files with 418 additions and 28 deletions
@@ -81,4 +81,38 @@ describe("PaymentApi", () => {
});
expect(response.message).toBe("Thank you for the thoughtful gift.");
});
it("accepts a server-issued offer before opening the subscription page", async () => {
httpClientMock.mockResolvedValue({
success: true,
data: {
commercialOfferId: "offer-1",
planId: "vip_annual",
subscriptionType: "vip",
discountPercent: 30,
pricePercent: 70,
expiresAt: "2026-07-24T08:00:00+00:00",
message: "I got it for you.",
promotionType: "commercial_seven_discount",
},
});
const response = await new PaymentApi().acceptCommercialOffer("offer-1");
expect(httpClientMock).toHaveBeenCalledWith(
"/api/payment/commercial-offers/offer-1/accept",
{ method: "POST" },
);
expect(response.discountPercent).toBe(30);
});
it("requests an offer-scoped plan catalog without changing the public call", async () => {
httpClientMock.mockResolvedValue({ success: true, data: { plans: [] } });
await new PaymentApi().getPlans("offer-1");
expect(httpClientMock).toHaveBeenCalledWith("/api/payment/plans", {
query: { commercialOfferId: "offer-1" },
});
});
});