@getopenpay/openpay-js-react 0.1.7 → 0.1.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/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import rn, { createContext as on, useContext as sn, useRef as re, useCallback as Z, useEffect as q, useState as w, useMemo as Q } from "react";
1
+ import un, { createContext as dn, useContext as mn, useRef as se, useCallback as J, useEffect as z, useState as C, useMemo as ee } from "react";
2
2
  import { jsx as V } from "react/jsx-runtime";
3
3
  import { z as n } from "zod";
4
- import { v4 as st } from "uuid";
5
- import { connectToChild as it } from "penpal";
6
- import ae from "chalk";
7
- const at = on({
4
+ import { v4 as ut } from "uuid";
5
+ import { connectToChild as dt } from "penpal";
6
+ import de from "chalk";
7
+ const mt = dn({
8
8
  formId: "",
9
9
  formHeight: "",
10
10
  referer: void 0,
@@ -12,42 +12,42 @@ const at = on({
12
12
  registerIframe: () => {
13
13
  },
14
14
  baseUrl: ""
15
- }), an = () => {
16
- const e = sn(at);
15
+ }), pn = () => {
16
+ const e = mn(mt);
17
17
  if (!e)
18
18
  throw new Error("useOpenPayElements must be used within an OpenPayElementsProvider");
19
19
  return e;
20
- }, cn = "https://cde.getopenpay.com", ln = n.object({
20
+ }, fn = "https://cde.getopenpay.com", yn = n.object({
21
21
  type: n.string(),
22
22
  loc: n.array(n.string()),
23
23
  msg: n.string(),
24
24
  url: n.string()
25
- }), un = n.array(ln), dn = n.object({
25
+ }), _n = n.array(yn), gn = n.object({
26
26
  code: n.string(),
27
27
  message: n.string(),
28
28
  path: n.array(n.string())
29
- }), mn = n.array(dn), fn = {
29
+ }), hn = n.array(gn), wn = {
30
30
  "failed to fetch": "Connection error: please double check if you are connected to the internet, then try again"
31
- }, je = (e) => {
31
+ }, De = (e) => {
32
32
  const t = e.toLowerCase().trim();
33
- return fn[t] ?? e;
34
- }, pn = (e) => {
33
+ return wn[t] ?? e;
34
+ }, En = (e) => {
35
35
  try {
36
36
  return typeof JSON.parse(e) == "object";
37
37
  } catch {
38
38
  return !1;
39
39
  }
40
- }, yn = (e) => e.length === 1 ? je(e[0].msg) : `Please fix the following errors:
41
- ${e.map((r) => `• ${je(r.msg)}`).join(`
42
- `)}`, _n = (e) => `Encountered the following errors:
40
+ }, Cn = (e) => e.length === 1 ? De(e[0].msg) : `Please fix the following errors:
41
+ ${e.map((r) => `• ${De(r.msg)}`).join(`
42
+ `)}`, bn = (e) => `Encountered the following errors:
43
43
  ${e.map((r) => `- ${r.path.join("/")}: ${r.message}`).join(`
44
- `)}`, pe = (e) => {
44
+ `)}`, we = (e) => {
45
45
  if (e instanceof Error)
46
- if (pn(e.message)) {
46
+ if (En(e.message)) {
47
47
  const t = JSON.parse(e.message);
48
- return un.safeParse(t).success ? yn(t) : mn.safeParse(t).success ? _n(t) : e.message;
48
+ return _n.safeParse(t).success ? Cn(t) : hn.safeParse(t).success ? bn(t) : e.message;
49
49
  } else
50
- return je(e.message);
50
+ return De(e.message);
51
51
  if (typeof e == "object")
52
52
  try {
53
53
  return JSON.stringify(e);
@@ -56,23 +56,23 @@ ${e.map((r) => `- ${r.path.join("/")}: ${r.message}`).join(`
56
56
  }
57
57
  else
58
58
  return e + "";
59
- }, te = (e, t) => (...r) => {
59
+ }, re = (e, t) => (...r) => {
60
60
  try {
61
61
  return t(...r);
62
62
  } catch {
63
63
  return;
64
64
  }
65
- }, O = n.string().trim().min(1, { message: "Cannot be blank" }), v = n.string().trim().optional(), de = (e) => n.nullable(e.optional());
66
- var C = /* @__PURE__ */ ((e) => (e.FIRST_NAME = "firstName", e.LAST_NAME = "lastName", e.EMAIL = "email", e.ZIP_CODE = "zipCode", e.CITY = "city", e.STATE = "state", e.COUNTRY = "country", e.ADDRESS = "address", e.PHONE = "phone", e.PROMOTION_CODE = "promotionCode", e))(C || {});
67
- const ct = n.nativeEnum(C);
68
- var lt = /* @__PURE__ */ ((e) => (e.CARD_NUMBER = "cardNumber", e.CARD_EXPIRY = "cardExpiry", e.CARD_CVC = "cardCvc", e))(lt || {});
69
- const ut = n.nativeEnum(lt), dt = n.union([ct, ut]);
70
- var mt = /* @__PURE__ */ ((e) => (e.CARD = "card", e.CARD_NUMBER = "card-number", e.CARD_EXPIRY = "card-expiry", e.CARD_CVC = "card-cvc", e))(mt || {});
71
- const gn = n.nativeEnum(mt), ye = n.object({
65
+ }, k = n.string().trim().min(1, { message: "Cannot be blank" }), v = n.string().trim().optional(), ye = (e) => n.nullable(e.optional());
66
+ var y = /* @__PURE__ */ ((e) => (e.FIRST_NAME = "firstName", e.LAST_NAME = "lastName", e.EMAIL = "email", e.ZIP_CODE = "zipCode", e.CITY = "city", e.STATE = "state", e.COUNTRY = "country", e.ADDRESS = "address", e.PHONE = "phone", e.PROMOTION_CODE = "promotionCode", e))(y || {});
67
+ const pt = n.nativeEnum(y);
68
+ var ft = /* @__PURE__ */ ((e) => (e.CARD_NUMBER = "cardNumber", e.CARD_EXPIRY = "cardExpiry", e.CARD_CVC = "cardCvc", e))(ft || {});
69
+ const yt = n.nativeEnum(ft), _t = n.union([pt, yt]);
70
+ var gt = /* @__PURE__ */ ((e) => (e.CARD = "card", e.CARD_NUMBER = "card-number", e.CARD_EXPIRY = "card-expiry", e.CARD_CVC = "card-cvc", e))(gt || {});
71
+ const Sn = n.nativeEnum(gt), Ee = n.object({
72
72
  provider: n.string(),
73
- processor_name: de(n.string()),
74
- metadata: de(n.record(n.string(), n.any()))
75
- }), hn = n.object({
73
+ processor_name: ye(n.string()),
74
+ metadata: ye(n.record(n.string(), n.any()))
75
+ }), Pn = n.object({
76
76
  id: n.string()
77
77
  });
78
78
  n.object({
@@ -91,7 +91,7 @@ n.object({
91
91
  letterSpacing: v,
92
92
  lineHeight: v
93
93
  });
94
- const f = n.enum([
94
+ const g = n.enum([
95
95
  // Element -> Form
96
96
  "LAYOUT",
97
97
  "LOADED",
@@ -112,83 +112,83 @@ const f = n.enum([
112
112
  "TOKENIZE",
113
113
  "CHECKOUT",
114
114
  "START_PAYMENT_FLOW"
115
- ]), wn = f.extract(["TOKENIZE_STARTED", "CHECKOUT_STARTED"]), En = n.object({ type: wn }), Cn = f.extract(["BLUR", "FOCUS", "CHANGE"]), bn = n.object({
116
- type: Cn,
117
- elementType: ut,
115
+ ]), vn = g.extract(["TOKENIZE_STARTED", "CHECKOUT_STARTED"]), kn = n.object({ type: vn }), On = g.extract(["BLUR", "FOCUS", "CHANGE"]), Rn = n.object({
116
+ type: On,
117
+ elementType: yt,
118
118
  errors: n.array(n.string()).optional()
119
- }), Sn = f.extract(["LOAD_ERROR", "TOKENIZE_ERROR", "CHECKOUT_ERROR"]), Pn = n.object({
120
- type: Sn,
121
- message: O,
119
+ }), In = g.extract(["LOAD_ERROR", "TOKENIZE_ERROR", "CHECKOUT_ERROR"]), An = n.object({
120
+ type: In,
121
+ message: k,
122
122
  headers: n.record(n.string(), n.string()).optional()
123
- }), vn = f.extract(["VALIDATION_ERROR"]), On = n.object({
124
- type: vn,
125
- elementType: dt,
123
+ }), Tn = g.extract(["VALIDATION_ERROR"]), Mn = n.object({
124
+ type: Tn,
125
+ elementType: _t,
126
126
  errors: n.array(n.string())
127
- }), Rn = n.object({
128
- type: n.literal(f.enum.LAYOUT),
129
- height: O
130
- }), kn = n.object({
131
- type: n.literal(f.enum.LOADED),
132
- sessionId: O,
127
+ }), jn = n.object({
128
+ type: n.literal(g.enum.LAYOUT),
129
+ height: k
130
+ }), Fn = n.object({
131
+ type: n.literal(g.enum.LOADED),
132
+ sessionId: k,
133
133
  totalAmountAtoms: n.number(),
134
134
  currency: v,
135
- checkoutPaymentMethods: n.array(ye)
136
- }), Tn = n.object({
137
- type: n.literal(f.enum.PAYMENT_FLOW_STARTED),
135
+ checkoutPaymentMethods: n.array(Ee)
136
+ }), Nn = n.object({
137
+ type: n.literal(g.enum.PAYMENT_FLOW_STARTED),
138
138
  nextActionMetadata: n.record(n.string(), n.any()),
139
139
  paymentFlowMetadata: n.any().optional(),
140
140
  startPFMetadata: n.optional(n.record(n.string(), n.any()))
141
- }), An = n.object({
142
- type: n.literal(f.enum.SETUP_PAYMENT_METHOD_SUCCESS),
141
+ }), Dn = n.object({
142
+ type: n.literal(g.enum.SETUP_PAYMENT_METHOD_SUCCESS),
143
143
  paymentMethodId: n.string()
144
- }), oe = n.object({
145
- firstName: O,
146
- lastName: O,
147
- email: O,
148
- zipCode: O,
149
- country: O,
144
+ }), ae = n.object({
145
+ firstName: k,
146
+ lastName: k,
147
+ email: k,
148
+ zipCode: k,
149
+ country: k,
150
150
  promotionCode: v
151
- }), In = n.object({
152
- email: O,
153
- zipCode: O,
154
- country: O,
151
+ }), Ln = n.object({
152
+ email: k,
153
+ zipCode: k,
154
+ country: k,
155
155
  promotionCode: v
156
- }), jn = f.extract(["TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW"]), ft = n.object({
157
- type: jn,
158
- sessionId: O,
159
- checkoutPaymentMethod: ye,
156
+ }), xn = g.extract(["TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW"]), ht = n.object({
157
+ type: xn,
158
+ sessionId: k,
159
+ checkoutPaymentMethod: Ee,
160
160
  paymentFlowMetadata: n.any().optional(),
161
161
  doNotUseLegacyCCFlow: n.boolean().optional(),
162
162
  existingCCPMId: v
163
- }).extend(oe.shape), Mn = n.object({
164
- type: n.literal(f.enum.TOKENIZE_SUCCESS),
163
+ }).extend(ae.shape), Un = n.object({
164
+ type: n.literal(g.enum.TOKENIZE_SUCCESS),
165
165
  isReadyForCheckout: n.boolean()
166
- }), Fn = n.object({
167
- type: n.literal(f.enum.CHECKOUT_SUCCESS),
166
+ }), $n = n.object({
167
+ type: n.literal(g.enum.CHECKOUT_SUCCESS),
168
168
  invoiceUrls: n.array(n.string()),
169
169
  subscriptionIds: n.array(n.string()),
170
170
  customerId: n.string()
171
- }), Dn = n.discriminatedUnion("type", [
172
- En,
173
- bn,
174
- Pn,
175
- On,
176
- Rn,
171
+ }), qn = n.discriminatedUnion("type", [
177
172
  kn,
178
- ft,
173
+ Rn,
174
+ An,
179
175
  Mn,
176
+ jn,
180
177
  Fn,
181
- Tn,
182
- An
183
- ]), Nn = n.object({
184
- payload: Dn,
185
- nonce: O,
186
- formId: O,
187
- elementId: O
178
+ ht,
179
+ Un,
180
+ $n,
181
+ Nn,
182
+ Dn
183
+ ]), zn = n.object({
184
+ payload: qn,
185
+ nonce: k,
186
+ formId: k,
187
+ elementId: k
188
188
  });
189
189
  n.object({
190
190
  amountAtom: n.number(),
191
- currency: O
191
+ currency: k
192
192
  });
193
193
  n.object({
194
194
  secure_token: n.string(),
@@ -196,79 +196,85 @@ n.object({
196
196
  });
197
197
  n.object({
198
198
  secure_token: n.string(),
199
- existing_cc_pm_id: de(n.string())
199
+ existing_cc_pm_id: ye(n.string())
200
200
  });
201
- const xn = n.object({
202
- payment_methods: n.array(hn)
203
- }), Ln = n.object({
201
+ const Hn = n.object({
202
+ payment_methods: n.array(Pn)
203
+ }), Kn = n.object({
204
204
  elementType: n.string(),
205
205
  errors: n.array(n.string())
206
206
  });
207
207
  n.object({
208
208
  session_id: n.string()
209
209
  });
210
- const $n = n.object({
210
+ const Vn = n.object({
211
211
  success: n.literal(!1),
212
212
  error_type: n.literal("validation_error"),
213
- errors: n.array(Ln)
214
- }), Un = n.discriminatedUnion("success", [
213
+ errors: n.array(Kn)
214
+ }), Yn = n.discriminatedUnion("success", [
215
215
  n.object({ success: n.literal(!0) }),
216
- $n
216
+ Vn
217
217
  ]);
218
218
  n.object({
219
219
  session_id: n.string(),
220
- checkout_payment_method: ye,
221
- non_cde_form_fields: oe,
220
+ checkout_payment_method: Ee,
221
+ non_cde_form_fields: ae,
222
222
  do_not_use_legacy_cc_flow: n.boolean().optional(),
223
- existing_cc_pm_id: de(n.string())
223
+ existing_cc_pm_id: ye(n.string())
224
224
  });
225
225
  n.object({
226
226
  session_id: n.string(),
227
- checkout_payment_method: ye,
228
- non_cde_form_fields: oe
227
+ checkout_payment_method: Ee,
228
+ non_cde_form_fields: ae
229
229
  });
230
- var me = /* @__PURE__ */ ((e) => (e.SUCCESS = "success", e.FAILURE = "failure", e.CANCELLED = "cancelled", e))(me || {});
231
- const qn = n.object({
230
+ var _e = /* @__PURE__ */ ((e) => (e.SUCCESS = "success", e.FAILURE = "failure", e.CANCELLED = "cancelled", e))(_e || {});
231
+ const Zn = n.object({
232
232
  status: n.enum([
233
233
  "success",
234
234
  "failure",
235
235
  "cancelled"
236
236
  /* CANCELLED */
237
237
  ])
238
- }), zn = n.object({
238
+ }), Wn = n.object({
239
239
  type: n.string(),
240
240
  redirect_url: n.string(),
241
241
  initial_intent_id: n.string(),
242
242
  consent_id: n.string()
243
- }), pt = (e) => {
243
+ }), wt = (e) => {
244
244
  const t = {};
245
245
  return Object.entries(e).forEach(([r, o]) => {
246
246
  try {
247
- const s = ct.parse(r);
247
+ const s = pt.parse(r);
248
248
  Array.isArray(o) ? t[s] = o : Array.isArray(o._errors) && (t[s] = o._errors);
249
249
  } catch {
250
250
  return;
251
251
  }
252
252
  }), t;
253
- }, yt = n.object({
253
+ }, Et = n.object({
254
254
  stripe_pk: n.string(),
255
255
  client_secret: n.string(),
256
256
  stripe_pm_id: n.string()
257
- }), Hn = n.object({
257
+ }), Jn = n.object({
258
258
  type: n.string(),
259
259
  client_secret: n.string(),
260
260
  stripe_pk: n.string()
261
- }), Vn = {
261
+ }), Bn = {
262
262
  usd: "usd",
263
263
  brl: "brl"
264
- }, _e = async (e) => {
264
+ }, ce = async (e) => {
265
265
  for (let r = 0; r < 10; r++)
266
- Be() || await _t(500);
267
- if (!Be())
266
+ et() || await Ct(500);
267
+ if (!et())
268
268
  throw new Error("Stripe JS not found.");
269
269
  return new Stripe(e);
270
- }, Kn = async (e, t, r, o, s) => {
271
- const i = await _e(e), a = Vn[r.toLowerCase().trim()];
270
+ }, Gn = async (e, t) => {
271
+ const r = await ce(e);
272
+ return {
273
+ elements: r.elements(t),
274
+ stripe: r
275
+ };
276
+ }, Qn = async (e, t, r, o, s) => {
277
+ const i = await ce(e), a = Bn[r.toLowerCase().trim()];
272
278
  return i.paymentRequest({
273
279
  // TODO: replace this with stripe account country as soon as we support it
274
280
  country: "US",
@@ -282,9 +288,9 @@ const qn = n.object({
282
288
  requestPayerEmail: !0,
283
289
  disableWallets: []
284
290
  });
285
- }, _t = (e) => new Promise((t) => {
291
+ }, Ct = (e) => new Promise((t) => {
286
292
  setTimeout(t, e);
287
- }), Be = () => "Stripe" in window, Yn = async (e) => new Promise((t, r) => {
293
+ }), et = () => "Stripe" in window, Xn = async (e) => new Promise((t, r) => {
288
294
  try {
289
295
  e.on("paymentmethod", async (o) => {
290
296
  t(o);
@@ -294,7 +300,7 @@ const qn = n.object({
294
300
  } catch (o) {
295
301
  r(o);
296
302
  }
297
- }), Zn = async (e, t) => {
303
+ }), er = async (e, t) => {
298
304
  const r = e.nextActionMetadata;
299
305
  if (!e.paymentFlowMetadata || !e.paymentFlowMetadata.stripePmId)
300
306
  throw new Error(`Invalid payment flow metadata format: ${JSON.stringify(e.paymentFlowMetadata)}`);
@@ -302,68 +308,68 @@ const qn = n.object({
302
308
  throw new Error(`Invalid next action metadata format: ${JSON.stringify(r)}`);
303
309
  if (t.paymentMethod.id !== e.paymentFlowMetadata.stripePmId)
304
310
  throw new Error(`PM ID mismatch: ${t.paymentMethod.id} != ${e.paymentFlowMetadata.stripePmId}`);
305
- const s = await (await _e(r.stripe_pk)).confirmCardSetup(r.client_secret, {
311
+ const s = await (await ce(r.stripe_pk)).confirmCardSetup(r.client_secret, {
306
312
  payment_method: e.paymentFlowMetadata.stripePmId
307
313
  });
308
314
  if (s.error)
309
315
  throw t.complete("fail"), new Error(`Payment failed: ${s.error.message ?? "unknown"}`);
310
316
  t.complete("success");
311
- }, Jn = async (e, t) => {
317
+ }, tr = async (e, t) => {
312
318
  if (!e.stripe_pk || !e.client_secret)
313
319
  throw new Error(`Invalid next action metadata format: ${JSON.stringify(e)}`);
314
- const o = await (await _e(e.stripe_pk)).confirmCardSetup(e.client_secret, {
320
+ const o = await (await ce(e.stripe_pk)).confirmCardSetup(e.client_secret, {
315
321
  payment_method: t.paymentMethod.id
316
322
  });
317
323
  if (o.error)
318
324
  throw t.complete("fail"), new Error(`Payment failed: ${o.error.message ?? "unknown"}`);
319
325
  return t.complete("success"), o;
320
- }, Wn = async (e) => {
321
- const t = yt.parse(e.nextActionMetadata);
322
- await gt(t);
323
- }, gt = async (e) => {
326
+ }, nr = async (e) => {
327
+ const t = Et.parse(e.nextActionMetadata);
328
+ await bt(t);
329
+ }, bt = async (e) => {
324
330
  var s, i, a, c;
325
- const r = await (await _e(e.stripe_pk)).confirmCardSetup(e.client_secret, {
331
+ const r = await (await ce(e.stripe_pk)).confirmCardSetup(e.client_secret, {
326
332
  payment_method: e.stripe_pm_id
327
333
  }), o = (s = r.setupIntent) == null ? void 0 : s.status;
328
334
  if (o !== "succeeded") throw o === "canceled" ? new Error("Payment cancelled, please click Submit again to pay") : new Error(
329
335
  `${((i = r.error) == null ? void 0 : i.message) ?? ((c = (a = r.setupIntent) == null ? void 0 : a.last_setup_error) == null ? void 0 : c.message) ?? "Payment failed, please click submit again to pay."}`
330
336
  );
331
- }, Bn = (e) => JSON.stringify(e), Me = (e, t) => Array.from(e.querySelectorAll("[data-opid]") ?? []).reduce((s, i) => {
337
+ }, rr = (e) => JSON.stringify(e), ge = (e, t) => Array.from(e.querySelectorAll("[data-opid]") ?? []).reduce((s, i) => {
332
338
  const a = i.getAttribute("data-opid");
333
339
  return a ? { ...s, [a]: i.value } : s;
334
- }, t ?? {}), Gn = (e, t, r, o, s, i, a) => {
335
- const c = Me(r, {
340
+ }, t ?? {}), or = (e, t, r, o, s, i, a) => {
341
+ const c = ge(r, {
336
342
  type: e,
337
343
  sessionId: t,
338
344
  checkoutPaymentMethod: s,
339
345
  paymentFlowMetadata: a,
340
346
  doNotUseLegacyCCFlow: i
341
347
  });
342
- (s.provider === "apple_pay" || s.provider === "google_pay" || s.provider === "stripe_link") && (c[C.ZIP_CODE] || (c[C.ZIP_CODE] = "00000"));
343
- const l = ft.safeParse(c);
348
+ (s.provider === "apple_pay" || s.provider === "google_pay" || s.provider === "stripe_link") && (c[y.ZIP_CODE] || (c[y.ZIP_CODE] = "00000"));
349
+ const l = ht.safeParse(c);
344
350
  if (l.success)
345
351
  return l.data;
346
352
  {
347
- const d = l.error.format(), m = pt(d);
348
- for (const [E, g] of Object.entries(m))
349
- o(E, g, E);
353
+ const u = l.error.format(), d = wt(u);
354
+ for (const [f, m] of Object.entries(d))
355
+ o(f, m, f);
350
356
  return null;
351
357
  }
352
- }, Qn = (e) => {
358
+ }, sr = (e) => {
353
359
  try {
354
- return Nn.parse(e);
360
+ return zn.parse(e);
355
361
  } catch (t) {
356
362
  throw t;
357
363
  }
358
- }, Te = (e, t, r, o, s) => {
364
+ }, Fe = (e, t, r, o, s) => {
359
365
  const i = {
360
366
  payload: o,
361
- nonce: st(),
367
+ nonce: ut(),
362
368
  formId: t,
363
369
  elementId: r
364
370
  };
365
371
  e.postMessage(JSON.stringify(i), s);
366
- }, Xn = async (e) => {
372
+ }, ir = async (e) => {
367
373
  if (typeof e != "object" || !e) return !1;
368
374
  try {
369
375
  const t = { type: "ping" }, r = await e.send(t);
@@ -373,32 +379,32 @@ const qn = n.object({
373
379
  } catch {
374
380
  return !1;
375
381
  }
376
- }, er = (e, t) => !!e && t;
377
- async function tr(e) {
378
- const r = await it({
382
+ }, ar = (e, t) => !!e && t;
383
+ async function cr(e) {
384
+ const r = await dt({
379
385
  iframe: e,
380
386
  debug: !0
381
- }).promise, o = await Xn(r);
382
- if (!er(r, o))
387
+ }).promise, o = await ir(r);
388
+ if (!ar(r, o))
383
389
  throw new Error("Got invalid CDE connection object");
384
390
  return r;
385
391
  }
386
392
  const b = (e) => n.nullable(e.optional());
387
393
  n.string().trim().min(1, { message: "Cannot be blank" });
388
- const nr = n.object({
394
+ const lr = n.object({
389
395
  cde_response_type: n.literal("error"),
390
396
  message: n.string(),
391
397
  headers: n.record(n.string(), n.string()).optional()
392
398
  });
393
399
  n.enum(["usd", "brl"]);
394
- const ht = n.object({
400
+ const St = n.object({
395
401
  name: n.string(),
396
402
  amount_atom_off: b(n.number()),
397
403
  percent_off: b(n.number()),
398
404
  currency: b(n.string()),
399
405
  duration: n.string(),
400
406
  duration_in_months: b(n.number())
401
- }), wt = n.object({
407
+ }), Pt = n.object({
402
408
  amount_subtotal_atom: n.number().int(),
403
409
  amount_total_atom: n.number().int(),
404
410
  currency: n.string(),
@@ -407,81 +413,81 @@ const ht = n.object({
407
413
  billing_interval: b(n.string()),
408
414
  billing_interval_count: b(n.number().int()),
409
415
  quantity: n.number().int()
410
- }), rr = n.record(n.string(), n.any()), or = n.object({
416
+ }), ur = n.record(n.string(), n.any()), dr = n.object({
411
417
  name: n.string(),
412
- settings: b(rr)
413
- }), ge = n.object({
418
+ settings: b(ur)
419
+ }), le = n.object({
414
420
  provider: n.string(),
415
421
  processor_name: b(n.string()),
416
422
  metadata: b(n.record(n.string(), n.any()))
417
- }), sr = n.object({
423
+ }), mr = n.object({
418
424
  quantity: n.number()
419
- }), ir = n.object({
425
+ }), pr = n.object({
420
426
  id: b(n.string()),
421
427
  billing_interval: b(n.string()),
422
428
  billing_interval_count: b(n.number().int()),
423
- subscription_items: n.array(sr),
429
+ subscription_items: n.array(mr),
424
430
  trial_start: b(n.string()),
425
431
  trial_end: b(n.string())
426
- }), Et = n.object({
432
+ }), vt = n.object({
427
433
  amount_atom: n.number()
428
- }), ar = n.object({
434
+ }), fr = n.object({
429
435
  amount_atom: n.number(),
430
436
  amount_atom_considering_discount_applied: n.number(),
431
437
  currency: n.string(),
432
- discount_amount_atoms: n.array(Et),
438
+ discount_amount_atoms: n.array(vt),
433
439
  subscription_item_id: n.string()
434
- }), cr = n.object({
435
- coupon: ht
436
- }), lr = n.object({
440
+ }), yr = n.object({
441
+ coupon: St
442
+ }), _r = n.object({
437
443
  currency: n.string(),
438
- discounts: n.array(cr),
444
+ discounts: n.array(yr),
439
445
  hosted_invoice_url: b(n.string()),
440
- lines: n.array(ar),
446
+ lines: n.array(fr),
441
447
  remaining_amount_atom: n.number(),
442
448
  tax_amount_atom: n.number(),
443
449
  total_amount_atom: n.number(),
444
- total_discount_amount_atoms: n.array(Et)
445
- }), Ge = n.object({
446
- created: n.array(ir),
447
- invoices: n.array(lr)
448
- }), Ct = n.object({
449
- preview: Ge,
450
- preview_post_trial: b(Ge),
451
- coupons: n.array(ht)
452
- }), Qe = n.object({
450
+ total_discount_amount_atoms: n.array(vt)
451
+ }), tt = n.object({
452
+ created: n.array(pr),
453
+ invoices: n.array(_r)
454
+ }), kt = n.object({
455
+ preview: tt,
456
+ preview_post_trial: b(tt),
457
+ coupons: n.array(St)
458
+ }), nt = n.object({
453
459
  status: n.literal("open"),
454
460
  token: n.string(),
455
461
  email: b(n.string()),
456
- line_items: n.array(wt),
462
+ line_items: n.array(Pt),
457
463
  amount_subtotal_atom: n.number().int(),
458
464
  amount_total_atom: n.number().int(),
459
- brand: or,
460
- subs_preview: b(Ct),
465
+ brand: dr,
466
+ subs_preview: b(kt),
461
467
  // Null in setup mode
462
- methods_available: n.array(ge)
463
- }), bt = n.discriminatedUnion("mode", [
468
+ methods_available: n.array(le)
469
+ }), Ot = n.discriminatedUnion("mode", [
464
470
  n.object({
465
471
  mode: n.literal("setup"),
466
472
  currency: n.nullable(n.undefined())
467
- }).extend(Qe.shape),
473
+ }).extend(nt.shape),
468
474
  n.object({
469
475
  mode: n.enum(["payment", "subscription"]),
470
476
  currency: n.string()
471
- }).extend(Qe.shape)
472
- ]), ur = n.object({
477
+ }).extend(nt.shape)
478
+ ]), gr = n.object({
473
479
  status: n.literal("complete")
474
- }), dr = n.object({
480
+ }), hr = n.object({
475
481
  status: n.literal("expired")
476
482
  });
477
- n.union([bt, ur, dr]);
483
+ n.union([Ot, gr, hr]);
478
484
  n.object({
479
485
  logo: n.string(),
480
486
  icon: n.string(),
481
487
  primary_color: n.string(),
482
488
  secondary_color: n.string()
483
489
  });
484
- const St = n.object({
490
+ const Rt = n.object({
485
491
  invoice_urls: n.array(n.string()),
486
492
  subscription_ids: n.array(n.string()),
487
493
  customer_id: n.string()
@@ -493,55 +499,63 @@ n.object({
493
499
  customer_email: n.string(),
494
500
  customer_zip_code: n.string(),
495
501
  customer_country: n.string(),
496
- line_items: n.array(wt),
502
+ line_items: n.array(Pt),
497
503
  total_amount_atom: n.number().int(),
498
504
  cancel_at_end: n.boolean(),
499
- checkout_payment_method: ge,
505
+ checkout_payment_method: le,
500
506
  promotion_code: n.string().optional(),
501
507
  do_not_use_legacy_cc_flow: n.boolean().optional()
502
508
  });
503
- const mr = n.object({
509
+ const wr = n.object({
504
510
  payment_method_id: n.string()
505
511
  });
506
512
  n.object({
507
513
  id: n.string(),
508
514
  return_url: n.string()
509
515
  });
510
- const fr = n.object({
516
+ const Er = n.object({
511
517
  type: n.string(),
512
518
  loc: n.array(n.string()),
513
519
  msg: n.string(),
514
520
  url: n.string()
515
521
  });
516
- n.array(fr);
517
- const pr = n.object({
522
+ n.array(Er);
523
+ n.object({
524
+ new_customer_email: n.string().optional(),
525
+ new_customer_address: n.record(n.string(), n.any()).optional(),
526
+ payment_provider: n.string(),
527
+ checkout_payment_method: le,
528
+ existing_cc_pm_id: n.string().optional(),
529
+ their_existing_pm_id: n.string().optional()
530
+ });
531
+ const It = n.object({
518
532
  required_user_actions: n.array(n.record(n.string(), n.any()))
519
533
  });
520
534
  n.object({
521
- fields: In,
522
- checkoutPaymentMethod: ge
535
+ fields: Ln,
536
+ checkoutPaymentMethod: le
523
537
  });
524
538
  n.object({
525
539
  session_id: n.string(),
526
- non_cde_form_fields: oe,
527
- checkout_payment_method: ge
540
+ non_cde_form_fields: ae,
541
+ checkout_payment_method: le
528
542
  });
529
- const yr = n.object({
543
+ const Cr = n.object({
530
544
  required_user_actions: n.array(n.record(n.string(), n.any())),
531
545
  cc_pm_id: n.string()
532
546
  });
533
547
  n.record(n.any());
534
- const _r = (e) => e.reduce((t, r) => t + r, 0);
535
- function gr(e, t) {
548
+ const br = (e) => e.reduce((t, r) => t + r, 0);
549
+ function Sr(e, t) {
536
550
  var r = Object.setPrototypeOf;
537
551
  r ? r(e, t) : e.__proto__ = t;
538
552
  }
539
- function hr(e, t) {
553
+ function Pr(e, t) {
540
554
  t === void 0 && (t = e.constructor);
541
555
  var r = Error.captureStackTrace;
542
556
  r && r(e, t);
543
557
  }
544
- var wr = /* @__PURE__ */ function() {
558
+ var vr = /* @__PURE__ */ function() {
545
559
  var e = function(r, o) {
546
560
  return e = Object.setPrototypeOf || {
547
561
  __proto__: []
@@ -560,19 +574,19 @@ var wr = /* @__PURE__ */ function() {
560
574
  }
561
575
  t.prototype = r === null ? Object.create(r) : (o.prototype = r.prototype, new o());
562
576
  };
563
- }(), Er = function(e) {
564
- wr(t, e);
577
+ }(), kr = function(e) {
578
+ vr(t, e);
565
579
  function t(r, o) {
566
580
  var s = this.constructor, i = e.call(this, r, o) || this;
567
581
  return Object.defineProperty(i, "name", {
568
582
  value: s.name,
569
583
  enumerable: !1,
570
584
  configurable: !0
571
- }), gr(i, s.prototype), hr(i), i;
585
+ }), Sr(i, s.prototype), Pr(i), i;
572
586
  }
573
587
  return t;
574
588
  }(Error);
575
- class Pt extends Er {
589
+ class At extends kr {
576
590
  constructor(t) {
577
591
  const r = `[cde-client] Error querying CDE: ${t.message}`;
578
592
  super(r), this.response = t;
@@ -581,16 +595,16 @@ class Pt extends Er {
581
595
  return this.response.message;
582
596
  }
583
597
  }
584
- const x = async (e, t, r) => {
598
+ const D = async (e, t, r) => {
585
599
  const o = await e.send(t);
586
- if (br(o))
587
- throw new Pt(o);
588
- if (!Cr(o, r)) {
600
+ if (Rr(o))
601
+ throw new At(o);
602
+ if (!Or(o, r)) {
589
603
  const s = r.safeParse(o);
590
604
  throw s.success ? new Error("Invalid state") : s.error;
591
605
  }
592
606
  return o;
593
- }, Cr = (e, t) => t.safeParse(e).success, br = (e) => nr.safeParse(e).success, Sr = async (e, t) => await x(e, { type: "get_checkout_preview", payload: t }, Ct), se = async (e) => await x(e, { type: "get_prefill", payload: {} }, bt), Pr = async (e, t) => await x(e, { type: "start_payment_flow_for_cc", payload: t }, yr), vr = async (e, t) => await x(e, { type: "start_payment_flow_for_pr", payload: t }, pr), xe = async (e, t) => await x(e, { type: "confirm_payment_flow", payload: t }, xn), Or = async (e, t, r) => {
607
+ }, Or = (e, t) => t.safeParse(e).success, Rr = (e) => lr.safeParse(e).success, Ir = async (e, t) => await D(e, { type: "get_checkout_preview", payload: t }, kt), B = async (e) => await D(e, { type: "get_prefill", payload: {} }, Ot), Ar = async (e, t) => await D(e, { type: "v2_start_payment_flow", payload: t }, It), Tr = async (e, t) => await D(e, { type: "start_payment_flow_for_cc", payload: t }, Cr), Mr = async (e, t) => await D(e, { type: "start_payment_flow_for_pr", payload: t }, It), Ce = async (e, t) => await D(e, { type: "confirm_payment_flow", payload: t }, Hn), jr = async (e, t, r) => {
594
608
  const o = Date.now();
595
609
  for (r = r ?? 5e3; Date.now() - o < r; ) {
596
610
  const s = e.querySelector(`input[data-opid=${t}]`);
@@ -599,64 +613,240 @@ const x = async (e, t, r) => {
599
613
  throw new Error(`Invalid state: matched input element had wrong class: ${s.tagName}`);
600
614
  return s;
601
615
  }
602
- await _t(300);
616
+ await Ct(300);
603
617
  }
604
618
  return null;
605
- }, Rr = async (e, t, r) => {
606
- const o = await Sr(e, {
619
+ }, Fr = async (e, t, r) => {
620
+ const o = await Ir(e, {
607
621
  secure_token: t,
608
622
  promotion_code: r
609
623
  }), s = new Set(o.preview.invoices.map((c) => c.currency));
610
624
  if (s.size !== 1)
611
625
  throw new Error(`Expected exactly one currency, got ${s.size}`);
612
- const i = s.values().next().value ?? "usd", a = _r(o.preview.invoices.map((c) => c.remaining_amount_atom));
626
+ const i = s.values().next().value ?? "usd", a = br(o.preview.invoices.map((c) => c.remaining_amount_atom));
613
627
  return {
614
628
  currency: i,
615
629
  amountAtom: a
616
630
  };
617
- }, vt = async (e, t, r, o) => {
631
+ }, Ue = async (e, t, r, o) => {
618
632
  if (r)
619
633
  return { amountAtom: 0, currency: "usd" };
620
634
  {
621
635
  o = o || void 0;
622
- const s = await Rr(e, t, o);
636
+ const s = await Fr(e, t, o);
623
637
  return { amountAtom: s.amountAtom, currency: s.currency };
624
638
  }
625
- }, kr = async (e, t) => {
639
+ }, Nr = async (e, t) => {
626
640
  if (e.size === 0)
627
641
  throw new Error("No CDE connections found");
628
642
  return await Promise.all(
629
643
  Array.from(e.values()).map(
630
- (o) => x(o, { type: "tokenize_card", payload: t }, Un)
644
+ (o) => D(o, { type: "tokenize_card", payload: t }, Yn)
631
645
  )
632
646
  );
633
- }, Xe = async (e, t) => {
647
+ }, rt = async (e, t) => {
634
648
  try {
635
- return await x(e, { type: "checkout_card_elements", payload: t }, St);
649
+ return await D(e, { type: "checkout_card_elements", payload: t }, Rt);
636
650
  } catch (r) {
637
651
  throw r;
638
652
  }
639
- }, Tr = async (e, t) => await x(e, { type: "setup_payment_method", payload: t }, mr), Ar = async (e, t) => await x(e, { type: "checkout", payload: t }, St), Ot = 1e3, Ir = async (e, t) => {
640
- const o = await it({
653
+ }, Dr = async (e, t) => await D(e, { type: "setup_payment_method", payload: t }, wr), Tt = async (e, t) => await D(e, { type: "checkout", payload: t }, Rt), Mt = 1e3, Lr = async (e, t) => {
654
+ const o = await dt({
641
655
  iframe: e,
642
656
  debug: !0,
643
- timeout: Ot,
657
+ timeout: Mt,
644
658
  childOrigin: "*"
645
659
  // TODO: use with proper childOrigin
646
660
  }).promise;
647
- return (await x(o, { type: "ping-3ds-status" }, qn)).status;
648
- }, jr = (e) => {
661
+ return (await D(o, { type: "ping-3ds-status" }, Zn)).status;
662
+ }, xr = (e) => {
649
663
  if (typeof e != "string") return !1;
650
664
  try {
651
665
  return JSON.parse(e), !0;
652
666
  } catch {
653
667
  return !1;
654
668
  }
655
- }, Mr = "@keyframes fadeIn{0%{opacity:0;transform:scale(.9)}to{opacity:1;transform:scale(1)}}.overlay{position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483648!important;display:flex;justify-content:center;align-items:center;background-color:#00000080}.container{max-width:500px;max-height:600px;width:100%;height:100%;background-color:#fff;position:relative;animation:fadeIn .3s ease-out}.frame{max-width:500px;max-height:600px;width:100%;height:100%;border:none}.cancel-button{position:absolute;background:transparent;border:none;font-size:1rem;color:#fff;cursor:pointer;top:-1.5rem;padding:0;right:0}", Fr = (e) => {
669
+ }, $e = (e) => async (t) => {
670
+ try {
671
+ t.flowCallbacks.onCheckoutStarted();
672
+ const r = await e(t);
673
+ if (r.mode === "setup")
674
+ t.flowCallbacks.onSetupPaymentMethodSuccess(r.result.payment_method_id);
675
+ else if (r.mode === "checkout")
676
+ t.flowCallbacks.onCheckoutSuccess(
677
+ r.result.invoice_urls,
678
+ r.result.subscription_ids,
679
+ r.result.customer_id
680
+ );
681
+ else
682
+ throw new Error(`Unhandled mode: ${r}`);
683
+ } catch (r) {
684
+ throw t.flowCallbacks.onCheckoutError(we(r)), r;
685
+ }
686
+ }, jt = (e) => async (t) => {
687
+ try {
688
+ return await e(t);
689
+ } catch (r) {
690
+ const { err__: o } = Y("init-error-catcher");
691
+ return o(r), { isAvailable: !1, reason: we(r) };
692
+ }
693
+ }, Y = (e) => {
694
+ const t = (...o) => {
695
+ window.console.log(`${de.green.bold("ojs/")}${de.bold.gray(`${e}`)} `, ...o);
696
+ }, r = (...o) => {
697
+ window.console.error(`${de.red.bold("ojs/")}${de.bold.gray(`${e}`)} `, ...o);
698
+ };
699
+ return {
700
+ log: t,
701
+ err: r,
702
+ log__: t,
703
+ err__: r
704
+ };
705
+ }, { log__: Do, err__: Ur } = Y("common"), qe = (e) => {
706
+ if (e.payment_methods.length !== 1)
707
+ throw new Error(`Expected exactly one payment method, got ${e.payment_methods.length}`);
708
+ return { payment_method_id: e.payment_methods[0].id };
709
+ }, Ft = (e, t) => {
710
+ const r = e.find((o) => t.safeParse(o).success);
711
+ if (!r)
712
+ throw Ur("No CPMs found for model. All models:", e), new Error("No CPMs found for model");
713
+ return t.parse(r);
714
+ }, { log__: $r, err__: Nt } = Y("common-cc"), ze = (e, t) => {
715
+ const r = ae.safeParse(e);
716
+ if (!r.success) {
717
+ const o = r.error.format(), s = wt(o);
718
+ for (const [i, a] of Object.entries(s))
719
+ t(i, a, i);
720
+ throw Nt("Got validation errors in non-CDE form fields", s), new Error("Got validation errors in non-CDE form fields");
721
+ }
722
+ return r.data;
723
+ }, qr = (e, t) => {
724
+ for (const r of e)
725
+ if (r.success === !1)
726
+ throw r.errors.forEach((o) => {
727
+ const s = _t.safeParse(o.elementType);
728
+ if (!s.success)
729
+ Nt(`Unknown field name in onValidationError: ${o.elementType}`);
730
+ else {
731
+ const i = s.data;
732
+ t(i, o.errors);
733
+ }
734
+ }), $r(`Error tokenizing card: got validation errors: ${JSON.stringify(r.errors)}`), new Error("Got validation errors while tokenizing card");
735
+ }, zr = "ojs-stripe-link-btn", { log__: A, err__: Hr } = Y("stripe-link"), Kr = n.object({
736
+ provider: n.literal("stripe_link"),
737
+ processor_name: n.literal("stripe"),
738
+ metadata: n.object({
739
+ stripe_pk: n.string()
740
+ })
741
+ }), Vr = n.array(
742
+ n.object({
743
+ our_existing_pm_id: n.string()
744
+ })
745
+ ).length(1), Yr = jt(
746
+ async ({ context: e, flowCallbacks: t }) => {
747
+ var d;
748
+ A("Checking if there are any CPMs for Stripe PR...");
749
+ const r = Ft(e.checkoutPaymentMethods, Kr);
750
+ A("Starting stripe link flow...");
751
+ const o = Array.from(e.cdeConnections.values())[0], s = await B(o), i = s.mode === "setup";
752
+ A("Creating stripe elements...");
753
+ const a = await Ue(o, s.token, i, void 0), { elements: c, stripe: l } = await Gn(r.metadata.stripe_pk, {
754
+ mode: "setup",
755
+ currency: a.currency,
756
+ setup_future_usage: "off_session",
757
+ paymentMethodCreation: "manual"
758
+ });
759
+ A("Mounting payment element...");
760
+ const u = c.create("expressCheckout", {
761
+ buttonHeight: (d = e.customInitParams.stripeLink) == null ? void 0 : d.buttonHeight,
762
+ paymentMethods: {
763
+ amazonPay: "never",
764
+ applePay: "never",
765
+ googlePay: "never",
766
+ paypal: "never"
767
+ }
768
+ });
769
+ return u.mount(`#${zr}`), u.on("click", async (f) => {
770
+ var m;
771
+ if (A("Stripe Link button clicked"), (m = e.customInitParams.stripeLink) != null && m.overrideLinkSubmit && !await e.customInitParams.stripeLink.overrideLinkSubmit()) {
772
+ A("Stripe Link submit aborted by overrideLinkSubmit");
773
+ return;
774
+ }
775
+ f.resolve();
776
+ }), u.on("confirm", async (f) => {
777
+ A("Stripe Link window confirmed", f);
778
+ const m = await l.createPaymentMethod({
779
+ elements: c,
780
+ params: {
781
+ billing_details: f.billingDetails
782
+ }
783
+ });
784
+ m.error ? (Hr("error", m.error), t.onCheckoutError(m.error.message ?? "Stripe Link unknown error")) : (A("paymentMethod", m.paymentMethod), ie.stripeLink.run({
785
+ context: e,
786
+ checkoutPaymentMethod: r,
787
+ nonCdeFormInputs: ge(e.formDiv),
788
+ flowCallbacks: t,
789
+ customParams: { stripePM: m.paymentMethod },
790
+ initResult: { isAvailable: !0 }
791
+ }));
792
+ }), { isAvailable: !0 };
793
+ }
794
+ ), Zr = $e(
795
+ async ({
796
+ context: e,
797
+ checkoutPaymentMethod: t,
798
+ nonCdeFormInputs: r,
799
+ flowCallbacks: o,
800
+ customParams: s
801
+ }) => {
802
+ A("Running Stripe PR flow...");
803
+ const i = Array.from(e.cdeConnections.values())[0];
804
+ A("Merging PM fields with form fields...");
805
+ const a = Wr(r, s.stripePM), c = ze(a, o.onValidationError);
806
+ A("Starting payment flow...");
807
+ const l = await Ar(i, {
808
+ payment_provider: t.provider,
809
+ checkout_payment_method: t,
810
+ their_existing_pm_id: s.stripePM.id
811
+ });
812
+ A("Start payment flow response", l);
813
+ const d = Vr.parse(l.required_user_actions)[0].our_existing_pm_id, f = await B(i);
814
+ if (f.mode === "setup") {
815
+ A("Doing payment setup...");
816
+ const m = await Ce(i, {
817
+ secure_token: f.token,
818
+ existing_cc_pm_id: d
819
+ });
820
+ return { mode: "setup", result: qe(m) };
821
+ } else {
822
+ A("Doing checkout...");
823
+ const m = {
824
+ secure_token: f.token,
825
+ payment_input: {
826
+ provider_type: t.provider
827
+ },
828
+ customer_email: c[y.EMAIL],
829
+ customer_zip_code: c[y.ZIP_CODE],
830
+ customer_country: c[y.COUNTRY],
831
+ promotion_code: c[y.PROMOTION_CODE],
832
+ line_items: f.line_items,
833
+ total_amount_atom: f.amount_total_atom,
834
+ cancel_at_end: !1,
835
+ checkout_payment_method: t
836
+ };
837
+ return { mode: "checkout", result: await Tt(i, m) };
838
+ }
839
+ }
840
+ ), Wr = (e, t) => {
841
+ var a, c, l, u, d;
842
+ const r = { ...e }, [o, ...s] = ((c = (a = t.billing_details.name) == null ? void 0 : a.trim()) == null ? void 0 : c.split(/\s+/)) ?? [], i = s.join(" ") || void 0;
843
+ return r[y.FIRST_NAME] = r[y.FIRST_NAME] || o || "_OP_UNKNOWN", r[y.LAST_NAME] = r[y.LAST_NAME] || i || "_OP_UNKNOWN", r[y.EMAIL] = r[y.EMAIL] || // eslint-disable-next-line @typescript-eslint/no-explicit-any
844
+ ((l = t.link) == null ? void 0 : l.email) || t.billing_details.email || "op_unfilled@getopenpay.com", r[y.ZIP_CODE] = r[y.ZIP_CODE] || ((u = t.billing_details.address) == null ? void 0 : u.postal_code) || "00000", r[y.COUNTRY] = r[y.COUNTRY] || ((d = t.billing_details.address) == null ? void 0 : d.country) || "US", A("Final form inputs:", r), r;
845
+ }, Jr = "@keyframes fadeIn{0%{opacity:0;transform:scale(.9)}to{opacity:1;transform:scale(1)}}.overlay{position:fixed;top:0;left:0;width:100%;height:100%;z-index:2147483648!important;display:flex;justify-content:center;align-items:center;background-color:#00000080}.container{max-width:500px;max-height:600px;width:100%;height:100%;background-color:#fff;position:relative;animation:fadeIn .3s ease-out}.frame{max-width:500px;max-height:600px;width:100%;height:100%;border:none}.cancel-button{position:absolute;background:transparent;border:none;font-size:1rem;color:#fff;cursor:pointer;top:-1.5rem;padding:0;right:0}", Br = (e) => {
656
846
  const t = document.createElement("template");
657
847
  t.innerHTML = `
658
848
  <style>
659
- ${Mr}
849
+ ${Jr}
660
850
  </style>
661
851
  <div class="overlay">
662
852
  <div class="container">
@@ -670,125 +860,59 @@ const x = async (e, t, r) => {
670
860
  const s = o.querySelector("#three-ds-iframe"), i = o.querySelector(".cancel-button");
671
861
  return document.body.appendChild(r), { host: r, iframe: s, cancelButton: i };
672
862
  };
673
- function Dr(e, t, r) {
863
+ function Gr(e, t, r) {
674
864
  const o = async () => {
675
865
  try {
676
- const i = await Ir(e, r);
866
+ const i = await Lr(e, r);
677
867
  i && (clearInterval(s), t(i));
678
868
  } catch {
679
869
  }
680
870
  };
681
871
  o();
682
- const s = setInterval(o, Ot);
872
+ const s = setInterval(o, Mt);
683
873
  return s;
684
874
  }
685
- function Nr({
875
+ function Qr({
686
876
  elements: e,
687
877
  pollingInterval: t,
688
878
  resolve: r
689
879
  }) {
690
880
  const o = () => {
691
- clearInterval(t), e.host.remove(), r(me.CANCELLED);
881
+ clearInterval(t), e.host.remove(), r(_e.CANCELLED);
692
882
  };
693
883
  return e.cancelButton.addEventListener("click", o), () => {
694
884
  e.cancelButton.removeEventListener("click", o);
695
885
  };
696
886
  }
697
- async function xr({
887
+ async function Xr({
698
888
  url: e,
699
889
  baseUrl: t
700
890
  }) {
701
- const r = Fr(e);
891
+ const r = Br(e);
702
892
  return new Promise((o) => {
703
893
  const s = (c) => {
704
894
  setTimeout(() => {
705
895
  r.host.remove();
706
896
  }, 1e3), o(c), a == null || a();
707
- }, i = Dr(r.iframe, s, new URL(t).origin), a = Nr({
897
+ }, i = Gr(r.iframe, s, new URL(t).origin), a = Qr({
708
898
  elements: r,
709
899
  pollingInterval: i,
710
900
  resolve: o
711
901
  });
712
902
  });
713
903
  }
714
- const Rt = (e) => async (t) => {
715
- try {
716
- t.flowCallbacks.onCheckoutStarted();
717
- const r = await e(t);
718
- if (r.mode === "setup")
719
- t.flowCallbacks.onSetupPaymentMethodSuccess(r.result.payment_method_id);
720
- else if (r.mode === "checkout")
721
- t.flowCallbacks.onCheckoutSuccess(
722
- r.result.invoice_urls,
723
- r.result.subscription_ids,
724
- r.result.customer_id
725
- );
726
- else
727
- throw new Error(`Unhandled mode: ${r}`);
728
- } catch (r) {
729
- throw t.flowCallbacks.onCheckoutError(pe(r)), r;
730
- }
731
- }, Lr = (e) => async (t) => {
732
- try {
733
- return await e(t);
734
- } catch (r) {
735
- const { err__: o } = J("init-error-catcher");
736
- return o(r), { isAvailable: !1, reason: pe(r) };
737
- }
738
- }, J = (e) => {
739
- const t = (...o) => {
740
- window.console.log(`${ae.green.bold("ojs/")}${ae.bold.gray(`${e}`)} `, ...o);
741
- }, r = (...o) => {
742
- window.console.error(`${ae.red.bold("ojs/")}${ae.bold.gray(`${e}`)} `, ...o);
743
- };
744
- return {
745
- log: t,
746
- err: r,
747
- log__: t,
748
- err__: r
749
- };
750
- }, { log__: $r, err__: kt } = J("common-cc"), Tt = (e, t) => {
751
- const r = oe.safeParse(e);
752
- if (!r.success) {
753
- const o = r.error.format(), s = pt(o);
754
- for (const [i, a] of Object.entries(s))
755
- t(i, a, i);
756
- throw kt("Got validation errors in non-CDE form fields", s), new Error("Got validation errors in non-CDE form fields");
757
- }
758
- return r.data;
759
- }, Ur = (e, t) => {
760
- for (const r of e)
761
- if (r.success === !1)
762
- throw r.errors.forEach((o) => {
763
- const s = dt.safeParse(o.elementType);
764
- if (!s.success)
765
- kt(`Unknown field name in onValidationError: ${o.elementType}`);
766
- else {
767
- const i = s.data;
768
- t(i, o.errors);
769
- }
770
- }), $r(`Error tokenizing card: got validation errors: ${JSON.stringify(r.errors)}`), new Error("Got validation errors while tokenizing card");
771
- }, { err__: Ae } = J("commmon"), At = (e) => {
772
- if (e.payment_methods.length !== 1)
773
- throw new Error(`Expected exactly one payment method, got ${e.payment_methods.length}`);
774
- return { payment_method_id: e.payment_methods[0].id };
775
- }, qr = (e, t) => {
776
- const r = e.find((o) => t.safeParse(o).success);
777
- if (!r)
778
- throw Ae(`No CPMs found for model ${t}`), Ae(e), Ae("zodModel"), new Error(`No CPMs found for model ${t}`);
779
- return t.parse(r);
780
- }, { log__: P, err__: et } = J("common-cc"), { log__: tt } = J("stripe-cc"), zr = Rt(
904
+ const { log__: P, err__: ot } = Y("common-cc"), { log__: st } = Y("stripe-cc"), eo = $e(
781
905
  async ({ context: e, checkoutPaymentMethod: t, nonCdeFormInputs: r, flowCallbacks: o }) => {
782
- var d;
906
+ var u;
783
907
  P("├ Running common CC flow...", { checkoutPaymentMethod: t });
784
- const s = Array.from(e.cdeConnections.values())[0], i = await se(s);
908
+ const s = Array.from(e.cdeConnections.values())[0], i = await B(s);
785
909
  P(`├ Validating non-CDE form fields [Mode: ${i.mode}]`);
786
- const a = Tt(r, o.onValidationError);
910
+ const a = ze(r, o.onValidationError);
787
911
  P(`├ Tokenizing card info in CDE [Session: ${e.elementsSessionId}]`);
788
- const c = await kr(e.cdeConnections, {
912
+ const c = await Nr(e.cdeConnections, {
789
913
  session_id: e.elementsSessionId
790
914
  });
791
- Ur(c, o.onValidationError);
915
+ qr(c, o.onValidationError);
792
916
  const l = {
793
917
  session_id: e.elementsSessionId,
794
918
  checkout_payment_method: t,
@@ -797,82 +921,82 @@ const Rt = (e) => async (t) => {
797
921
  try {
798
922
  if (i.mode === "setup") {
799
923
  P(`├ Setting up payment method in CDE [Token: ${i.token}]`);
800
- const m = await Tr(s, l);
801
- return P(`╰ Setup completed successfully [PM ID: ${m.payment_method_id}]`), { mode: "setup", result: m };
924
+ const d = await Dr(s, l);
925
+ return P(`╰ Setup completed successfully [PM ID: ${d.payment_method_id}]`), { mode: "setup", result: d };
802
926
  } else {
803
927
  P(`├ Initial checkout flow. Checking out card info in CDE [Session: ${e.elementsSessionId}]`);
804
- const m = await Xe(s, l);
805
- return P("╰ Checkout completed successfully."), { mode: "checkout", result: m };
928
+ const d = await rt(s, l);
929
+ return P("╰ Checkout completed successfully."), { mode: "checkout", result: d };
806
930
  }
807
- } catch (m) {
808
- if (m instanceof Pt && m.originalErrorMessage === "3DS_REQUIRED") {
809
- P("├ Card requires 3DS, starting non-legacy payment flow");
810
- const E = ((d = m.response.headers) == null ? void 0 : d["op-should-use-new-flow"]) === "true", g = await Pr(s, l);
811
- if (P(`├ op-should-use-new-flow: ${E}`), P("├ Payment flow result:", g), E ? await Kr(g, e.baseUrl) : await Yr(g), i.mode === "setup") {
812
- P(`├ Confirming payment flow [cc_pm_id: ${g.cc_pm_id}]`);
813
- const _ = await xe(s, {
931
+ } catch (d) {
932
+ if (d instanceof At && d.originalErrorMessage === "3DS_REQUIRED") {
933
+ P("├ Card requires 3DS, starting non-legacy payment flow"), P("error.response.headers", d.response.headers);
934
+ const f = ((u = d.response.headers) == null ? void 0 : u["op-should-use-new-flow"]) === "true", m = await Tr(s, l);
935
+ if (P(`├ op-should-use-new-flow: ${f}`), P("├ Payment flow result:", m), f ? await ro(m, e.baseUrl) : await oo(m), i.mode === "setup") {
936
+ P(`├ Confirming payment flow [cc_pm_id: ${m.cc_pm_id}]`);
937
+ const _ = await Ce(s, {
814
938
  secure_token: i.token,
815
- existing_cc_pm_id: g.cc_pm_id
939
+ existing_cc_pm_id: m.cc_pm_id
816
940
  });
817
941
  P("├ Confirm payment flow result received Result:", _);
818
- const h = At(_);
819
- return P(`╰ Setup completed successfully [PM ID: ${h.payment_method_id}]`), { mode: "setup", result: h };
942
+ const E = qe(_);
943
+ return P(`╰ Setup completed successfully [PM ID: ${E.payment_method_id}]`), { mode: "setup", result: E };
820
944
  } else {
821
- P(`├ Checking out after 3DS flow [Flow: ${E ? "new" : "legacy"}]`);
822
- const _ = await Xe(s, {
945
+ P(`├ Checking out after 3DS flow [Flow: ${f ? "new" : "legacy"}]`);
946
+ const _ = await rt(s, {
823
947
  ...l,
824
- existing_cc_pm_id: g.cc_pm_id,
825
- do_not_use_legacy_cc_flow: !E
948
+ existing_cc_pm_id: m.cc_pm_id,
949
+ do_not_use_legacy_cc_flow: !f
826
950
  });
827
951
  return P("╰ Checkout completed successfully."), { mode: "checkout", result: _ };
828
952
  }
829
953
  }
830
- throw et("╰ Error checking out card info in CDE"), et(m), m;
954
+ throw ot("╰ Error checking out card info in CDE"), ot(d), d;
831
955
  }
832
956
  }
833
- ), Hr = (e) => {
957
+ ), to = (e) => {
834
958
  const t = e.required_user_actions.find((r) => r.type === "stripe_3ds");
835
959
  if (!t)
836
960
  throw new Error("No stripe 3DS action found");
837
- return yt.parse(t);
838
- }, Vr = (e) => {
961
+ return Et.parse(t);
962
+ }, no = (e) => {
839
963
  const t = e.required_user_actions.find((r) => r.type === "airwallex_payment_consent");
840
964
  if (!t)
841
965
  throw new Error("No common 3DS action found");
842
- return zn.parse(t);
843
- }, Kr = async (e, t) => {
844
- const r = Vr(e);
966
+ return Wn.parse(t);
967
+ }, ro = async (e, t) => {
968
+ const r = no(e);
845
969
  P(`├ Using common 3DS flow [URL: ${r.redirect_url}]`);
846
- const o = await xr({ url: r.redirect_url, baseUrl: t });
847
- if (P(`╰ 3DS verification completed [Status: ${o}]`), o === me.CANCELLED)
970
+ const o = await Xr({ url: r.redirect_url, baseUrl: t });
971
+ if (P(`╰ 3DS verification completed [Status: ${o}]`), o === _e.CANCELLED)
848
972
  throw new Error("3DS verification cancelled");
849
- if (o === me.FAILURE)
973
+ if (o === _e.FAILURE)
850
974
  throw new Error("3DS verification failed");
851
- }, Yr = async (e) => {
852
- const t = Hr(e);
853
- tt(`├ Using stripe 3DS flow [Client Secret: ${t.client_secret.substring(0, 8)}...]`), await gt(t), tt("╰ Stripe 3DS flow completed successfully");
854
- }, { log__: T, err__: Zr } = J("stripe-pr"), Jr = n.object({
975
+ }, oo = async (e) => {
976
+ const t = to(e);
977
+ st(`├ Using stripe 3DS flow [Client Secret: ${t.client_secret.substring(0, 8)}...]`), await bt(t), st("╰ Stripe 3DS flow completed successfully");
978
+ }, { log__: I, err__: so } = Y("stripe-pr"), io = n.object({
855
979
  provider: n.union([n.literal("apple_pay"), n.literal("google_pay")]),
856
980
  processor_name: n.literal("stripe"),
857
981
  metadata: n.object({
858
982
  stripe_pk: n.string()
859
983
  })
860
- }), Wr = Lr(
984
+ }), ao = jt(
861
985
  async ({ context: e }) => {
862
- T("Checking if there are any CPMs for Stripe PR...");
863
- const t = qr(e.checkoutPaymentMethods, Jr);
864
- T("Initializing Stripe PR flow...");
865
- const r = Array.from(e.cdeConnections.values())[0], o = await se(r), s = o.mode === "setup";
866
- T("Getting initial preview amount");
867
- const i = await vt(r, o.token, s, void 0), a = await Kn(
986
+ I("Checking if there are any CPMs for Stripe PR...");
987
+ const t = Ft(e.checkoutPaymentMethods, io);
988
+ I("Initializing Stripe PR flow...");
989
+ const r = Array.from(e.cdeConnections.values())[0], o = await B(r), s = o.mode === "setup";
990
+ I("Getting initial preview amount");
991
+ const i = await Ue(r, o.token, s, void 0), a = await Qn(
868
992
  t.metadata.stripe_pk,
869
993
  i.amountAtom,
870
994
  i.currency,
871
995
  s
872
996
  );
873
- T("Checking if can make payment");
997
+ I("Checking if can make payment");
874
998
  const c = await a.canMakePayment();
875
- return c === null ? (Zr("canMakePayment returned null"), { isAvailable: !1, reason: "canMakePayment returned null" }) : (T("Stripe PR flow initialized successfully. Can make payment", c), {
999
+ return c === null ? (so("canMakePayment returned null"), { isAvailable: !1, reason: "canMakePayment returned null" }) : (I("Stripe PR flow initialized successfully. Can make payment", c), {
876
1000
  isAvailable: !0,
877
1001
  pr: a,
878
1002
  availableProviders: {
@@ -881,7 +1005,7 @@ const Rt = (e) => async (t) => {
881
1005
  }
882
1006
  });
883
1007
  }
884
- ), Br = Rt(
1008
+ ), co = $e(
885
1009
  async ({
886
1010
  context: e,
887
1011
  checkoutPaymentMethod: t,
@@ -890,54 +1014,54 @@ const Rt = (e) => async (t) => {
890
1014
  customParams: s,
891
1015
  initResult: i
892
1016
  }) => {
893
- if (T("Running Stripe PR flow..."), s.provider !== t.provider)
1017
+ if (I("Running Stripe PR flow..."), s.provider !== t.provider)
894
1018
  throw new Error(`Provider mismatch. Expected ${s.provider}, got ${t.provider}`);
895
1019
  const a = Array.from(e.cdeConnections.values())[0], c = i.pr;
896
1020
  if (s != null && s.overridePaymentRequest) {
897
- const h = s.overridePaymentRequest;
898
- T("Overriding PR amount with", h), Qr(c, h.amount, h.pending);
1021
+ const E = s.overridePaymentRequest;
1022
+ I("Overriding PR amount with", E), uo(c, E.amount, E.pending);
899
1023
  }
900
- T("Showing PR dialog..."), c.show();
901
- const l = await Yn(c);
902
- T("Stripe PM added event:", l), T("Merging PM fields with form fields...");
903
- const d = Gr(r, l), m = Tt(d, o.onValidationError);
904
- T("PR dialog finished. Starting payment flow...");
905
- const E = await vr(a, {
906
- fields: m,
1024
+ I("Showing PR dialog..."), c.show();
1025
+ const l = await Xn(c);
1026
+ I("Stripe PM added event:", l), I("Merging PM fields with form fields...");
1027
+ const u = lo(r, l), d = ze(u, o.onValidationError);
1028
+ I("PR dialog finished. Starting payment flow...");
1029
+ const f = await Mr(a, {
1030
+ fields: d,
907
1031
  checkoutPaymentMethod: t
908
- }), g = Xr(E);
909
- T("Confirming PR with Stripe..."), await Jn(g, l);
910
- const _ = await se(a);
1032
+ }), m = mo(f);
1033
+ I("Confirming PR with Stripe..."), await tr(m, l);
1034
+ const _ = await B(a);
911
1035
  if (_.mode === "setup") {
912
- T("Confirming payment flow for setup...");
913
- const h = await xe(a, {
1036
+ I("Confirming payment flow for setup...");
1037
+ const E = await Ce(a, {
914
1038
  secure_token: _.token
915
1039
  });
916
- return { mode: "setup", result: At(h) };
1040
+ return { mode: "setup", result: qe(E) };
917
1041
  } else {
918
- T("Performing checkout...");
919
- const h = {
1042
+ I("Performing checkout...");
1043
+ const E = {
920
1044
  secure_token: _.token,
921
1045
  payment_input: {
922
1046
  provider_type: t.provider
923
1047
  },
924
- customer_email: m[C.EMAIL],
925
- customer_zip_code: m[C.ZIP_CODE],
926
- customer_country: m[C.COUNTRY],
927
- promotion_code: m[C.PROMOTION_CODE],
1048
+ customer_email: d[y.EMAIL],
1049
+ customer_zip_code: d[y.ZIP_CODE],
1050
+ customer_country: d[y.COUNTRY],
1051
+ promotion_code: d[y.PROMOTION_CODE],
928
1052
  line_items: _.line_items,
929
1053
  total_amount_atom: _.amount_total_atom,
930
1054
  cancel_at_end: !1,
931
1055
  checkout_payment_method: t
932
1056
  };
933
- return { mode: "checkout", result: await Ar(a, h) };
1057
+ return { mode: "checkout", result: await Tt(a, E) };
934
1058
  }
935
1059
  }
936
- ), Gr = (e, t) => {
937
- var a, c, l, d;
1060
+ ), lo = (e, t) => {
1061
+ var a, c, l, u;
938
1062
  const r = { ...e }, [o, ...s] = ((c = (a = t.payerName) == null ? void 0 : a.trim()) == null ? void 0 : c.split(/\s+/)) ?? [], i = s.join(" ") || void 0;
939
- return r[C.FIRST_NAME] = r[C.FIRST_NAME] || o || "_OP_UNKNOWN", r[C.LAST_NAME] = r[C.LAST_NAME] || i || "_OP_UNKNOWN", r[C.EMAIL] = r[C.EMAIL] || t.payerEmail || "op_unfilled@getopenpay.com", r[C.ZIP_CODE] = r[C.ZIP_CODE] || ((l = t.shippingAddress) == null ? void 0 : l.postalCode) || "00000", r[C.COUNTRY] = r[C.COUNTRY] || ((d = t.shippingAddress) == null ? void 0 : d.country) || "US", T("Final form inputs:", r), r;
940
- }, Qr = (e, t, r) => {
1063
+ return r[y.FIRST_NAME] = r[y.FIRST_NAME] || o || "_OP_UNKNOWN", r[y.LAST_NAME] = r[y.LAST_NAME] || i || "_OP_UNKNOWN", r[y.EMAIL] = r[y.EMAIL] || t.payerEmail || "op_unfilled@getopenpay.com", r[y.ZIP_CODE] = r[y.ZIP_CODE] || ((l = t.shippingAddress) == null ? void 0 : l.postalCode) || "00000", r[y.COUNTRY] = r[y.COUNTRY] || ((u = t.shippingAddress) == null ? void 0 : u.country) || "US", I("Final form inputs:", r), r;
1064
+ }, uo = (e, t, r) => {
941
1065
  e.update({
942
1066
  total: {
943
1067
  amount: t.amountAtom,
@@ -946,116 +1070,121 @@ const Rt = (e) => async (t) => {
946
1070
  },
947
1071
  currency: t.currency
948
1072
  });
949
- }, Xr = (e) => {
1073
+ }, mo = (e) => {
950
1074
  if (e.required_user_actions.length !== 1)
951
1075
  throw new Error(`Error occurred.
952
1076
  Details: got ${e.required_user_actions.length} required user actions`);
953
- return Hn.parse(e.required_user_actions[0]);
954
- }, nt = (e, t, r) => {
1077
+ return Jn.parse(e.required_user_actions[0]);
1078
+ }, it = (e, t, r) => {
955
1079
  const o = e.filter((s) => s.provider === t);
956
1080
  if (o.length === 0)
957
1081
  throw new Error(`No CPMs found with provider '${t}' and processor '${r}'`);
958
1082
  if (o.length !== 1)
959
1083
  throw new Error(`More than one CPM found with provider '${t}' and processor '${r}'`);
960
1084
  return o[0];
961
- }, Fe = {
1085
+ }, ie = {
962
1086
  // ✋ Note: For flows that require initialization, please add them to `init-flows.ts`
963
- // Stripe
1087
+ // Common
964
1088
  commonCC: {
965
- run: zr
1089
+ run: eo
966
1090
  },
1091
+ // Stripe
967
1092
  stripePR: {
968
- init: Wr,
969
- run: Br
1093
+ init: ao,
1094
+ run: co
1095
+ },
1096
+ stripeLink: {
1097
+ init: Yr,
1098
+ run: Zr
970
1099
  }
971
1100
  // 👉 Add more flows here
972
1101
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
973
1102
  };
974
- function It(e) {
1103
+ function Dt(e) {
975
1104
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
976
1105
  }
977
- var he = {};
978
- Object.defineProperty(he, "__esModule", {
1106
+ var be = {};
1107
+ Object.defineProperty(be, "__esModule", {
979
1108
  value: !0
980
1109
  });
981
- he.Observable = void 0;
982
- const jt = (e) => !!Symbol[e], Le = (e) => jt(e) ? Symbol[e] : "@@" + e, eo = Le("iterator"), De = Le("observable"), Mt = Le("species");
983
- function fe(e, t) {
1110
+ be.Observable = void 0;
1111
+ const Lt = (e) => !!Symbol[e], He = (e) => Lt(e) ? Symbol[e] : "@@" + e, po = He("iterator"), Le = He("observable"), xt = He("species");
1112
+ function he(e, t) {
984
1113
  let r = e[t];
985
1114
  if (r != null) {
986
1115
  if (typeof r != "function") throw new TypeError(r + " is not a function");
987
1116
  return r;
988
1117
  }
989
1118
  }
990
- function ne(e) {
1119
+ function oe(e) {
991
1120
  let t = e.constructor;
992
- return t !== void 0 && (t = t[Mt], t === null && (t = void 0)), t !== void 0 ? t : we;
1121
+ return t !== void 0 && (t = t[xt], t === null && (t = void 0)), t !== void 0 ? t : Se;
993
1122
  }
994
- function to(e) {
995
- return e instanceof we;
1123
+ function fo(e) {
1124
+ return e instanceof Se;
996
1125
  }
997
- function X(e) {
998
- X.log ? X.log(e) : setTimeout(() => {
1126
+ function te(e) {
1127
+ te.log ? te.log(e) : setTimeout(() => {
999
1128
  throw e;
1000
1129
  });
1001
1130
  }
1002
- function le(e) {
1131
+ function pe(e) {
1003
1132
  Promise.resolve().then(() => {
1004
1133
  try {
1005
1134
  e();
1006
1135
  } catch (t) {
1007
- X(t);
1136
+ te(t);
1008
1137
  }
1009
1138
  });
1010
1139
  }
1011
- function Ft(e) {
1140
+ function Ut(e) {
1012
1141
  let t = e._cleanup;
1013
1142
  if (t !== void 0 && (e._cleanup = void 0, !!t))
1014
1143
  try {
1015
1144
  if (typeof t == "function")
1016
1145
  t();
1017
1146
  else {
1018
- let r = fe(t, "unsubscribe");
1147
+ let r = he(t, "unsubscribe");
1019
1148
  r && r.call(t);
1020
1149
  }
1021
1150
  } catch (r) {
1022
- X(r);
1151
+ te(r);
1023
1152
  }
1024
1153
  }
1025
- function Ne(e) {
1154
+ function xe(e) {
1026
1155
  e._observer = void 0, e._queue = void 0, e._state = "closed";
1027
1156
  }
1028
- function no(e) {
1157
+ function yo(e) {
1029
1158
  let t = e._queue;
1030
1159
  if (t) {
1031
1160
  e._queue = void 0, e._state = "ready";
1032
- for (let r = 0; r < t.length && (Dt(e, t[r].type, t[r].value), e._state !== "closed"); ++r)
1161
+ for (let r = 0; r < t.length && ($t(e, t[r].type, t[r].value), e._state !== "closed"); ++r)
1033
1162
  ;
1034
1163
  }
1035
1164
  }
1036
- function Dt(e, t, r) {
1165
+ function $t(e, t, r) {
1037
1166
  e._state = "running";
1038
1167
  let o = e._observer;
1039
1168
  try {
1040
- let s = fe(o, t);
1169
+ let s = he(o, t);
1041
1170
  switch (t) {
1042
1171
  case "next":
1043
1172
  s && s.call(o, r);
1044
1173
  break;
1045
1174
  case "error":
1046
- if (Ne(e), s) s.call(o, r);
1175
+ if (xe(e), s) s.call(o, r);
1047
1176
  else throw r;
1048
1177
  break;
1049
1178
  case "complete":
1050
- Ne(e), s && s.call(o);
1179
+ xe(e), s && s.call(o);
1051
1180
  break;
1052
1181
  }
1053
1182
  } catch (s) {
1054
- X(s);
1183
+ te(s);
1055
1184
  }
1056
- e._state === "closed" ? Ft(e) : e._state === "running" && (e._state = "ready");
1185
+ e._state === "closed" ? Ut(e) : e._state === "running" && (e._state = "ready");
1057
1186
  }
1058
- function Ie(e, t, r) {
1187
+ function Ne(e, t, r) {
1059
1188
  if (e._state !== "closed") {
1060
1189
  if (e._state === "buffering") {
1061
1190
  e._queue.push({
@@ -1068,13 +1197,13 @@ function Ie(e, t, r) {
1068
1197
  e._state = "buffering", e._queue = [{
1069
1198
  type: t,
1070
1199
  value: r
1071
- }], le(() => no(e));
1200
+ }], pe(() => yo(e));
1072
1201
  return;
1073
1202
  }
1074
- Dt(e, t, r);
1203
+ $t(e, t, r);
1075
1204
  }
1076
1205
  }
1077
- class ro {
1206
+ class _o {
1078
1207
  constructor(t, r) {
1079
1208
  this._cleanup = void 0, this._observer = t, this._queue = void 0, this._state = "initializing";
1080
1209
  let o = this, s = {
@@ -1082,13 +1211,13 @@ class ro {
1082
1211
  return o._state === "closed";
1083
1212
  },
1084
1213
  next(i) {
1085
- Ie(o, "next", i);
1214
+ Ne(o, "next", i);
1086
1215
  },
1087
1216
  error(i) {
1088
- Ie(o, "error", i);
1217
+ Ne(o, "error", i);
1089
1218
  },
1090
1219
  complete() {
1091
- Ie(o, "complete");
1220
+ Ne(o, "complete");
1092
1221
  }
1093
1222
  };
1094
1223
  try {
@@ -1102,12 +1231,12 @@ class ro {
1102
1231
  return this._state === "closed";
1103
1232
  }
1104
1233
  unsubscribe() {
1105
- this._state !== "closed" && (Ne(this), Ft(this));
1234
+ this._state !== "closed" && (xe(this), Ut(this));
1106
1235
  }
1107
1236
  }
1108
- let we = class ue {
1237
+ let Se = class fe {
1109
1238
  constructor(t) {
1110
- if (!(this instanceof ue)) throw new TypeError("Observable cannot be called as a function");
1239
+ if (!(this instanceof fe)) throw new TypeError("Observable cannot be called as a function");
1111
1240
  if (typeof t != "function") throw new TypeError("Observable initializer must be a function");
1112
1241
  this._subscriber = t;
1113
1242
  }
@@ -1116,7 +1245,7 @@ let we = class ue {
1116
1245
  next: t,
1117
1246
  error: arguments[1],
1118
1247
  complete: arguments[2]
1119
- }), new ro(t, this._subscriber);
1248
+ }), new _o(t, this._subscriber);
1120
1249
  }
1121
1250
  forEach(t) {
1122
1251
  return new Promise((r, o) => {
@@ -1142,7 +1271,7 @@ let we = class ue {
1142
1271
  }
1143
1272
  map(t) {
1144
1273
  if (typeof t != "function") throw new TypeError(t + " is not a function");
1145
- let r = ne(this);
1274
+ let r = oe(this);
1146
1275
  return new r((o) => this.subscribe({
1147
1276
  next(s) {
1148
1277
  try {
@@ -1162,7 +1291,7 @@ let we = class ue {
1162
1291
  }
1163
1292
  filter(t) {
1164
1293
  if (typeof t != "function") throw new TypeError(t + " is not a function");
1165
- let r = ne(this);
1294
+ let r = oe(this);
1166
1295
  return new r((o) => this.subscribe({
1167
1296
  next(s) {
1168
1297
  try {
@@ -1182,15 +1311,15 @@ let we = class ue {
1182
1311
  }
1183
1312
  reduce(t) {
1184
1313
  if (typeof t != "function") throw new TypeError(t + " is not a function");
1185
- let r = ne(this), o = arguments.length > 1, s = !1, a = arguments[1];
1314
+ let r = oe(this), o = arguments.length > 1, s = !1, a = arguments[1];
1186
1315
  return new r((c) => this.subscribe({
1187
1316
  next(l) {
1188
- let d = !s;
1189
- if (s = !0, !d || o)
1317
+ let u = !s;
1318
+ if (s = !0, !u || o)
1190
1319
  try {
1191
1320
  a = t(a, l);
1192
- } catch (m) {
1193
- return c.error(m);
1321
+ } catch (d) {
1322
+ return c.error(d);
1194
1323
  }
1195
1324
  else
1196
1325
  a = l;
@@ -1209,7 +1338,7 @@ let we = class ue {
1209
1338
  return await this.forEach((r) => t.push(r)), t;
1210
1339
  }
1211
1340
  concat(...t) {
1212
- let r = ne(this);
1341
+ let r = oe(this);
1213
1342
  return new r((o) => {
1214
1343
  let s, i = 0;
1215
1344
  function a(c) {
@@ -1232,26 +1361,26 @@ let we = class ue {
1232
1361
  }
1233
1362
  flatMap(t) {
1234
1363
  if (typeof t != "function") throw new TypeError(t + " is not a function");
1235
- let r = ne(this);
1364
+ let r = oe(this);
1236
1365
  return new r((o) => {
1237
1366
  let s = [], i = this.subscribe({
1238
1367
  next(c) {
1239
1368
  if (t)
1240
1369
  try {
1241
1370
  c = t(c);
1242
- } catch (d) {
1243
- return o.error(d);
1371
+ } catch (u) {
1372
+ return o.error(u);
1244
1373
  }
1245
1374
  let l = r.from(c).subscribe({
1246
- next(d) {
1247
- o.next(d);
1375
+ next(u) {
1376
+ o.next(u);
1248
1377
  },
1249
- error(d) {
1250
- o.error(d);
1378
+ error(u) {
1379
+ o.error(u);
1251
1380
  },
1252
1381
  complete() {
1253
- let d = s.indexOf(l);
1254
- d >= 0 && s.splice(d, 1), a();
1382
+ let u = s.indexOf(l);
1383
+ u >= 0 && s.splice(u, 1), a();
1255
1384
  }
1256
1385
  });
1257
1386
  s.push(l);
@@ -1271,21 +1400,21 @@ let we = class ue {
1271
1400
  };
1272
1401
  });
1273
1402
  }
1274
- [De]() {
1403
+ [Le]() {
1275
1404
  return this;
1276
1405
  }
1277
1406
  static from(t) {
1278
- let r = typeof this == "function" ? this : ue;
1407
+ let r = typeof this == "function" ? this : fe;
1279
1408
  if (t == null) throw new TypeError(t + " is not an object");
1280
- let o = fe(t, De);
1409
+ let o = he(t, Le);
1281
1410
  if (o) {
1282
1411
  let s = o.call(t);
1283
1412
  if (Object(s) !== s) throw new TypeError(s + " is not an object");
1284
- return to(s) && s.constructor === r ? s : new r((i) => s.subscribe(i));
1413
+ return fo(s) && s.constructor === r ? s : new r((i) => s.subscribe(i));
1285
1414
  }
1286
- if (jt("iterator") && (o = fe(t, eo), o))
1415
+ if (Lt("iterator") && (o = he(t, po), o))
1287
1416
  return new r((s) => {
1288
- le(() => {
1417
+ pe(() => {
1289
1418
  if (!s.closed) {
1290
1419
  for (let i of o.call(t))
1291
1420
  if (s.next(i), s.closed) return;
@@ -1295,7 +1424,7 @@ let we = class ue {
1295
1424
  });
1296
1425
  if (Array.isArray(t))
1297
1426
  return new r((s) => {
1298
- le(() => {
1427
+ pe(() => {
1299
1428
  if (!s.closed) {
1300
1429
  for (let i = 0; i < t.length; ++i)
1301
1430
  if (s.next(t[i]), s.closed) return;
@@ -1306,9 +1435,9 @@ let we = class ue {
1306
1435
  throw new TypeError(t + " is not observable");
1307
1436
  }
1308
1437
  static of(...t) {
1309
- let r = typeof this == "function" ? this : ue;
1438
+ let r = typeof this == "function" ? this : fe;
1310
1439
  return new r((o) => {
1311
- le(() => {
1440
+ pe(() => {
1312
1441
  if (!o.closed) {
1313
1442
  for (let s = 0; s < t.length; ++s)
1314
1443
  if (o.next(t[s]), o.closed) return;
@@ -1317,25 +1446,30 @@ let we = class ue {
1317
1446
  });
1318
1447
  });
1319
1448
  }
1320
- static get [Mt]() {
1449
+ static get [xt]() {
1321
1450
  return this;
1322
1451
  }
1323
1452
  };
1324
- he.Observable = we;
1325
- Object.defineProperty(we, Symbol("extensions"), {
1453
+ be.Observable = Se;
1454
+ Object.defineProperty(Se, Symbol("extensions"), {
1326
1455
  value: {
1327
- symbol: De,
1328
- hostReportError: X
1456
+ symbol: Le,
1457
+ hostReportError: te
1329
1458
  },
1330
1459
  configurable: !0
1331
1460
  });
1332
- var oo = he.Observable;
1333
- const so = /* @__PURE__ */ It(oo), { log__: io, err__: ao } = J("init-flows"), co = (e) => ({
1334
- // Stripe PR
1335
- stripePR: lo("stripePR", Fe.stripePR.init({ context: e }))
1336
- // 👉 Add initialization flows here
1337
- }), lo = (e, t) => {
1338
- const r = new so((o) => {
1461
+ var go = be.Observable;
1462
+ const ho = /* @__PURE__ */ Dt(go), { log__: wo, err__: Eo } = Y("init-flows"), Co = () => ("ojs_init_results" in window || (window.ojs_init_results = {}), window.ojs_init_results), bo = (e, t) => {
1463
+ const r = { context: e, flowCallbacks: t };
1464
+ return {
1465
+ // Stripe PR
1466
+ stripePR: at("stripePR", ie.stripePR.init(r)),
1467
+ // Stripe Link
1468
+ stripeLink: at("stripeLink", ie.stripeLink.init(r))
1469
+ // 👉 Add initialization flows here
1470
+ };
1471
+ }, at = (e, t) => {
1472
+ const r = new ho((o) => {
1339
1473
  o.next({ status: "loading" }), t.then((s) => {
1340
1474
  o.next({ status: "loaded", result: s });
1341
1475
  }).catch((s) => {
@@ -1344,28 +1478,28 @@ const so = /* @__PURE__ */ It(oo), { log__: io, err__: ao } = J("init-flows"), c
1344
1478
  });
1345
1479
  return r.subscribe({
1346
1480
  next: (o) => {
1347
- io(`${e} flow result`, o);
1481
+ wo(`${e} flow result`, o), Co()[e] = o;
1348
1482
  },
1349
1483
  error: (o) => {
1350
- throw ao(`${e} flow initialization error:
1484
+ throw Eo(`${e} flow initialization error:
1351
1485
  ${JSON.stringify(o)}`), o;
1352
1486
  }
1353
1487
  }), r;
1354
- }, ce = {
1488
+ }, me = {
1355
1489
  isLoading: !0,
1356
1490
  isAvailable: !1,
1357
1491
  startFlow: async () => {
1358
1492
  }
1359
- }, rt = {
1493
+ }, ct = {
1360
1494
  isLoading: !1,
1361
1495
  isAvailable: !1,
1362
1496
  startFlow: async () => {
1363
1497
  }
1364
1498
  };
1365
- var $e = { exports: {} }, uo = rn;
1366
- function Nt(e, t, r) {
1499
+ var Ke = { exports: {} }, So = un;
1500
+ function qt(e, t, r) {
1367
1501
  var o = typeof t == "function";
1368
- uo.useEffect(function() {
1502
+ So.useEffect(function() {
1369
1503
  var s, i = !0, a = e(function() {
1370
1504
  return i;
1371
1505
  });
@@ -1376,62 +1510,62 @@ function Nt(e, t, r) {
1376
1510
  };
1377
1511
  }, o ? r : t);
1378
1512
  }
1379
- $e.exports = Nt;
1380
- $e.exports.useAsyncEffect = Nt;
1381
- var mo = $e.exports;
1382
- const ot = /* @__PURE__ */ It(mo);
1383
- function fo(e, t = 0) {
1384
- const r = re(!1), o = re(), s = re(e), i = Z(() => r.current, []), a = Z(() => {
1513
+ Ke.exports = qt;
1514
+ Ke.exports.useAsyncEffect = qt;
1515
+ var Po = Ke.exports;
1516
+ const lt = /* @__PURE__ */ Dt(Po);
1517
+ function vo(e, t = 0) {
1518
+ const r = se(!1), o = se(), s = se(e), i = J(() => r.current, []), a = J(() => {
1385
1519
  r.current = !1, o.current && clearTimeout(o.current), o.current = setTimeout(() => {
1386
1520
  r.current = !0, s.current();
1387
1521
  }, t);
1388
- }, [t]), c = Z(() => {
1522
+ }, [t]), c = J(() => {
1389
1523
  r.current = null, o.current && clearTimeout(o.current);
1390
1524
  }, []);
1391
- return q(() => {
1525
+ return z(() => {
1392
1526
  s.current = e;
1393
- }, [e]), q(() => (a(), c), [t]), [i, c, a];
1527
+ }, [e]), z(() => (a(), c), [t]), [i, c, a];
1394
1528
  }
1395
- function po(e, t = 0, r = []) {
1396
- const [o, s, i] = fo(e, t);
1397
- return q(i, r), [o, s];
1529
+ function ko(e, t = 0, r = []) {
1530
+ const [o, s, i] = vo(e, t);
1531
+ return z(i, r), [o, s];
1398
1532
  }
1399
- const yo = (e, t, r, o) => {
1400
- const [s, i] = w(""), [a, c] = w(""), [l, d] = w(null), [m, E] = w(!1), [g, _] = w(null);
1401
- return ot(async () => {
1533
+ const Oo = (e, t, r, o) => {
1534
+ const [s, i] = C(""), [a, c] = C(""), [l, u] = C(null), [d, f] = C(!1), [m, _] = C(null);
1535
+ return lt(async () => {
1402
1536
  if (!o || !e)
1403
1537
  return;
1404
- const h = await Or(o, C.PROMOTION_CODE);
1405
- h == null || h.addEventListener("input", () => {
1406
- E(!0), _(null), i(h.value);
1538
+ const E = await jr(o, y.PROMOTION_CODE);
1539
+ E == null || E.addEventListener("input", () => {
1540
+ f(!0), _(null), i(E.value);
1407
1541
  });
1408
- }, [!!o, e]), po(
1542
+ }, [!!o, e]), ko(
1409
1543
  () => {
1410
1544
  e && c(s);
1411
1545
  },
1412
1546
  1e3,
1413
1547
  [s, e]
1414
- ), ot(
1415
- async (h) => {
1548
+ ), lt(
1549
+ async (E) => {
1416
1550
  try {
1417
1551
  if (!t || !r || !e)
1418
1552
  return;
1419
- const L = (await se(t)).mode === "setup", Ce = await vt(t, r, L, a);
1420
- h() && (_(null), d(Ce));
1421
- } catch (I) {
1422
- h() && _(pe(I));
1553
+ const ve = (await B(t)).mode === "setup", U = await Ue(t, r, ve, a);
1554
+ E() && (_(null), u(U));
1555
+ } catch (M) {
1556
+ E() && _(we(M));
1423
1557
  } finally {
1424
- h() && E(!1);
1558
+ E() && f(!1);
1425
1559
  }
1426
1560
  },
1427
1561
  [!t, !r, a, e]
1428
1562
  ), {
1429
1563
  amount: l,
1430
- isLoading: m,
1431
- error: g
1564
+ isLoading: d,
1565
+ error: m
1432
1566
  };
1433
- }, xt = (e = {}) => {
1434
- const [t, r] = w(e), o = Q(
1567
+ }, zt = (e = {}) => {
1568
+ const [t, r] = C(e), o = ee(
1435
1569
  () => ({
1436
1570
  set: (i, a) => {
1437
1571
  r((c) => ({
@@ -1453,12 +1587,12 @@ const yo = (e, t, r, o) => {
1453
1587
  // eslint-disable-next-line react-hooks/exhaustive-deps
1454
1588
  [r]
1455
1589
  ), s = {
1456
- get: Z((i) => t[i], [t]),
1590
+ get: J((i) => t[i], [t]),
1457
1591
  ...o
1458
1592
  };
1459
1593
  return [t, s];
1460
- }, _o = () => {
1461
- const [e, t] = xt({
1594
+ }, Ro = () => {
1595
+ const [e, t] = zt({
1462
1596
  card: void 0,
1463
1597
  "card-cvc": void 0,
1464
1598
  "card-expiry": void 0,
@@ -1468,17 +1602,17 @@ const yo = (e, t, r, o) => {
1468
1602
  cdeConns: e,
1469
1603
  anyCdeConn: r,
1470
1604
  connectToCdeIframe: async (o, s) => {
1471
- t.set(o, await tr(s));
1605
+ t.set(o, await cr(s));
1472
1606
  }
1473
1607
  };
1474
- }, go = (e) => {
1475
- const t = e.replace("ojs-", "").replace("-element", ""), r = gn.safeParse(t);
1608
+ }, Io = (e) => {
1609
+ const t = e.replace("ojs-", "").replace("-element", ""), r = Sn.safeParse(t);
1476
1610
  if (!r.success)
1477
1611
  throw new Error(
1478
1612
  `Invalid element id: ${e}, it needs to be in the format "ojs-{elementType}-element" (e.g. "ojs-card-number-element")`
1479
1613
  );
1480
1614
  return r.data;
1481
- }, Po = (e) => {
1615
+ }, Lo = (e) => {
1482
1616
  const {
1483
1617
  children: t,
1484
1618
  checkoutSecureToken: r,
@@ -1488,79 +1622,80 @@ const yo = (e, t, r, o) => {
1488
1622
  onChange: a,
1489
1623
  onLoad: c,
1490
1624
  onLoadError: l,
1491
- onValidationError: d,
1492
- onCheckoutStarted: m,
1493
- onCheckoutSuccess: E,
1494
- onCheckoutError: g,
1625
+ onValidationError: u,
1626
+ onCheckoutStarted: d,
1627
+ onCheckoutSuccess: f,
1628
+ onCheckoutError: m,
1495
1629
  onSetupPaymentMethodSuccess: _,
1496
- baseUrl: h,
1497
- enableDynamicPreviews: I
1498
- } = e, L = h ?? cn, [Ce, Lt] = w(void 0), [Ue, $t] = w([]), [Ut, qt] = w("1px"), [be, zt] = w(!1), [D, Se] = w(void 0), [qe, K] = w(!1), [Y, Ht] = w([]), [ee, Vt] = w({}), [ze, ie] = w(0), [He, z] = w(!1), [$, Kt] = w(void 0), [Ve, Yt] = w(void 0), [Ke, Zt] = w(void 0), [U, Jt] = w(void 0), [Pe] = w(void 0), W = Q(() => `opjs-form-${st()}`, []), j = re(null), { cdeConns: Ye, anyCdeConn: B, connectToCdeIframe: Wt } = _o(), [Bt, Gt] = w(null), [Ze, G] = xt({
1499
- apple_pay: ce,
1500
- google_pay: ce
1630
+ baseUrl: E,
1631
+ enableDynamicPreviews: M,
1632
+ customInitParams: ve
1633
+ } = e, U = E ?? fn, [Ht, Kt] = C(void 0), [Ve, Vt] = C([]), [Yt, Zt] = C("1px"), [ke, Wt] = C(!1), [L, Oe] = C(void 0), [Ye, Z] = C(!1), [W, Jt] = C([]), [ne, Bt] = C({}), [Ze, ue] = C(0), [We, H] = C(!1), [$, Gt] = C(void 0), [Je, Qt] = C(void 0), [Be, Xt] = C(void 0), [q, en] = C(void 0), [Re] = C(void 0), G = ee(() => `opjs-form-${ut()}`, []), j = se(null), { cdeConns: Ge, anyCdeConn: Q, connectToCdeIframe: tn } = Ro(), [nn, rn] = C(null), [Qe, X] = zt({
1634
+ apple_pay: me,
1635
+ google_pay: me
1501
1636
  });
1502
- q(() => {
1503
- const u = { version: "0.1.7", release_version: "0.1.7" };
1504
- window.ojs_version = u;
1637
+ z(() => {
1638
+ const p = { version: "0.1.8", release_version: "0.1.8" };
1639
+ window.ojs_version = p;
1505
1640
  }, []);
1506
- const Qt = yo(
1507
- I ?? !1,
1508
- B,
1641
+ const on = Oo(
1642
+ M ?? !1,
1643
+ Q,
1509
1644
  r,
1510
1645
  j.current
1511
- ), ve = Z(
1512
- (u) => {
1513
- if (u.origin !== L || !u.source) return;
1514
- const M = u.source;
1515
- if (!jr(u.data))
1646
+ ), Ie = J(
1647
+ (p) => {
1648
+ if (p.origin !== U || !p.source) return;
1649
+ const F = p.source;
1650
+ if (!xr(p.data))
1516
1651
  return;
1517
- const A = JSON.parse(u.data), p = Qn(A), H = p.elementId;
1518
- if (p.formId !== W || !H || p.nonce in Ue)
1652
+ const T = JSON.parse(p.data), h = sr(T), K = h.elementId;
1653
+ if (h.formId !== G || !K || h.nonce in Ve)
1519
1654
  return;
1520
- $t((k) => [...k, p.nonce]);
1521
- const y = p.payload, R = y.type;
1522
- if (R === f.enum.LAYOUT) {
1523
- const k = y.height ? `${y.height}px` : "100%";
1524
- qt(k);
1525
- } else if (R === f.enum.FOCUS && s)
1526
- s(p.elementId);
1527
- else if (R === f.enum.BLUR && i)
1528
- i(p.elementId);
1529
- else if (R === f.enum.CHANGE && a)
1530
- a(p.elementId);
1531
- else if (R === f.enum.LOADED) {
1532
- const k = Y.find((S) => S.contentWindow === M);
1533
- if (K(!1), !k)
1655
+ Vt((R) => [...R, h.nonce]);
1656
+ const w = h.payload, O = w.type;
1657
+ if (O === g.enum.LAYOUT) {
1658
+ const R = w.height ? `${w.height}px` : "100%";
1659
+ Zt(R);
1660
+ } else if (O === g.enum.FOCUS && s)
1661
+ s(h.elementId);
1662
+ else if (O === g.enum.BLUR && i)
1663
+ i(h.elementId);
1664
+ else if (O === g.enum.CHANGE && a)
1665
+ a(h.elementId);
1666
+ else if (O === g.enum.LOADED) {
1667
+ const R = W.find((S) => S.contentWindow === F);
1668
+ if (Z(!1), !R)
1534
1669
  return;
1535
- Vt((S) => ({ ...S, [H]: M })), Zt(y.totalAmountAtoms), Yt(y.currency), Jt(y.checkoutPaymentMethods), $ || Kt(y.sessionId);
1536
- } else if (R === f.enum.TOKENIZE_STARTED)
1537
- K(!0);
1538
- else if (R === f.enum.CHECKOUT_STARTED)
1539
- m && m();
1540
- else if (R === f.enum.PAYMENT_FLOW_STARTED) {
1541
- if (!D)
1670
+ Bt((S) => ({ ...S, [K]: F })), Xt(w.totalAmountAtoms), Qt(w.currency), en(w.checkoutPaymentMethods), $ || Gt(w.sessionId);
1671
+ } else if (O === g.enum.TOKENIZE_STARTED)
1672
+ Z(!0);
1673
+ else if (O === g.enum.CHECKOUT_STARTED)
1674
+ d && d();
1675
+ else if (O === g.enum.PAYMENT_FLOW_STARTED) {
1676
+ if (!L)
1542
1677
  throw new Error("extraData not populated");
1543
- if (!B)
1678
+ if (!Q)
1544
1679
  throw new Error("Not connected to CDE");
1545
1680
  (async () => {
1546
- const S = y.nextActionMetadata.type;
1681
+ const S = w.nextActionMetadata.type;
1547
1682
  if (S !== void 0) if (S === "stripe_3ds")
1548
- await Wn(y);
1683
+ await nr(w);
1549
1684
  else if (S === "stripe_payment_request") {
1550
- if (!Pe)
1685
+ if (!Re)
1551
1686
  throw new Error("Stripe PM not set");
1552
- await Zn(y, Pe);
1687
+ await er(w, Re);
1553
1688
  } else
1554
1689
  throw new Error(`Unknown next action type: ${S}`);
1555
- const F = await se(B);
1556
- if (F.mode === "setup") {
1557
- const { payment_methods: N } = await xe(B, {
1558
- secure_token: F.token,
1559
- existing_cc_pm_id: D.existingCCPMId
1690
+ const N = await B(Q);
1691
+ if (N.mode === "setup") {
1692
+ const { payment_methods: x } = await Ce(Q, {
1693
+ secure_token: N.token,
1694
+ existing_cc_pm_id: L.existingCCPMId
1560
1695
  });
1561
- if (N.length !== 1)
1562
- throw new Error(`Expected exactly one payment method, got ${N.length}`);
1563
- return K(!1), ie(0), z(!1), _ && _(N[0].id), {
1696
+ if (x.length !== 1)
1697
+ throw new Error(`Expected exactly one payment method, got ${x.length}`);
1698
+ return Z(!1), ue(0), H(!1), _ && _(x[0].id), {
1564
1699
  proceedToCheckout: !1
1565
1700
  };
1566
1701
  } else
@@ -1568,184 +1703,185 @@ const yo = (e, t, r, o) => {
1568
1703
  proceedToCheckout: !0
1569
1704
  };
1570
1705
  })().then(({ proceedToCheckout: S }) => {
1571
- var N;
1706
+ var x;
1572
1707
  if (!S)
1573
1708
  return;
1574
- let F;
1575
- if (D.checkoutPaymentMethod.provider === "credit_card" && (F = (N = y.startPFMetadata) == null ? void 0 : N.cc_pm_id, !F))
1709
+ let N;
1710
+ if (L.checkoutPaymentMethod.provider === "credit_card" && (N = (x = w.startPFMetadata) == null ? void 0 : x.cc_pm_id, !N))
1576
1711
  throw new Error("CC PM ID not found");
1577
- Te(
1578
- M,
1579
- W,
1580
- H,
1581
- { ...D, type: "CHECKOUT", doNotUseLegacyCCFlow: !0, existingCCPMId: F },
1582
- L
1583
- ), z(!0), Se(void 0), m && m();
1712
+ Fe(
1713
+ F,
1714
+ G,
1715
+ K,
1716
+ { ...L, type: "CHECKOUT", doNotUseLegacyCCFlow: !0, existingCCPMId: N },
1717
+ U
1718
+ ), H(!0), Oe(void 0), d && d();
1584
1719
  }).catch((S) => {
1585
- const F = pe(S);
1586
- K(!1), z(!1), g && g(F);
1720
+ const N = we(S);
1721
+ Z(!1), H(!1), m && m(N);
1587
1722
  });
1588
- } else if (R === f.enum.TOKENIZE_SUCCESS && D) {
1589
- const k = ze + 1, S = k === Object.keys(ee).length;
1590
- !He && (S || y.isReadyForCheckout) ? (Te(M, W, H, D, L), z(!0), Se(void 0)) : ie(k);
1591
- } else if (R === f.enum.CHECKOUT_SUCCESS)
1592
- K(!1), ie(0), z(!1), E && E(y.invoiceUrls, y.subscriptionIds, y.customerId);
1593
- else if (R === f.enum.SETUP_PAYMENT_METHOD_SUCCESS)
1594
- K(!1), ie(0), z(!1), _ && _(y.paymentMethodId);
1595
- else if (R === f.enum.LOAD_ERROR)
1596
- l && l(y.message);
1597
- else if (R === f.enum.VALIDATION_ERROR) {
1598
- const k = D == null ? void 0 : D.checkoutPaymentMethod.provider;
1599
- (k === "credit_card" || k === void 0) && d && d(y.elementType, y.errors, H);
1600
- } else if (R === f.enum.TOKENIZE_ERROR || R === f.enum.CHECKOUT_ERROR)
1601
- if (y.message === "3DS_REQUIRED") {
1602
- const k = U == null ? void 0 : U.find((S) => S.provider === "credit_card");
1603
- if (!$ || !j.current || !d || !k) return;
1604
- for (const [S, F] of Object.entries(ee)) {
1605
- if (!F) continue;
1606
- const N = Gn(
1607
- f.enum.START_PAYMENT_FLOW,
1723
+ } else if (O === g.enum.TOKENIZE_SUCCESS && L) {
1724
+ const R = Ze + 1, S = R === Object.keys(ne).length;
1725
+ !We && (S || w.isReadyForCheckout) ? (Fe(F, G, K, L, U), H(!0), Oe(void 0)) : ue(R);
1726
+ } else if (O === g.enum.CHECKOUT_SUCCESS)
1727
+ Z(!1), ue(0), H(!1), f && f(w.invoiceUrls, w.subscriptionIds, w.customerId);
1728
+ else if (O === g.enum.SETUP_PAYMENT_METHOD_SUCCESS)
1729
+ Z(!1), ue(0), H(!1), _ && _(w.paymentMethodId);
1730
+ else if (O === g.enum.LOAD_ERROR)
1731
+ l && l(w.message);
1732
+ else if (O === g.enum.VALIDATION_ERROR) {
1733
+ const R = L == null ? void 0 : L.checkoutPaymentMethod.provider;
1734
+ (R === "credit_card" || R === void 0) && u && u(w.elementType, w.errors, K);
1735
+ } else if (O === g.enum.TOKENIZE_ERROR || O === g.enum.CHECKOUT_ERROR)
1736
+ if (w.message === "3DS_REQUIRED") {
1737
+ const R = q == null ? void 0 : q.find((S) => S.provider === "credit_card");
1738
+ if (!$ || !j.current || !u || !R) return;
1739
+ for (const [S, N] of Object.entries(ne)) {
1740
+ if (!N) continue;
1741
+ const x = or(
1742
+ g.enum.START_PAYMENT_FLOW,
1608
1743
  $,
1609
1744
  j.current,
1610
- d,
1745
+ u,
1611
1746
  // Only stripe supports frontend 3DS right now,
1612
1747
  // so we pass processor_name: 'stripe' to tell delegator to only use stripe
1613
- { ...k, processor_name: "stripe" },
1748
+ { ...R, processor_name: "stripe" },
1614
1749
  !1
1615
1750
  );
1616
- if (N) {
1617
- z(!0), Se(N), Te(F, W, S, N, L);
1751
+ if (x) {
1752
+ H(!0), Oe(x), Fe(N, G, S, x, U);
1618
1753
  break;
1619
1754
  }
1620
1755
  }
1621
1756
  } else
1622
- K(!1), z(!1), g && g(y.message);
1757
+ Z(!1), H(!1), m && m(w.message);
1623
1758
  },
1624
1759
  [
1625
- W,
1760
+ G,
1626
1761
  $,
1627
- Ue,
1628
- D,
1629
- Y,
1630
- ee,
1631
- ze,
1632
- He,
1762
+ Ve,
1763
+ L,
1764
+ W,
1765
+ ne,
1766
+ Ze,
1767
+ We,
1633
1768
  i,
1634
1769
  a,
1635
1770
  s,
1636
1771
  l,
1637
- m,
1638
- E,
1639
- _,
1640
- g,
1641
1772
  d,
1642
- L,
1643
- Pe,
1773
+ f,
1774
+ _,
1775
+ m,
1776
+ u,
1644
1777
  U,
1645
- B
1778
+ Re,
1779
+ q,
1780
+ Q
1646
1781
  ]
1647
- ), Je = Q(() => {
1648
- const u = () => {
1782
+ ), Ae = ee(() => {
1783
+ const p = () => {
1649
1784
  };
1650
1785
  return {
1651
- onCheckoutError: te("onCheckoutError", g ?? u),
1652
- onCheckoutStarted: te("onCheckoutStarted", m ?? u),
1653
- onCheckoutSuccess: te("onCheckoutSuccess", E ?? u),
1654
- onSetupPaymentMethodSuccess: te("onSetupPaymentMethodSuccess", _ ?? u),
1655
- onValidationError: te("onValidationError", d ?? u)
1786
+ onCheckoutError: re("onCheckoutError", m ?? p),
1787
+ onCheckoutStarted: re("onCheckoutStarted", d ?? p),
1788
+ onCheckoutSuccess: re("onCheckoutSuccess", f ?? p),
1789
+ onSetupPaymentMethodSuccess: re("onSetupPaymentMethodSuccess", _ ?? p),
1790
+ onValidationError: re("onValidationError", u ?? p)
1656
1791
  };
1657
- }, [g, m, E, _, d]), Oe = () => {
1658
- if (!j.current || !$ || !U) return null;
1659
- const u = /* @__PURE__ */ new Map();
1660
- return Object.entries(Ye).forEach(([A, p]) => {
1661
- p && u.set(A, p);
1662
- }), u.size === 0 ? null : {
1792
+ }, [m, d, f, _, u]), Te = () => {
1793
+ if (!j.current || !$ || !q) return null;
1794
+ const p = /* @__PURE__ */ new Map();
1795
+ return Object.entries(Ge).forEach(([T, h]) => {
1796
+ h && p.set(T, h);
1797
+ }), p.size === 0 ? null : {
1663
1798
  formDiv: j.current,
1664
1799
  elementsSessionId: $,
1665
- checkoutPaymentMethods: U,
1666
- cdeConnections: u,
1667
- baseUrl: new URL(L).origin
1800
+ checkoutPaymentMethods: q,
1801
+ cdeConnections: p,
1802
+ customInitParams: ve ?? {},
1803
+ baseUrl: new URL(U).origin
1668
1804
  };
1669
- }, We = (u, M, A) => {
1670
- const p = Oe();
1671
- if (!(!p || !j.current))
1672
- return Fe.stripePR.run({
1673
- context: p,
1674
- checkoutPaymentMethod: nt(p.checkoutPaymentMethods, u),
1675
- nonCdeFormInputs: Me(j.current),
1676
- flowCallbacks: Je,
1677
- customParams: { provider: u, overridePaymentRequest: A == null ? void 0 : A.overridePaymentRequest },
1678
- initResult: M
1805
+ }, Xe = (p, F, T) => {
1806
+ const h = Te();
1807
+ if (!(!h || !j.current))
1808
+ return ie.stripePR.run({
1809
+ context: h,
1810
+ checkoutPaymentMethod: it(h.checkoutPaymentMethods, p),
1811
+ nonCdeFormInputs: ge(j.current),
1812
+ flowCallbacks: Ae,
1813
+ customParams: { provider: p, overridePaymentRequest: T == null ? void 0 : T.overridePaymentRequest },
1814
+ initResult: F
1679
1815
  });
1680
1816
  };
1681
- q(() => {
1682
- if (Bt !== null) return;
1683
- const u = Oe();
1684
- if (!u) return;
1685
- const M = co(u);
1686
- Gt(M), M.stripePR.subscribe((A) => {
1687
- if (A.status === "loading")
1688
- G.set("apple_pay", ce), G.set("google_pay", ce);
1689
- else if (A.status === "error")
1690
- G.set("apple_pay", rt), G.set("google_pay", rt);
1691
- else if (A.status === "loaded") {
1692
- const p = A.result, H = p.isAvailable && p.availableProviders.applePay, ke = p.isAvailable && p.availableProviders.googlePay;
1693
- G.set("apple_pay", {
1817
+ z(() => {
1818
+ if (nn !== null) return;
1819
+ const p = Te();
1820
+ if (!p) return;
1821
+ const F = bo(p, Ae);
1822
+ rn(F), F.stripePR.subscribe((T) => {
1823
+ if (T.status === "loading")
1824
+ X.set("apple_pay", me), X.set("google_pay", me);
1825
+ else if (T.status === "error")
1826
+ X.set("apple_pay", ct), X.set("google_pay", ct);
1827
+ else if (T.status === "loaded") {
1828
+ const h = T.result, K = h.isAvailable && h.availableProviders.applePay, je = h.isAvailable && h.availableProviders.googlePay;
1829
+ X.set("apple_pay", {
1694
1830
  isLoading: !1,
1695
- isAvailable: H,
1696
- startFlow: async (y) => H ? We("apple_pay", p, y) : void 0
1697
- }), G.set("google_pay", {
1831
+ isAvailable: K,
1832
+ startFlow: async (w) => K ? Xe("apple_pay", h, w) : void 0
1833
+ }), X.set("google_pay", {
1698
1834
  isLoading: !1,
1699
- isAvailable: ke,
1700
- startFlow: async (y) => ke ? We("google_pay", p, y) : void 0
1835
+ isAvailable: je,
1836
+ startFlow: async (w) => je ? Xe("google_pay", h, w) : void 0
1701
1837
  });
1702
1838
  }
1703
1839
  });
1704
- }, [j.current, $, U, Object.keys(Ye).length]);
1705
- const Xt = () => {
1706
- const u = Oe();
1707
- !j.current || !$ || !B || !U || !u || Fe.commonCC.run({
1708
- context: u,
1709
- checkoutPaymentMethod: nt(U, "credit_card"),
1710
- nonCdeFormInputs: Me(j.current),
1711
- flowCallbacks: Je,
1840
+ }, [j.current, $, q, Object.keys(Ge).length]);
1841
+ const sn = () => {
1842
+ const p = Te();
1843
+ !j.current || !$ || !Q || !q || !p || ie.commonCC.run({
1844
+ context: p,
1845
+ checkoutPaymentMethod: it(q, "credit_card"),
1846
+ nonCdeFormInputs: ge(j.current),
1847
+ flowCallbacks: Ae,
1712
1848
  customParams: void 0,
1713
1849
  // This flow requires no custom params
1714
1850
  initResult: void 0
1715
1851
  // This flow requires no initialization
1716
1852
  });
1717
- }, Re = Z(
1718
- (u) => {
1719
- qe && u.preventDefault();
1853
+ }, Me = J(
1854
+ (p) => {
1855
+ Ye && p.preventDefault();
1720
1856
  },
1721
- [qe]
1857
+ [Ye]
1722
1858
  );
1723
- q(() => {
1724
- if (be || !j.current) return;
1725
- Y.length > 0 && Y.length === Object.keys(ee).length && (zt(!0), c && c(Ke, Ve));
1726
- }, [Y, ee, be, c, Ke, Ve]), q(() => (Lt(window.location.origin), window.addEventListener("message", ve), window.addEventListener("beforeunload", Re), () => {
1727
- window.removeEventListener("beforeunload", Re), window.removeEventListener("message", ve);
1728
- }), [$, ve, Re]);
1729
- const en = Z(
1730
- async (u) => {
1731
- if (Y.find((p) => p.contentWindow === u.contentWindow)) return;
1732
- Ht((p) => [...p, u]);
1733
- const A = go(u.id);
1734
- await Wt(A, u);
1859
+ z(() => {
1860
+ if (ke || !j.current) return;
1861
+ W.length > 0 && W.length === Object.keys(ne).length && (Wt(!0), c && c(Be, Je));
1862
+ }, [W, ne, ke, c, Be, Je]), z(() => (Kt(window.location.origin), window.addEventListener("message", Ie), window.addEventListener("beforeunload", Me), () => {
1863
+ window.removeEventListener("beforeunload", Me), window.removeEventListener("message", Ie);
1864
+ }), [$, Ie, Me]);
1865
+ const an = J(
1866
+ async (p) => {
1867
+ if (W.find((h) => h.contentWindow === p.contentWindow)) return;
1868
+ Jt((h) => [...h, p]);
1869
+ const T = Io(p.id);
1870
+ await tn(T, p);
1735
1871
  },
1736
1872
  // eslint-disable-next-line react-hooks/exhaustive-deps
1737
- [Y]
1738
- ), tn = {
1739
- formId: W,
1740
- formHeight: Ut,
1741
- referer: Ce,
1873
+ [W]
1874
+ ), cn = {
1875
+ formId: G,
1876
+ formHeight: Yt,
1877
+ referer: Ht,
1742
1878
  checkoutSecureToken: r,
1743
- registerIframe: en,
1744
- baseUrl: L
1745
- }, nn = {
1746
- submit: Xt,
1747
- applePay: Ze.apple_pay,
1748
- googlePay: Ze.google_pay,
1879
+ registerIframe: an,
1880
+ baseUrl: U
1881
+ }, ln = {
1882
+ submit: sn,
1883
+ applePay: Qe.apple_pay,
1884
+ googlePay: Qe.google_pay,
1749
1885
  // stripeLink: {
1750
1886
  // TODO: uncomment if we need stripe elements later.
1751
1887
  // Better if we can make stripe link work in prod without elements.
@@ -1753,40 +1889,40 @@ const yo = (e, t, r, o) => {
1753
1889
  // authElement: stripeElements.isReady ? StripeLinkAuthElement : NoOpElement,
1754
1890
  // pr: paymentRequests.stripe_link,
1755
1891
  // },
1756
- loaded: be,
1757
- preview: Qt
1892
+ loaded: ke,
1893
+ preview: on
1758
1894
  };
1759
- return /* @__PURE__ */ V(at.Provider, { value: tn, children: /* @__PURE__ */ V("div", { className: o, ref: j, children: t(nn) }) });
1760
- }, Ee = (e) => {
1761
- const { subPath: t, styles: r } = e, { formId: o, referer: s, formHeight: i, checkoutSecureToken: a, registerIframe: c, baseUrl: l } = an(), [d, m] = w(!1), E = re(null), g = Q(() => r ? Bn(r) : "", [r]), _ = Q(() => ({
1895
+ return /* @__PURE__ */ V(mt.Provider, { value: cn, children: /* @__PURE__ */ V("div", { className: o, ref: j, children: t(ln) }) });
1896
+ }, Pe = (e) => {
1897
+ const { subPath: t, styles: r } = e, { formId: o, referer: s, formHeight: i, checkoutSecureToken: a, registerIframe: c, baseUrl: l } = pn(), [u, d] = C(!1), f = se(null), m = ee(() => r ? rr(r) : "", [r]), _ = ee(() => ({
1762
1898
  border: "none",
1763
1899
  width: "100%",
1764
1900
  height: i
1765
- }), [i]), h = Q(() => {
1901
+ }), [i]), E = ee(() => {
1766
1902
  if (!a || !s) return "";
1767
- const I = new URLSearchParams();
1768
- return I.append("referer", s), I.append("styles", g), I.append("formId", o), I.append("secureToken", a), I.toString();
1769
- }, [g, o, s, a]);
1770
- return q(() => m(!0), []), q(() => {
1771
- !E.current || !d || c(E.current);
1772
- }, [d]), a ? /* @__PURE__ */ V(
1903
+ const M = new URLSearchParams();
1904
+ return M.append("referer", s), M.append("styles", m), M.append("formId", o), M.append("secureToken", a), M.toString();
1905
+ }, [m, o, s, a]);
1906
+ return z(() => d(!0), []), z(() => {
1907
+ !f.current || !u || c(f.current);
1908
+ }, [u]), a ? /* @__PURE__ */ V(
1773
1909
  "iframe",
1774
1910
  {
1775
1911
  id: `ojs-${t}-element`,
1776
1912
  name: `${t}-element`,
1777
1913
  className: "ojs-iframe",
1778
- src: `${l}/app/v1/${t}-element/?${h}`,
1914
+ src: `${l}/app/v1/${t}-element/?${E}`,
1779
1915
  style: _,
1780
- ref: E
1916
+ ref: f
1781
1917
  }
1782
1918
  ) : /* @__PURE__ */ V("div", {});
1783
- }, vo = ({ styles: e }) => /* @__PURE__ */ V(Ee, { styles: e, subPath: "card-cvc" }), Oo = ({ styles: e }) => /* @__PURE__ */ V(Ee, { styles: e, subPath: "card" }), Ro = ({ styles: e }) => /* @__PURE__ */ V(Ee, { styles: e, subPath: "card-expiry" }), ko = ({ styles: e }) => /* @__PURE__ */ V(Ee, { styles: e, subPath: "card-number" });
1919
+ }, xo = ({ styles: e }) => /* @__PURE__ */ V(Pe, { styles: e, subPath: "card-cvc" }), Uo = ({ styles: e }) => /* @__PURE__ */ V(Pe, { styles: e, subPath: "card" }), $o = ({ styles: e }) => /* @__PURE__ */ V(Pe, { styles: e, subPath: "card-expiry" }), qo = ({ styles: e }) => /* @__PURE__ */ V(Pe, { styles: e, subPath: "card-number" });
1784
1920
  export {
1785
- vo as CardCvcElement,
1786
- Oo as CardElement,
1787
- Ro as CardExpiryElement,
1788
- ko as CardNumberElement,
1789
- Po as ElementsForm,
1790
- C as FieldName,
1791
- an as useOpenPayElements
1921
+ xo as CardCvcElement,
1922
+ Uo as CardElement,
1923
+ $o as CardExpiryElement,
1924
+ qo as CardNumberElement,
1925
+ Lo as ElementsForm,
1926
+ y as FieldName,
1927
+ pn as useOpenPayElements
1792
1928
  };