@fantastic.dev/better-stripe 0.77.0 → 0.79.0
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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/client/core/accountLinks.d.ts +17 -1
- package/dist/client/core/accountLinks.d.ts.map +1 -1
- package/dist/client/core/accountLinks.js +72 -11
- package/dist/client/core/accountLinks.js.map +1 -1
- package/dist/client/core/billingPortalClient.d.ts.map +1 -1
- package/dist/client/core/billingPortalClient.js +1 -1
- package/dist/client/core/billingPortalClient.js.map +1 -1
- package/dist/client/core/billingPortalFlow.d.ts +69 -0
- package/dist/client/core/billingPortalFlow.d.ts.map +1 -0
- package/dist/client/core/billingPortalFlow.js +81 -0
- package/dist/client/core/billingPortalFlow.js.map +1 -0
- package/dist/client/core/idempotency.d.ts.map +1 -1
- package/dist/client/core/idempotency.js +4 -1
- package/dist/client/core/idempotency.js.map +1 -1
- package/dist/client/helpers.d.ts +3 -1
- package/dist/client/helpers.d.ts.map +1 -1
- package/dist/client/helpers.js +13 -2
- package/dist/client/helpers.js.map +1 -1
- package/dist/client/index.d.ts +5 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/invoiceReads.d.ts +3 -1
- package/dist/client/invoiceReads.d.ts.map +1 -1
- package/dist/client/singleAttemptHttpClient.d.ts +11 -0
- package/dist/client/singleAttemptHttpClient.d.ts.map +1 -0
- package/dist/client/singleAttemptHttpClient.js +51 -0
- package/dist/client/singleAttemptHttpClient.js.map +1 -0
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/react/workflows/Billing.d.ts.map +1 -1
- package/dist/react/workflows/Billing.js +6 -4
- package/dist/react/workflows/Billing.js.map +1 -1
- package/docs/client-api.md +123 -0
- package/package.json +1 -1
- package/src/client/core/accountLinks.test.ts +4 -4
- package/src/client/core/accountLinks.ts +120 -13
- package/src/client/core/billingPortal.test.ts +8 -6
- package/src/client/core/billingPortalClient.ts +5 -1
- package/src/client/core/billingPortalFlow.test.ts +349 -0
- package/src/client/core/billingPortalFlow.ts +98 -0
- package/src/client/core/billingPortalIdentity.test.ts +418 -0
- package/src/client/core/idempotency.ts +6 -1
- package/src/client/customer-preview.test.ts +188 -7
- package/src/client/helpers.ts +15 -1
- package/src/client/index.ts +5 -2
- package/src/client/invoiceReads.ts +1 -1
- package/src/client/singleAttemptHttpClient.test.ts +70 -0
- package/src/client/singleAttemptHttpClient.ts +58 -0
- package/src/react/workflows/Billing.tsx +15 -8
- package/src/react/workflows/BillingPortal.test.tsx +101 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Billing.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Billing.tsx"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGxD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE;QACL,EAAE,EAAE,MAAM,CAAC;QACX,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,EAAE,CAAC;CACL,CAAC;AACF,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAA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CAAC;AACF,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BAmCtD"}
|
|
@@ -67,11 +67,13 @@ export function BillingPortal(props) {
|
|
|
67
67
|
const url = typeof result === "string" ? result : result.url;
|
|
68
68
|
if (!url)
|
|
69
69
|
throw new Error("Stripe did not return a portal URL.");
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
return url;
|
|
71
|
+
}, props.scopeKey, (url) => {
|
|
72
|
+
(props.onNavigate ?? ((nextUrl) => window.location.assign(nextUrl)))(url);
|
|
73
|
+
});
|
|
74
|
+
const open = async () => (await action.run()) === undefined ? undefined : true;
|
|
73
75
|
const state = {
|
|
74
|
-
open
|
|
76
|
+
open,
|
|
75
77
|
isPending: action.isPending,
|
|
76
78
|
error: action.error,
|
|
77
79
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Billing.js","sourceRoot":"","sources":["../../../src/react/workflows/Billing.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAYtD,MAAM,UAAU,kBAAkB,CAChC,IAAqC,EACrC,QAAgB;IAEhB,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACjD,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,OAAO,EAAE,MAAM,CAAC,GAAG;KACpB,CAAC;AACJ,CAAC;AAMD,MAAM,UAAU,eAAe,CAAC,EAC9B,QAAQ,EACR,IAAI,EACJ,QAAQ,GACa;IACrB,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,EAAE,QAAQ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[corrections](usage-corrections.md) and [settlement](usage-settlement.md).
|
|
752
752
|
These are trusted host APIs. Browser-selected payer, realm, meter or provider
|
|
753
753
|
references do not establish authorization.
|
|
754
|
+
|
|
755
|
+
### Confirm a specific subscription update
|
|
756
|
+
|
|
757
|
+
`createBillingPortalSession` accepts an optional `flowData` typed as
|
|
758
|
+
`BillingPortalSubscriptionUpdateFlow` from the package's main export:
|
|
759
|
+
|
|
760
|
+
```ts
|
|
761
|
+
const portal = await stripe.createBillingPortalSession(ctx, {
|
|
762
|
+
stripeAccountId: authorizedCustomerAccountId,
|
|
763
|
+
connectedAccountId: authorizedConnectedAccountId, // omit for platform scope
|
|
764
|
+
configurationId: serverSelectedConfigurationId,
|
|
765
|
+
returnUrl: authorizedBillingUrl,
|
|
766
|
+
flowData: {
|
|
767
|
+
type: "subscription_update_confirm",
|
|
768
|
+
subscription_update_confirm: {
|
|
769
|
+
subscription: authorizedOriginalSubscriptionId,
|
|
770
|
+
items: [
|
|
771
|
+
{ id: authorizedExistingItemId, price: serverAllowedTargetPriceId },
|
|
772
|
+
],
|
|
773
|
+
},
|
|
774
|
+
after_completion: {
|
|
775
|
+
type: "redirect",
|
|
776
|
+
redirect: { return_url: authorizedCompletionUrl },
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
});
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
The SDK validates the supported shape, copies its scalar values before awaiting
|
|
783
|
+
Stripe, and retrieves the exact original subscription in the same connected-account
|
|
784
|
+
scope as session creation. It requires the original customer account and a complete
|
|
785
|
+
single-item subscription containing the requested item. It rejects multi-item
|
|
786
|
+
subscriptions, partial item pages and mismatches before creating a session. A failed
|
|
787
|
+
read never falls back to an account-wide portal. Omitting `flowData` preserves the
|
|
788
|
+
ordinary portal without an additional subscription read.
|
|
789
|
+
|
|
790
|
+
These resource checks do not authenticate a caller or authorize a target price,
|
|
791
|
+
quantity, portal configuration or redirect. The host must establish each policy
|
|
792
|
+
before calling. Account customer and connected-account scope are distinct. Stripe's
|
|
793
|
+
account/version and portal feature restrictions still apply; one transport response
|
|
794
|
+
is not a guarantee of provider support. Stripe presents the actual confirmation,
|
|
795
|
+
amount, proration and effective timing under the chosen configuration. The SDK does
|
|
796
|
+
not quote or apply a separate price change.
|
|
797
|
+
|
|
798
|
+
The existing `BillingPortal` React workflow accepts the host's `createSession`
|
|
799
|
+
callback. Include actor, original subscription and target in its `scopeKey`; current
|
|
800
|
+
success navigates through `onNavigate`, while completion after scope change/unmount
|
|
801
|
+
does not navigate. `open()` still resolves to `true` or `undefined`. Errors remain in
|
|
802
|
+
workflow state. A returned session URL or completion redirect does not prove a paid
|
|
803
|
+
invoice, update access, award a commission or replace verified lifecycle processing.
|
|
804
|
+
Durable retry identity and safe reissue policy are separate from this API.
|
|
805
|
+
|
|
806
|
+
### Retain a caller-owned portal request
|
|
807
|
+
|
|
808
|
+
Use `prepareBillingPortalSessionRequestIdentity` from the main export to bind a
|
|
809
|
+
caller-generated key to the complete normalized portal request. Persist the
|
|
810
|
+
returned `{ key, binding }` and immutable authorized options **before** the first
|
|
811
|
+
session creation. Reuse that pair after a timeout, duplicate invocation or lost
|
|
812
|
+
response:
|
|
813
|
+
|
|
814
|
+
```ts
|
|
815
|
+
import { prepareBillingPortalSessionRequestIdentity } from "@fantastic.dev/better-stripe";
|
|
816
|
+
|
|
817
|
+
// The host authorizes and stores these options with the authenticated operation.
|
|
818
|
+
const options = {
|
|
819
|
+
stripeAccountId: authorizedCustomerAccountId,
|
|
820
|
+
connectedAccountId: authorizedConnectedAccountId,
|
|
821
|
+
configurationId: serverSelectedConfigurationId,
|
|
822
|
+
returnUrl: authorizedBillingUrl,
|
|
823
|
+
// Include the same supported flowData here for a targeted confirmation.
|
|
824
|
+
};
|
|
825
|
+
const requestIdentity = prepareBillingPortalSessionRequestIdentity(
|
|
826
|
+
options,
|
|
827
|
+
callerOwnedOperationKey,
|
|
828
|
+
);
|
|
829
|
+
// Persist options + requestIdentity in the host's durable operation store here.
|
|
830
|
+
const portal = await stripe.createBillingPortalSession(ctx, {
|
|
831
|
+
...options,
|
|
832
|
+
requestIdentity,
|
|
833
|
+
});
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
The binding includes the customer account, effective connected-account scope,
|
|
837
|
+
configuration, return URL and complete targeted flow, including quantity and
|
|
838
|
+
completion behavior when supplied. It is opaque, versioned and JSON-serializable.
|
|
839
|
+
The SDK rejects a changed binding before a provider request. Keys must be nonblank,
|
|
840
|
+
at most 255 characters and contain no carriage return or newline. Keep personal
|
|
841
|
+
information out of keys. The helper does not reserve a key, authenticate ownership
|
|
842
|
+
or remember earlier calls. A host can deliberately create another binding with the
|
|
843
|
+
same key; Stripe's conflict remains visible. A fixed configuration ID binds that
|
|
844
|
+
reference, not mutable provider configuration contents or default policy.
|
|
845
|
+
|
|
846
|
+
Each provider request in session creation makes one SDK transport attempt,
|
|
847
|
+
including the original subscription read for a targeted flow. Automatic provider retries are
|
|
848
|
+
disabled, including Stripe's special closed-connection retry. A transport failure
|
|
849
|
+
can still mean Stripe processed the request. Provider errors retain their safe
|
|
850
|
+
type/code; no error silently rotates the key, reissues a session or returns a
|
|
851
|
+
locally cached URL. Omitting `requestIdentity` leaves caller-owned retry protection
|
|
852
|
+
opt-in. The underlying Stripe client can generate a fresh per-invocation POST key;
|
|
853
|
+
that does not provide identity across separate SDK calls.
|
|
854
|
+
|
|
855
|
+
[Stripe's API v1 idempotency rules](https://docs.stripe.com/api/idempotent_requests)
|
|
856
|
+
apply. Once execution starts, Stripe retains the first response, including errors.
|
|
857
|
+
Validation and concurrent-request conflicts may not be saved. Keys may be pruned
|
|
858
|
+
after at least 24 hours; reuse after pruning can create a new resource. This is no
|
|
859
|
+
permanent replay guarantee. [Portal URLs are short-lived](https://docs.stripe.com/api/customer_portal/sessions).
|
|
860
|
+
The public portal reference exposes creation without a retrieve/list endpoint;
|
|
861
|
+
the SDK supplies no automatic lost-response reconciliation. Do not rotate an
|
|
862
|
+
identity automatically because a URL expired or a result is unknown. The host owns authenticated operation storage, concurrency, retry age,
|
|
863
|
+
reconciliation and deliberate new-request decisions. A new portal session never
|
|
864
|
+
proves a subscription change, payment or entitlement.
|
|
865
|
+
|
|
866
|
+
The React `BillingPortal` callback stays application-owned. Retain the identity
|
|
867
|
+
outside the component so retries and remounts reuse it. Persist it before calling
|
|
868
|
+
the server action, and include actor, original subscription and target in the
|
|
869
|
+
workflow scope. Recheck that scope after any awaited preparation and before
|
|
870
|
+
dispatch. The workflow suppresses stale navigation; it cannot undo a server request
|
|
871
|
+
already sent. The seller-plan example demonstrates this with read-only
|
|
872
|
+
`prepareManage`, a preconfigured server policy and per-tab `sessionStorage`.
|
|
873
|
+
Its explicit **Start a new billing request** button begins another operation.
|
|
874
|
+
Browser storage, persona selection and its conservative 23-hour retry cutoff are
|
|
875
|
+
demo choices; production hosts need durable authenticated storage and an explicit
|
|
876
|
+
policy for unknown outcomes.
|
package/package.json
CHANGED
|
@@ -240,10 +240,10 @@ describe("createBillingPortalSession", () => {
|
|
|
240
240
|
});
|
|
241
241
|
|
|
242
242
|
expect(result).toEqual({ url: "https://portal" });
|
|
243
|
-
expect(stripe.billingPortal.sessions.create).toHaveBeenCalledWith(
|
|
244
|
-
customer_account: "acct_7",
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
expect(stripe.billingPortal.sessions.create).toHaveBeenCalledWith(
|
|
244
|
+
{ customer_account: "acct_7", return_url: "https://return" },
|
|
245
|
+
{ maxNetworkRetries: 0 },
|
|
246
|
+
);
|
|
247
247
|
});
|
|
248
248
|
});
|
|
249
249
|
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type Stripe from "stripe";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
assertTargetedPortalSubscription,
|
|
5
|
+
billingPortalSessionOptions,
|
|
6
|
+
targetedPortalOptions,
|
|
7
|
+
type BillingPortalSubscriptionUpdateFlow,
|
|
8
|
+
} from "./billingPortalFlow.js";
|
|
9
|
+
import { idempotencyOptions } from "./idempotency.js";
|
|
10
|
+
import { singleAttemptPortalError } from "../singleAttemptHttpClient.js";
|
|
11
|
+
export type { BillingPortalSubscriptionUpdateFlow } from "./billingPortalFlow.js";
|
|
2
12
|
|
|
3
13
|
import { throwStripeError } from "../errors.js";
|
|
4
14
|
import type { RunCtx } from "../helpers.js";
|
|
@@ -207,8 +217,72 @@ export type CreateBillingPortalSessionOptions = BillingPortalScope & {
|
|
|
207
217
|
returnUrl: string;
|
|
208
218
|
/** Omit to use Stripe's default portal configuration. */
|
|
209
219
|
configurationId?: string;
|
|
220
|
+
/** Host-authorized exact original subscription and one allowed target price. */
|
|
221
|
+
flowData?: BillingPortalSubscriptionUpdateFlow;
|
|
222
|
+
/** Retain this exact key and request binding before the first creation attempt. */
|
|
223
|
+
requestIdentity?: BillingPortalSessionRequestIdentity;
|
|
210
224
|
};
|
|
211
225
|
|
|
226
|
+
/** Caller-owned immutable request identity; the SDK stores no key history. */
|
|
227
|
+
export type BillingPortalSessionRequestIdentity = {
|
|
228
|
+
key: string;
|
|
229
|
+
binding: string;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const portalRequestIdentity = z
|
|
233
|
+
.object({ key: z.string(), binding: z.string() })
|
|
234
|
+
.strict();
|
|
235
|
+
|
|
236
|
+
function portalSessionParams(
|
|
237
|
+
snapshot: Omit<CreateBillingPortalSessionOptions, "requestIdentity">,
|
|
238
|
+
): Stripe.BillingPortal.SessionCreateParams {
|
|
239
|
+
return {
|
|
240
|
+
customer_account: snapshot.stripeAccountId,
|
|
241
|
+
return_url: snapshot.returnUrl,
|
|
242
|
+
...(snapshot.configurationId !== undefined
|
|
243
|
+
? { configuration: snapshot.configurationId }
|
|
244
|
+
: {}),
|
|
245
|
+
...(snapshot.flowData !== undefined
|
|
246
|
+
? { flow_data: snapshot.flowData }
|
|
247
|
+
: {}),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function portalRequestBinding(
|
|
252
|
+
params: Stripe.BillingPortal.SessionCreateParams,
|
|
253
|
+
connectedAccountId: string | undefined,
|
|
254
|
+
): string {
|
|
255
|
+
return `better-stripe:billing-portal:v1:${JSON.stringify({
|
|
256
|
+
stripeAccount: connectedAccountId ?? null,
|
|
257
|
+
params,
|
|
258
|
+
})}`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Prepare a serializable identity without provider I/O. Persist it with the
|
|
263
|
+
* immutable authorized options before creation. Treat binding as opaque data,
|
|
264
|
+
* not authentication or an SDK-maintained record of earlier uses of this key.
|
|
265
|
+
*/
|
|
266
|
+
export function prepareBillingPortalSessionRequestIdentity(
|
|
267
|
+
opts: Omit<CreateBillingPortalSessionOptions, "requestIdentity">,
|
|
268
|
+
key: string,
|
|
269
|
+
): BillingPortalSessionRequestIdentity {
|
|
270
|
+
const identity = idempotencyOptions(key);
|
|
271
|
+
if (identity === undefined)
|
|
272
|
+
throwStripeError(
|
|
273
|
+
"INVALID_CONFIGURATION",
|
|
274
|
+
"A caller-owned key is required.",
|
|
275
|
+
);
|
|
276
|
+
const snapshot = billingPortalSessionOptions.parse(opts);
|
|
277
|
+
return {
|
|
278
|
+
key: identity.idempotencyKey,
|
|
279
|
+
binding: portalRequestBinding(
|
|
280
|
+
portalSessionParams(snapshot),
|
|
281
|
+
snapshot.connectedAccountId,
|
|
282
|
+
),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
212
286
|
export async function createBillingPortalConfiguration(
|
|
213
287
|
stripe: Stripe,
|
|
214
288
|
_ctx: RunCtx,
|
|
@@ -286,27 +360,60 @@ export async function createBillingPortalSession(
|
|
|
286
360
|
stripe: Stripe,
|
|
287
361
|
_ctx: RunCtx,
|
|
288
362
|
opts: CreateBillingPortalSessionOptions,
|
|
289
|
-
) {
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
363
|
+
): Promise<{ url: string }> {
|
|
364
|
+
const { requestIdentity: suppliedIdentity, ...options } = opts;
|
|
365
|
+
const identity =
|
|
366
|
+
suppliedIdentity === undefined
|
|
367
|
+
? undefined
|
|
368
|
+
: portalRequestIdentity.parse(suppliedIdentity);
|
|
369
|
+
const snapshot =
|
|
370
|
+
options.flowData !== undefined
|
|
371
|
+
? targetedPortalOptions.parse(options)
|
|
372
|
+
: identity !== undefined
|
|
373
|
+
? billingPortalSessionOptions.parse(options)
|
|
374
|
+
: { ...options };
|
|
375
|
+
const params = portalSessionParams(snapshot);
|
|
376
|
+
const keyed =
|
|
377
|
+
identity === undefined ? undefined : idempotencyOptions(identity.key);
|
|
378
|
+
if (
|
|
379
|
+
identity !== undefined &&
|
|
380
|
+
identity.binding !==
|
|
381
|
+
portalRequestBinding(params, snapshot.connectedAccountId)
|
|
382
|
+
)
|
|
383
|
+
throwStripeError(
|
|
384
|
+
"INVALID_CONFIGURATION",
|
|
385
|
+
"The retained Billing Portal identity does not match this request. Reuse its immutable authorized options.",
|
|
386
|
+
);
|
|
387
|
+
const request = {
|
|
388
|
+
...(snapshot.connectedAccountId !== undefined
|
|
389
|
+
? { stripeAccount: snapshot.connectedAccountId }
|
|
295
390
|
: {}),
|
|
391
|
+
maxNetworkRetries: 0,
|
|
296
392
|
};
|
|
297
393
|
try {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
394
|
+
if (snapshot.flowData !== undefined) {
|
|
395
|
+
const original =
|
|
396
|
+
snapshot.flowData.subscription_update_confirm.subscription;
|
|
397
|
+
const subscription = await stripe.subscriptions.retrieve(
|
|
398
|
+
original,
|
|
399
|
+
{},
|
|
400
|
+
request,
|
|
401
|
+
);
|
|
402
|
+
assertTargetedPortalSubscription(subscription, {
|
|
403
|
+
...snapshot,
|
|
404
|
+
flowData: snapshot.flowData,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
const session = await stripe.billingPortal.sessions.create(params, {
|
|
408
|
+
...request,
|
|
409
|
+
...keyed,
|
|
410
|
+
});
|
|
304
411
|
return { url: session.url };
|
|
305
412
|
} catch (error) {
|
|
306
413
|
throwStripeError(
|
|
307
414
|
"STRIPE_API_ERROR",
|
|
308
415
|
"Failed to create Billing Portal session",
|
|
309
|
-
error,
|
|
416
|
+
singleAttemptPortalError(error),
|
|
310
417
|
);
|
|
311
418
|
}
|
|
312
419
|
}
|
|
@@ -158,11 +158,13 @@ describe("configured Billing Portal sessions", () => {
|
|
|
158
158
|
return_url: "https://return",
|
|
159
159
|
configuration: "bpc_host",
|
|
160
160
|
};
|
|
161
|
-
expect(stripe.billingPortal.sessions.create.mock.calls[0]).toEqual(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
:
|
|
165
|
-
|
|
161
|
+
expect(stripe.billingPortal.sessions.create.mock.calls[0]).toEqual([
|
|
162
|
+
params,
|
|
163
|
+
{
|
|
164
|
+
...(connectedAccountId ? { stripeAccount: connectedAccountId } : {}),
|
|
165
|
+
maxNetworkRetries: 0,
|
|
166
|
+
},
|
|
167
|
+
]);
|
|
166
168
|
},
|
|
167
169
|
);
|
|
168
170
|
|
|
@@ -241,7 +243,7 @@ describe("BetterStripe portal API", () => {
|
|
|
241
243
|
customer_account: "acct_customer",
|
|
242
244
|
return_url: "https://return",
|
|
243
245
|
},
|
|
244
|
-
{ stripeAccount: "acct_owner" },
|
|
246
|
+
{ stripeAccount: "acct_owner", maxNetworkRetries: 0 },
|
|
245
247
|
);
|
|
246
248
|
});
|
|
247
249
|
});
|
|
@@ -30,6 +30,10 @@ export abstract class BillingPortalClient extends FinancialOwnershipHost {
|
|
|
30
30
|
ctx: RunCtx,
|
|
31
31
|
opts: portal.CreateBillingPortalSessionOptions,
|
|
32
32
|
) {
|
|
33
|
-
return portal.createBillingPortalSession(
|
|
33
|
+
return portal.createBillingPortalSession(
|
|
34
|
+
this.stripe({ singleAttempt: true }),
|
|
35
|
+
ctx,
|
|
36
|
+
opts,
|
|
37
|
+
);
|
|
34
38
|
}
|
|
35
39
|
}
|