@funnelsgrove/payments 0.11.9 → 0.11.10

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.
@@ -211,14 +211,18 @@ export function SolidgateCheckoutDialog({ open, request, customerEmail, checkout
211
211
  setCommittedEmail(normalizedCustomerEmail);
212
212
  setEmailError(null);
213
213
  }, [customerEmail, normalizedCustomerEmail]);
214
- const { discountKeyOrProviderId, failUrl, funnelPlanKey, funnelEndUserId, funnelId, idempotencyKey, offerSetId, returnUrl, runtimeConfig, successUrl, } = request;
215
- const { apiBaseUrl, funnelId: runtimeFunnelId, funnelSdkPublishableKey, funnelVersionId, } = runtimeConfig || {};
214
+ const { discountKeyOrProviderId, failUrl, funnelPlanKey, paymentProfileId, providerPlanId, checkoutType, environment, funnelEndUserId, funnelId, idempotencyKey, offerSetId, returnUrl, runtimeConfig, successUrl, } = request;
215
+ const { apiBaseUrl, funnelId: runtimeFunnelId, funnelSdkPublishableKey, funnelVersionId, paymentsApiVersion, } = runtimeConfig || {};
216
216
  const hasRuntimeConfig = runtimeConfig !== undefined;
217
217
  const normalizedRequest = useMemo(() => ({
218
218
  funnelId: (funnelId === null || funnelId === void 0 ? void 0 : funnelId.trim()) || null,
219
219
  funnelEndUserId: funnelEndUserId.trim(),
220
220
  offerSetId: offerSetId.trim(),
221
221
  funnelPlanKey: funnelPlanKey.trim(),
222
+ paymentProfileId: (paymentProfileId === null || paymentProfileId === void 0 ? void 0 : paymentProfileId.trim()) || null,
223
+ providerPlanId: (providerPlanId === null || providerPlanId === void 0 ? void 0 : providerPlanId.trim()) || null,
224
+ checkoutType: checkoutType || null,
225
+ environment: environment || null,
222
226
  idempotencyKey: idempotencyKey.trim(),
223
227
  discountKeyOrProviderId: (discountKeyOrProviderId === null || discountKeyOrProviderId === void 0 ? void 0 : discountKeyOrProviderId.trim()) || null,
224
228
  returnUrl: returnUrl.trim(),
@@ -229,16 +233,22 @@ export function SolidgateCheckoutDialog({ open, request, customerEmail, checkout
229
233
  funnelId: (runtimeFunnelId === null || runtimeFunnelId === void 0 ? void 0 : runtimeFunnelId.trim()) || null,
230
234
  funnelVersionId: (funnelVersionId === null || funnelVersionId === void 0 ? void 0 : funnelVersionId.trim()) || null,
231
235
  funnelSdkPublishableKey: (funnelSdkPublishableKey === null || funnelSdkPublishableKey === void 0 ? void 0 : funnelSdkPublishableKey.trim()) || null,
236
+ paymentsApiVersion: paymentsApiVersion || null,
232
237
  } : undefined,
233
238
  }), [
234
239
  apiBaseUrl,
235
240
  discountKeyOrProviderId,
236
241
  failUrl,
237
242
  funnelPlanKey,
243
+ paymentProfileId,
244
+ providerPlanId,
245
+ checkoutType,
246
+ environment,
238
247
  funnelEndUserId,
239
248
  funnelId,
240
249
  funnelSdkPublishableKey,
241
250
  funnelVersionId,
251
+ paymentsApiVersion,
242
252
  idempotencyKey,
243
253
  offerSetId,
244
254
  returnUrl,
@@ -26,6 +26,10 @@ export type PrepareSolidgateCheckoutInput = {
26
26
  funnelEndUserId: string;
27
27
  offerSetId: string;
28
28
  funnelPlanKey: string;
29
+ paymentProfileId?: string | null;
30
+ providerPlanId?: string | null;
31
+ checkoutType?: 'subscription' | 'one_time' | null;
32
+ environment?: 'test' | 'live' | null;
29
33
  idempotencyKey: string;
30
34
  discountKeyOrProviderId?: string | null;
31
35
  returnUrl: string;
@@ -32,6 +32,18 @@ const postJson = async (path, body, runtimeConfig, signal) => {
32
32
  }
33
33
  return response.json();
34
34
  };
35
+ const getJson = async (path, runtimeConfig, signal) => {
36
+ const publishableKey = resolvePublishableKey(runtimeConfig);
37
+ const response = await fetch(resolveApiUrl(path, runtimeConfig), {
38
+ method: 'GET',
39
+ headers: Object.assign({}, (publishableKey ? { 'x-sdk-publishable-key': publishableKey } : {})),
40
+ signal,
41
+ });
42
+ if (!response.ok) {
43
+ throw new Error('Solidgate checkout is temporarily unavailable');
44
+ }
45
+ return response.json();
46
+ };
35
47
  const isRecord = (value) => (Boolean(value) && typeof value === 'object' && !Array.isArray(value));
36
48
  const parsePreparation = (value) => {
37
49
  if (!isRecord(value) || !isRecord(value.display) || !isRecord(value.initialization)) {
@@ -98,26 +110,40 @@ const parseStatus = (value) => {
98
110
  };
99
111
  };
100
112
  export const prepareSolidgateCheckout = async (input) => {
101
- var _a;
102
- return parsePreparation(await postJson('/sdk/public/payments/solidgate/checkout', {
103
- funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig),
104
- funnelEndUserId: requiredString(input.funnelEndUserId, 'funnelEndUserId'),
105
- offerSetId: requiredString(input.offerSetId, 'offerSetId'),
106
- funnelPlanKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'),
107
- idempotencyKey: requiredString(input.idempotencyKey, 'idempotencyKey'),
108
- discountKeyOrProviderId: ((_a = input.discountKeyOrProviderId) === null || _a === void 0 ? void 0 : _a.trim()) || null,
109
- returnUrl: requiredString(input.returnUrl, 'returnUrl'),
110
- successUrl: requiredString(input.successUrl, 'successUrl'),
111
- failUrl: requiredString(input.failUrl, 'failUrl'),
112
- }, input.runtimeConfig, input.signal));
113
+ var _a, _b, _c, _d;
114
+ const useV2 = ((_a = input.runtimeConfig) === null || _a === void 0 ? void 0 : _a.paymentsApiVersion) === 'v2';
115
+ const paymentProfileId = ((_b = input.paymentProfileId) === null || _b === void 0 ? void 0 : _b.trim()) || null;
116
+ const providerPlanId = ((_c = input.providerPlanId) === null || _c === void 0 ? void 0 : _c.trim()) || null;
117
+ const checkoutType = input.checkoutType || null;
118
+ const environment = input.environment || null;
119
+ if (useV2 && (!paymentProfileId || !providerPlanId || !checkoutType || !environment)) {
120
+ throw new Error('Solidgate V2 checkout selection is incomplete');
121
+ }
122
+ return parsePreparation(await postJson(useV2
123
+ ? '/sdk/public/v2/payments/checkout-sessions'
124
+ : '/sdk/public/payments/solidgate/checkout', Object.assign(Object.assign({}, (useV2 ? {
125
+ checkoutType,
126
+ uiMode: 'custom',
127
+ environment,
128
+ paymentProfileId,
129
+ provider: 'solidgate',
130
+ providerPlanId,
131
+ planKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'),
132
+ } : {})), { funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig), funnelEndUserId: requiredString(input.funnelEndUserId, 'funnelEndUserId'), offerSetId: requiredString(input.offerSetId, 'offerSetId'), funnelPlanKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'), idempotencyKey: requiredString(input.idempotencyKey, 'idempotencyKey'), discountKeyOrProviderId: ((_d = input.discountKeyOrProviderId) === null || _d === void 0 ? void 0 : _d.trim()) || null, returnUrl: requiredString(input.returnUrl, 'returnUrl'), successUrl: requiredString(input.successUrl, 'successUrl'), failUrl: requiredString(input.failUrl, 'failUrl') }), input.runtimeConfig, input.signal));
113
133
  };
114
134
  export const retrieveSolidgateCheckoutStatus = async (input) => {
135
+ var _a;
115
136
  const attemptId = requiredString(input.attemptId, 'attemptId');
116
- const result = parseStatus(await postJson('/sdk/public/payments/solidgate/checkout/status', {
117
- funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig),
118
- funnelEndUserId: requiredString(input.funnelEndUserId, 'funnelEndUserId'),
119
- attemptId,
120
- }, input.runtimeConfig, input.signal));
137
+ const useV2 = ((_a = input.runtimeConfig) === null || _a === void 0 ? void 0 : _a.paymentsApiVersion) === 'v2';
138
+ const funnelId = resolveFunnelId(input.funnelId, input.runtimeConfig);
139
+ const funnelEndUserId = requiredString(input.funnelEndUserId, 'funnelEndUserId');
140
+ const result = parseStatus(await (useV2
141
+ ? getJson(`/sdk/public/v2/payments/checkout-sessions/${encodeURIComponent(attemptId)}?provider=solidgate&funnelId=${encodeURIComponent(funnelId)}&funnelEndUserId=${encodeURIComponent(funnelEndUserId)}`, input.runtimeConfig, input.signal)
142
+ : postJson('/sdk/public/payments/solidgate/checkout/status', {
143
+ funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig),
144
+ funnelEndUserId,
145
+ attemptId,
146
+ }, input.runtimeConfig, input.signal)));
121
147
  if (result.attemptId !== attemptId) {
122
148
  throw new Error('Solidgate checkout status returned the wrong attempt');
123
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.11.9",
3
+ "version": "0.11.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",