@growth-operations/ui-shared 1.5.7 → 1.5.8
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 +1 -1
- package/src/billing/BillingTab.jsx +49 -53
package/package.json
CHANGED
|
@@ -140,9 +140,10 @@ function StatusPanel({ entitlement }) {
|
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
// Pre-creates a Stripe
|
|
144
|
-
// { portalUrl, loading, error }.
|
|
145
|
-
// the
|
|
143
|
+
// Pre-creates a Stripe Customer Portal session on mount (in-iframe POST) and
|
|
144
|
+
// returns { portalUrl, loading, error, notReady }. Used by the TRIAL arm only —
|
|
145
|
+
// the credits arm builds a direct /v1/billing/portal/start link instead (no
|
|
146
|
+
// in-iframe fetch, avoiding the billing service's cold-start timeout).
|
|
146
147
|
function usePortalSession({ context, state, appKey }) {
|
|
147
148
|
const [loading, setLoading] = useState(true);
|
|
148
149
|
const [error, setError] = useState(null);
|
|
@@ -169,18 +170,11 @@ function usePortalSession({ context, state, appKey }) {
|
|
|
169
170
|
resetOnUnmount();
|
|
170
171
|
return;
|
|
171
172
|
}
|
|
172
|
-
// No Stripe customer yet → don't even try to open a portal.
|
|
173
|
-
// that hasn't been provisioned
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
// the trial arm relies on `status`.
|
|
178
|
-
const ent = state?.entitlement;
|
|
179
|
-
const status = ent?.status;
|
|
180
|
-
const onPaidPlan = !!ent?.plan;
|
|
181
|
-
const notProvisioned =
|
|
182
|
-
!ent || status === "not_installed" || (status == null && !onPaidPlan);
|
|
183
|
-
if (notProvisioned) {
|
|
173
|
+
// No Stripe customer yet → don't even try to open a portal. A trial
|
|
174
|
+
// install that hasn't been provisioned (no entitlement, or status null/
|
|
175
|
+
// not_installed) has nothing to manage; show the calm "not ready" state.
|
|
176
|
+
const status = state?.entitlement?.status;
|
|
177
|
+
if (!state.entitlement || status == null || status === "not_installed") {
|
|
184
178
|
if (mounted.current) {
|
|
185
179
|
setNotReady(true);
|
|
186
180
|
setLoading(false);
|
|
@@ -293,16 +287,28 @@ function TrialSubscriptionBilling({ context, state, appKey }) {
|
|
|
293
287
|
}
|
|
294
288
|
|
|
295
289
|
function CreditsBilling({ context, state, appKey }) {
|
|
296
|
-
// The Stripe portal session lets an EXISTING paid customer manage/switch/cancel
|
|
297
|
-
// their plan, with proration handled by Stripe.
|
|
298
|
-
const { portalUrl, loading, error, notReady } = usePortalSession({
|
|
299
|
-
context,
|
|
300
|
-
state,
|
|
301
|
-
appKey,
|
|
302
|
-
});
|
|
303
|
-
|
|
304
290
|
const onPaidPlan = !!state?.entitlement?.plan;
|
|
305
291
|
|
|
292
|
+
// Direct external link to the billing service's GET /v1/billing/portal/start,
|
|
293
|
+
// which resolves the customer + creates the Customer Portal session server-side
|
|
294
|
+
// and 303s to Stripe — IN THE OPENED TAB. No in-iframe portal-session fetch
|
|
295
|
+
// (that round trip hit the billing service's cold-start/CPU stall and surfaced
|
|
296
|
+
// as the iframe's 15s "Gateway took too long" error). Same pattern as
|
|
297
|
+
// PlanGrid's /checkout/start "Choose" button. null (button disabled) until
|
|
298
|
+
// billing_base_url is known.
|
|
299
|
+
const base = state?.billing_base_url ?? null;
|
|
300
|
+
const portalId = context?.portal?.id;
|
|
301
|
+
const returnUrl = state?.app_id
|
|
302
|
+
? `https://app.hubspot.com/app/${portalId}/${state.app_id}/billing`
|
|
303
|
+
: "https://app.hubspot.com/";
|
|
304
|
+
const portalStartUrl =
|
|
305
|
+
base && appKey && portalId
|
|
306
|
+
? `${base}/v1/billing/portal/start` +
|
|
307
|
+
`?app_key=${encodeURIComponent(appKey)}` +
|
|
308
|
+
`&portal_id=${encodeURIComponent(String(portalId))}` +
|
|
309
|
+
`&return_url=${encodeURIComponent(returnUrl)}`
|
|
310
|
+
: null;
|
|
311
|
+
|
|
306
312
|
// PAID: do NOT show the plan picker. The picker's "Choose" starts a NEW Stripe
|
|
307
313
|
// Checkout subscription — clicking another tier would create a SECOND
|
|
308
314
|
// subscription (double-bill), not switch in place. Plan changes (upgrade/
|
|
@@ -316,21 +322,15 @@ function CreditsBilling({ context, state, appKey }) {
|
|
|
316
322
|
entitlement={state?.entitlement}
|
|
317
323
|
creditMeter={state?.credit_meter}
|
|
318
324
|
/>
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
disabled={!portalUrl}
|
|
329
|
-
variant="primary"
|
|
330
|
-
>
|
|
331
|
-
{portalUrl ? "Manage subscription" : "Preparing billing…"}
|
|
332
|
-
</LoadingButton>
|
|
333
|
-
))}
|
|
325
|
+
<LoadingButton
|
|
326
|
+
href={
|
|
327
|
+
portalStartUrl ? { url: portalStartUrl, external: true } : undefined
|
|
328
|
+
}
|
|
329
|
+
disabled={!portalStartUrl}
|
|
330
|
+
variant="primary"
|
|
331
|
+
>
|
|
332
|
+
{portalStartUrl ? "Manage subscription" : "Preparing billing…"}
|
|
333
|
+
</LoadingButton>
|
|
334
334
|
<Text format={{ fontStyle: "italic" }}>
|
|
335
335
|
Change or cancel your plan in Stripe — billing is managed across all
|
|
336
336
|
Growth Operations apps.
|
|
@@ -350,21 +350,17 @@ function CreditsBilling({ context, state, appKey }) {
|
|
|
350
350
|
creditMeter={state?.credit_meter}
|
|
351
351
|
/>
|
|
352
352
|
<PlanGrid context={context} state={state} appKey={appKey} />
|
|
353
|
-
{!
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
>
|
|
365
|
-
{portalUrl ? "Buy credits in Stripe" : "Preparing billing…"}
|
|
366
|
-
</LoadingButton>
|
|
367
|
-
))}
|
|
353
|
+
{!hasPlans && (
|
|
354
|
+
<LoadingButton
|
|
355
|
+
href={
|
|
356
|
+
portalStartUrl ? { url: portalStartUrl, external: true } : undefined
|
|
357
|
+
}
|
|
358
|
+
disabled={!portalStartUrl}
|
|
359
|
+
variant="primary"
|
|
360
|
+
>
|
|
361
|
+
{portalStartUrl ? "Buy credits in Stripe" : "Preparing billing…"}
|
|
362
|
+
</LoadingButton>
|
|
363
|
+
)}
|
|
368
364
|
{!hasPlans && (
|
|
369
365
|
<Text format={{ fontStyle: "italic" }}>
|
|
370
366
|
Billing is managed in Stripe across all Growth Operations apps.
|