@startsimpli/billing 0.4.30 → 0.4.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/billing",
3
- "version": "0.4.30",
3
+ "version": "0.4.31",
4
4
  "description": "Universal billing integration for StartSimpli Next.js apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -390,6 +390,38 @@ describe("SubscriptionManager", () => {
390
390
  );
391
391
  });
392
392
 
393
+ it("a failed Manage Billing click shows an error instead of nothing", async () => {
394
+ const router = mockFetchRouter({
395
+ "/billing/subscription/current/": mockSubscriptionActive,
396
+ "/billing/products/": mockProduct,
397
+ }) as unknown as (url: string, init?: RequestInit) => Promise<unknown>;
398
+ const fetcher = vi.fn((url: string, init?: RequestInit) =>
399
+ url.includes("/billing/offer-portal/")
400
+ ? Promise.resolve({
401
+ ok: false,
402
+ status: 500,
403
+ json: () => Promise.resolve({ detail: "Failed to create portal session" }),
404
+ })
405
+ : router(url, init),
406
+ ) as unknown as typeof fetch;
407
+ const Wrapper = createWrapper(fetcher);
408
+
409
+ render(
410
+ <Wrapper>
411
+ <SubscriptionManager
412
+ productId="raise-simpli"
413
+ returnUrl="https://app.test.com/settings"
414
+ />
415
+ </Wrapper>
416
+ );
417
+
418
+ await userEvent.click(await screen.findByTestId("portal-button"));
419
+
420
+ const alert = await screen.findByTestId("portal-error");
421
+ expect(alert.getAttribute("role")).toBe("alert");
422
+ expect(alert.textContent?.trim().length).toBeGreaterThan(0);
423
+ });
424
+
393
425
  it("shows Manage Billing portal button", async () => {
394
426
  const fetcher = mockFetchRouter({
395
427
  "/billing/subscription/current/": mockSubscriptionActive,
@@ -196,7 +196,7 @@ export function SubscriptionManager({
196
196
  }: SubscriptionManagerProps) {
197
197
  const { subscription, loading: subLoading, error: subError, refetch: refetchSubscription } = useSubscription(productId);
198
198
  const { product, loading: productLoading, error: productError, refetch: refetchProduct } = useProduct(productId);
199
- const { openPortal, loading: portalLoading } = usePortal();
199
+ const { openPortal, loading: portalLoading, error: portalError } = usePortal();
200
200
  const { subscribeFree } = useCheckout();
201
201
  const { usage } = useUsage(productId);
202
202
  const { sync: successSync } = useSuccessSync();
@@ -607,6 +607,11 @@ export function SubscriptionManager({
607
607
  >
608
608
  {portalLoading ? "Loading..." : "Manage Billing"}
609
609
  </button>
610
+ {portalError && (
611
+ <p data-testid="portal-error" role="alert" className="mt-3 text-sm text-red-700">
612
+ {portalError.message}
613
+ </p>
614
+ )}
610
615
  </div>
611
616
  )}
612
617