@getopenpay/openpay-js-react 0.1.6-alpha.7c15e03 → 0.1.7

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,7 +1,10 @@
1
- import xn, { createContext as $n, useContext as Nn, useRef as _e, useCallback as se, useEffect as G, useState as E, useMemo as ue } from "react";
2
- import { jsx as X } from "react/jsx-runtime";
3
- import { z as o } from "zod";
4
- const Nt = $n({
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";
2
+ import { jsx as V } from "react/jsx-runtime";
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({
5
8
  formId: "",
6
9
  formHeight: "",
7
10
  referer: void 0,
@@ -9,42 +12,42 @@ const Nt = $n({
9
12
  registerIframe: () => {
10
13
  },
11
14
  baseUrl: ""
12
- }), Ln = () => {
13
- const e = Nn(Nt);
15
+ }), an = () => {
16
+ const e = sn(at);
14
17
  if (!e)
15
18
  throw new Error("useOpenPayElements must be used within an OpenPayElementsProvider");
16
19
  return e;
17
- }, Un = "https://cde.getopenpay.com", Bn = o.object({
18
- type: o.string(),
19
- loc: o.array(o.string()),
20
- msg: o.string(),
21
- url: o.string()
22
- }), qn = o.array(Bn), zn = o.object({
23
- code: o.string(),
24
- message: o.string(),
25
- path: o.array(o.string())
26
- }), Vn = o.array(zn), Hn = {
20
+ }, cn = "https://cde.getopenpay.com", ln = n.object({
21
+ type: n.string(),
22
+ loc: n.array(n.string()),
23
+ msg: n.string(),
24
+ url: n.string()
25
+ }), un = n.array(ln), dn = n.object({
26
+ code: n.string(),
27
+ message: n.string(),
28
+ path: n.array(n.string())
29
+ }), mn = n.array(dn), fn = {
27
30
  "failed to fetch": "Connection error: please double check if you are connected to the internet, then try again"
28
- }, Xe = (e) => {
31
+ }, je = (e) => {
29
32
  const t = e.toLowerCase().trim();
30
- return Hn[t] ?? e;
31
- }, Kn = (e) => {
33
+ return fn[t] ?? e;
34
+ }, pn = (e) => {
32
35
  try {
33
36
  return typeof JSON.parse(e) == "object";
34
37
  } catch {
35
38
  return !1;
36
39
  }
37
- }, Yn = (e) => e.length === 1 ? Xe(e[0].msg) : `Please fix the following errors:
38
- ${e.map((n) => `• ${Xe(n.msg)}`).join(`
39
- `)}`, Gn = (e) => `Encountered the following errors:
40
- ${e.map((n) => `- ${n.path.join("/")}: ${n.message}`).join(`
41
- `)}`, De = (e) => {
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:
43
+ ${e.map((r) => `- ${r.path.join("/")}: ${r.message}`).join(`
44
+ `)}`, pe = (e) => {
42
45
  if (e instanceof Error)
43
- if (Kn(e.message)) {
46
+ if (pn(e.message)) {
44
47
  const t = JSON.parse(e.message);
45
- return qn.safeParse(t).success ? Yn(t) : Vn.safeParse(t).success ? Gn(t) : e.message;
48
+ return un.safeParse(t).success ? yn(t) : mn.safeParse(t).success ? _n(t) : e.message;
46
49
  } else
47
- return Xe(e.message);
50
+ return je(e.message);
48
51
  if (typeof e == "object")
49
52
  try {
50
53
  return JSON.stringify(e);
@@ -53,42 +56,42 @@ ${e.map((n) => `- ${n.path.join("/")}: ${n.message}`).join(`
53
56
  }
54
57
  else
55
58
  return e + "";
56
- }, ge = (e, t) => (...n) => {
59
+ }, te = (e, t) => (...r) => {
57
60
  try {
58
- return t(...n);
61
+ return t(...r);
59
62
  } catch {
60
63
  return;
61
64
  }
62
- }, T = o.string().trim().min(1, { message: "Cannot be blank" }), A = o.string().trim().optional(), Ie = (e) => o.nullable(e.optional());
63
- var U = /* @__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))(U || {});
64
- const Lt = o.nativeEnum(U);
65
- var Ut = /* @__PURE__ */ ((e) => (e.CARD_NUMBER = "cardNumber", e.CARD_EXPIRY = "cardExpiry", e.CARD_CVC = "cardCvc", e))(Ut || {});
66
- const Bt = o.nativeEnum(Ut), qt = o.union([Lt, Bt]);
67
- var zt = /* @__PURE__ */ ((e) => (e.CARD = "card", e.CARD_NUMBER = "card-number", e.CARD_EXPIRY = "card-expiry", e.CARD_CVC = "card-cvc", e))(zt || {});
68
- const Zn = o.nativeEnum(zt), xe = o.object({
69
- provider: o.string(),
70
- processor_name: Ie(o.string()),
71
- metadata: Ie(o.record(o.string(), o.any()))
72
- }), Wn = o.object({
73
- id: o.string()
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({
72
+ provider: n.string(),
73
+ processor_name: de(n.string()),
74
+ metadata: de(n.record(n.string(), n.any()))
75
+ }), hn = n.object({
76
+ id: n.string()
74
77
  });
75
- o.object({
76
- cardNumber: A,
77
- expiry: A,
78
- cvc: A
78
+ n.object({
79
+ cardNumber: v,
80
+ expiry: v,
81
+ cvc: v
79
82
  });
80
- o.object({
81
- backgroundColor: A,
82
- color: A,
83
- fontFamily: A,
84
- fontSize: A,
85
- fontWeight: A,
86
- margin: A,
87
- padding: A,
88
- letterSpacing: A,
89
- lineHeight: A
83
+ n.object({
84
+ backgroundColor: v,
85
+ color: v,
86
+ fontFamily: v,
87
+ fontSize: v,
88
+ fontWeight: v,
89
+ margin: v,
90
+ padding: v,
91
+ letterSpacing: v,
92
+ lineHeight: v
90
93
  });
91
- const h = o.enum([
94
+ const f = n.enum([
92
95
  // Element -> Form
93
96
  "LAYOUT",
94
97
  "LOADED",
@@ -109,163 +112,163 @@ const h = o.enum([
109
112
  "TOKENIZE",
110
113
  "CHECKOUT",
111
114
  "START_PAYMENT_FLOW"
112
- ]), Jn = h.extract(["TOKENIZE_STARTED", "CHECKOUT_STARTED"]), Qn = o.object({ type: Jn }), Xn = h.extract(["BLUR", "FOCUS", "CHANGE"]), er = o.object({
113
- type: Xn,
114
- elementType: Bt,
115
- errors: o.array(o.string()).optional()
116
- }), tr = h.extract(["LOAD_ERROR", "TOKENIZE_ERROR", "CHECKOUT_ERROR"]), nr = o.object({
117
- type: tr,
118
- message: T,
119
- headers: o.record(o.string(), o.string()).optional()
120
- }), rr = h.extract(["VALIDATION_ERROR"]), or = o.object({
121
- type: rr,
122
- elementType: qt,
123
- errors: o.array(o.string())
124
- }), sr = o.object({
125
- type: o.literal(h.enum.LAYOUT),
126
- height: T
127
- }), ir = o.object({
128
- type: o.literal(h.enum.LOADED),
129
- sessionId: T,
130
- totalAmountAtoms: o.number(),
131
- currency: A,
132
- checkoutPaymentMethods: o.array(xe)
133
- }), ar = o.object({
134
- type: o.literal(h.enum.PAYMENT_FLOW_STARTED),
135
- nextActionMetadata: o.record(o.string(), o.any()),
136
- paymentFlowMetadata: o.any().optional(),
137
- startPFMetadata: o.optional(o.record(o.string(), o.any()))
138
- }), cr = o.object({
139
- type: o.literal(h.enum.SETUP_PAYMENT_METHOD_SUCCESS),
140
- paymentMethodId: o.string()
141
- }), Ee = o.object({
142
- firstName: T,
143
- lastName: T,
144
- email: T,
145
- zipCode: T,
146
- country: T,
147
- promotionCode: A
148
- }), lr = o.object({
149
- email: T,
150
- zipCode: T,
151
- country: T,
152
- promotionCode: A
153
- }), ur = h.extract(["TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW"]), Vt = o.object({
154
- type: ur,
155
- sessionId: T,
156
- checkoutPaymentMethod: xe,
157
- paymentFlowMetadata: o.any().optional(),
158
- doNotUseLegacyCCFlow: o.boolean().optional(),
159
- existingCCPMId: A
160
- }).extend(Ee.shape), dr = o.object({
161
- type: o.literal(h.enum.TOKENIZE_SUCCESS),
162
- isReadyForCheckout: o.boolean()
163
- }), mr = o.object({
164
- type: o.literal(h.enum.CHECKOUT_SUCCESS),
165
- invoiceUrls: o.array(o.string()),
166
- subscriptionIds: o.array(o.string()),
167
- customerId: o.string()
168
- }), fr = o.discriminatedUnion("type", [
169
- Qn,
170
- er,
171
- nr,
172
- or,
173
- sr,
174
- ir,
175
- Vt,
176
- dr,
177
- mr,
178
- ar,
179
- cr
180
- ]), pr = o.object({
181
- payload: fr,
182
- nonce: T,
183
- formId: T,
184
- elementId: T
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,
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,
122
+ headers: n.record(n.string(), n.string()).optional()
123
+ }), vn = f.extract(["VALIDATION_ERROR"]), On = n.object({
124
+ type: vn,
125
+ elementType: dt,
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,
133
+ totalAmountAtoms: n.number(),
134
+ currency: v,
135
+ checkoutPaymentMethods: n.array(ye)
136
+ }), Tn = n.object({
137
+ type: n.literal(f.enum.PAYMENT_FLOW_STARTED),
138
+ nextActionMetadata: n.record(n.string(), n.any()),
139
+ paymentFlowMetadata: n.any().optional(),
140
+ startPFMetadata: n.optional(n.record(n.string(), n.any()))
141
+ }), An = n.object({
142
+ type: n.literal(f.enum.SETUP_PAYMENT_METHOD_SUCCESS),
143
+ paymentMethodId: n.string()
144
+ }), oe = n.object({
145
+ firstName: O,
146
+ lastName: O,
147
+ email: O,
148
+ zipCode: O,
149
+ country: O,
150
+ promotionCode: v
151
+ }), In = n.object({
152
+ email: O,
153
+ zipCode: O,
154
+ country: O,
155
+ promotionCode: v
156
+ }), jn = f.extract(["TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW"]), ft = n.object({
157
+ type: jn,
158
+ sessionId: O,
159
+ checkoutPaymentMethod: ye,
160
+ paymentFlowMetadata: n.any().optional(),
161
+ doNotUseLegacyCCFlow: n.boolean().optional(),
162
+ existingCCPMId: v
163
+ }).extend(oe.shape), Mn = n.object({
164
+ type: n.literal(f.enum.TOKENIZE_SUCCESS),
165
+ isReadyForCheckout: n.boolean()
166
+ }), Fn = n.object({
167
+ type: n.literal(f.enum.CHECKOUT_SUCCESS),
168
+ invoiceUrls: n.array(n.string()),
169
+ subscriptionIds: n.array(n.string()),
170
+ customerId: n.string()
171
+ }), Dn = n.discriminatedUnion("type", [
172
+ En,
173
+ bn,
174
+ Pn,
175
+ On,
176
+ Rn,
177
+ kn,
178
+ ft,
179
+ Mn,
180
+ Fn,
181
+ Tn,
182
+ An
183
+ ]), Nn = n.object({
184
+ payload: Dn,
185
+ nonce: O,
186
+ formId: O,
187
+ elementId: O
185
188
  });
186
- o.object({
187
- amountAtom: o.number(),
188
- currency: T
189
+ n.object({
190
+ amountAtom: n.number(),
191
+ currency: O
189
192
  });
190
- o.object({
191
- secure_token: o.string(),
192
- promotion_code: o.string().optional()
193
+ n.object({
194
+ secure_token: n.string(),
195
+ promotion_code: n.string().optional()
193
196
  });
194
- o.object({
195
- secure_token: o.string(),
196
- existing_cc_pm_id: Ie(o.string())
197
+ n.object({
198
+ secure_token: n.string(),
199
+ existing_cc_pm_id: de(n.string())
197
200
  });
198
- const yr = o.object({
199
- payment_methods: o.array(Wn)
200
- }), gr = o.object({
201
- elementType: o.string(),
202
- errors: o.array(o.string())
201
+ const xn = n.object({
202
+ payment_methods: n.array(hn)
203
+ }), Ln = n.object({
204
+ elementType: n.string(),
205
+ errors: n.array(n.string())
203
206
  });
204
- o.object({
205
- session_id: o.string()
207
+ n.object({
208
+ session_id: n.string()
206
209
  });
207
- const hr = o.object({
208
- success: o.literal(!1),
209
- error_type: o.literal("validation_error"),
210
- errors: o.array(gr)
211
- }), _r = o.discriminatedUnion("success", [
212
- o.object({ success: o.literal(!0) }),
213
- hr
210
+ const $n = n.object({
211
+ success: n.literal(!1),
212
+ error_type: n.literal("validation_error"),
213
+ errors: n.array(Ln)
214
+ }), Un = n.discriminatedUnion("success", [
215
+ n.object({ success: n.literal(!0) }),
216
+ $n
214
217
  ]);
215
- o.object({
216
- session_id: o.string(),
217
- checkout_payment_method: xe,
218
- non_cde_form_fields: Ee,
219
- do_not_use_legacy_cc_flow: o.boolean().optional(),
220
- existing_cc_pm_id: Ie(o.string())
218
+ n.object({
219
+ session_id: n.string(),
220
+ checkout_payment_method: ye,
221
+ non_cde_form_fields: oe,
222
+ do_not_use_legacy_cc_flow: n.boolean().optional(),
223
+ existing_cc_pm_id: de(n.string())
221
224
  });
222
- o.object({
223
- session_id: o.string(),
224
- checkout_payment_method: xe,
225
- non_cde_form_fields: Ee
225
+ n.object({
226
+ session_id: n.string(),
227
+ checkout_payment_method: ye,
228
+ non_cde_form_fields: oe
226
229
  });
227
- var Me = /* @__PURE__ */ ((e) => (e.SUCCESS = "success", e.FAILURE = "failure", e.CANCELLED = "cancelled", e))(Me || {});
228
- const wr = o.object({
229
- status: o.enum([
230
+ var me = /* @__PURE__ */ ((e) => (e.SUCCESS = "success", e.FAILURE = "failure", e.CANCELLED = "cancelled", e))(me || {});
231
+ const qn = n.object({
232
+ status: n.enum([
230
233
  "success",
231
234
  "failure",
232
235
  "cancelled"
233
236
  /* CANCELLED */
234
237
  ])
235
- }), br = o.object({
236
- type: o.string(),
237
- redirect_url: o.string(),
238
- initial_intent_id: o.string(),
239
- consent_id: o.string()
240
- }), Ht = (e) => {
238
+ }), zn = n.object({
239
+ type: n.string(),
240
+ redirect_url: n.string(),
241
+ initial_intent_id: n.string(),
242
+ consent_id: n.string()
243
+ }), pt = (e) => {
241
244
  const t = {};
242
- return Object.entries(e).forEach(([n, r]) => {
245
+ return Object.entries(e).forEach(([r, o]) => {
243
246
  try {
244
- const s = Lt.parse(n);
245
- Array.isArray(r) ? t[s] = r : Array.isArray(r._errors) && (t[s] = r._errors);
247
+ const s = ct.parse(r);
248
+ Array.isArray(o) ? t[s] = o : Array.isArray(o._errors) && (t[s] = o._errors);
246
249
  } catch {
247
250
  return;
248
251
  }
249
252
  }), t;
250
- }, Kt = o.object({
251
- stripe_pk: o.string(),
252
- client_secret: o.string(),
253
- stripe_pm_id: o.string()
254
- }), Er = o.object({
255
- type: o.string(),
256
- client_secret: o.string(),
257
- stripe_pk: o.string()
258
- }), Cr = {
253
+ }, yt = n.object({
254
+ stripe_pk: n.string(),
255
+ client_secret: n.string(),
256
+ stripe_pm_id: n.string()
257
+ }), Hn = n.object({
258
+ type: n.string(),
259
+ client_secret: n.string(),
260
+ stripe_pk: n.string()
261
+ }), Vn = {
259
262
  usd: "usd",
260
263
  brl: "brl"
261
- }, $e = async (e) => {
262
- for (let n = 0; n < 10; n++)
263
- bt() || await Yt(500);
264
- if (!bt())
264
+ }, _e = async (e) => {
265
+ for (let r = 0; r < 10; r++)
266
+ Be() || await _t(500);
267
+ if (!Be())
265
268
  throw new Error("Stripe JS not found.");
266
269
  return new Stripe(e);
267
- }, vr = async (e, t, n, r, s) => {
268
- const i = await $e(e), a = Cr[n.toLowerCase().trim()];
270
+ }, Kn = async (e, t, r, o, s) => {
271
+ const i = await _e(e), a = Vn[r.toLowerCase().trim()];
269
272
  return i.paymentRequest({
270
273
  // TODO: replace this with stripe account country as soon as we support it
271
274
  country: "US",
@@ -273,538 +276,273 @@ const wr = o.object({
273
276
  total: {
274
277
  label: "Total",
275
278
  amount: t,
276
- pending: r
279
+ pending: o
277
280
  },
278
281
  requestPayerName: !0,
279
282
  requestPayerEmail: !0,
280
283
  disableWallets: []
281
284
  });
282
- }, Yt = (e) => new Promise((t) => {
285
+ }, _t = (e) => new Promise((t) => {
283
286
  setTimeout(t, e);
284
- }), bt = () => "Stripe" in window, Sr = async (e) => new Promise((t, n) => {
287
+ }), Be = () => "Stripe" in window, Yn = async (e) => new Promise((t, r) => {
285
288
  try {
286
- e.on("paymentmethod", async (r) => {
287
- t(r);
289
+ e.on("paymentmethod", async (o) => {
290
+ t(o);
288
291
  }), e.on("cancel", () => {
289
- n(new Error("Payment cancelled, please click Submit again to pay"));
292
+ r(new Error("Payment cancelled, please click Submit again to pay"));
290
293
  });
291
- } catch (r) {
292
- n(r);
294
+ } catch (o) {
295
+ r(o);
293
296
  }
294
- }), Pr = async (e, t) => {
295
- const n = e.nextActionMetadata;
297
+ }), Zn = async (e, t) => {
298
+ const r = e.nextActionMetadata;
296
299
  if (!e.paymentFlowMetadata || !e.paymentFlowMetadata.stripePmId)
297
300
  throw new Error(`Invalid payment flow metadata format: ${JSON.stringify(e.paymentFlowMetadata)}`);
298
- if (!n.stripe_pk || !n.client_secret)
299
- throw new Error(`Invalid next action metadata format: ${JSON.stringify(n)}`);
301
+ if (!r.stripe_pk || !r.client_secret)
302
+ throw new Error(`Invalid next action metadata format: ${JSON.stringify(r)}`);
300
303
  if (t.paymentMethod.id !== e.paymentFlowMetadata.stripePmId)
301
304
  throw new Error(`PM ID mismatch: ${t.paymentMethod.id} != ${e.paymentFlowMetadata.stripePmId}`);
302
- const s = await (await $e(n.stripe_pk)).confirmCardSetup(n.client_secret, {
305
+ const s = await (await _e(r.stripe_pk)).confirmCardSetup(r.client_secret, {
303
306
  payment_method: e.paymentFlowMetadata.stripePmId
304
307
  });
305
308
  if (s.error)
306
309
  throw t.complete("fail"), new Error(`Payment failed: ${s.error.message ?? "unknown"}`);
307
310
  t.complete("success");
308
- }, Rr = async (e, t) => {
311
+ }, Jn = async (e, t) => {
309
312
  if (!e.stripe_pk || !e.client_secret)
310
313
  throw new Error(`Invalid next action metadata format: ${JSON.stringify(e)}`);
311
- const r = await (await $e(e.stripe_pk)).confirmCardSetup(e.client_secret, {
314
+ const o = await (await _e(e.stripe_pk)).confirmCardSetup(e.client_secret, {
312
315
  payment_method: t.paymentMethod.id
313
316
  });
314
- if (r.error)
315
- throw t.complete("fail"), new Error(`Payment failed: ${r.error.message ?? "unknown"}`);
316
- t.complete("success");
317
- }, Or = async (e) => {
318
- const t = Kt.parse(e.nextActionMetadata);
319
- await Gt(t);
320
- }, Gt = async (e) => {
317
+ if (o.error)
318
+ throw t.complete("fail"), new Error(`Payment failed: ${o.error.message ?? "unknown"}`);
319
+ return t.complete("success"), o;
320
+ }, Wn = async (e) => {
321
+ const t = yt.parse(e.nextActionMetadata);
322
+ await gt(t);
323
+ }, gt = async (e) => {
321
324
  var s, i, a, c;
322
- const n = await (await $e(e.stripe_pk)).confirmCardSetup(e.client_secret, {
325
+ const r = await (await _e(e.stripe_pk)).confirmCardSetup(e.client_secret, {
323
326
  payment_method: e.stripe_pm_id
324
- }), r = (s = n.setupIntent) == null ? void 0 : s.status;
325
- if (r !== "succeeded") throw r === "canceled" ? new Error("Payment cancelled, please click Submit again to pay") : new Error(
326
- `${((i = n.error) == null ? void 0 : i.message) ?? ((c = (a = n.setupIntent) == null ? void 0 : a.last_setup_error) == null ? void 0 : c.message) ?? "Payment failed, please click submit again to pay."}`
327
+ }), o = (s = r.setupIntent) == null ? void 0 : s.status;
328
+ if (o !== "succeeded") throw o === "canceled" ? new Error("Payment cancelled, please click Submit again to pay") : new Error(
329
+ `${((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."}`
327
330
  );
328
- }, kr = (e) => JSON.stringify(e);
329
- var O = [];
330
- for (var Ge = 0; Ge < 256; ++Ge)
331
- O.push((Ge + 256).toString(16).slice(1));
332
- function Ar(e, t = 0) {
333
- return (O[e[t + 0]] + O[e[t + 1]] + O[e[t + 2]] + O[e[t + 3]] + "-" + O[e[t + 4]] + O[e[t + 5]] + "-" + O[e[t + 6]] + O[e[t + 7]] + "-" + O[e[t + 8]] + O[e[t + 9]] + "-" + O[e[t + 10]] + O[e[t + 11]] + O[e[t + 12]] + O[e[t + 13]] + O[e[t + 14]] + O[e[t + 15]]).toLowerCase();
334
- }
335
- var Pe, Tr = new Uint8Array(16);
336
- function Ir() {
337
- if (!Pe && (Pe = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Pe))
338
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
339
- return Pe(Tr);
340
- }
341
- var Mr = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
342
- const Et = {
343
- randomUUID: Mr
344
- };
345
- function Zt(e, t, n) {
346
- if (Et.randomUUID && !t && !e)
347
- return Et.randomUUID();
348
- e = e || {};
349
- var r = e.random || (e.rng || Ir)();
350
- return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Ar(r);
351
- }
352
- const et = (e, t) => Array.from(e.querySelectorAll("[data-opid]") ?? []).reduce((s, i) => {
331
+ }, Bn = (e) => JSON.stringify(e), Me = (e, t) => Array.from(e.querySelectorAll("[data-opid]") ?? []).reduce((s, i) => {
353
332
  const a = i.getAttribute("data-opid");
354
333
  return a ? { ...s, [a]: i.value } : s;
355
- }, t ?? {}), jr = (e, t, n, r, s, i, a) => {
356
- const c = et(n, {
334
+ }, t ?? {}), Gn = (e, t, r, o, s, i, a) => {
335
+ const c = Me(r, {
357
336
  type: e,
358
337
  sessionId: t,
359
338
  checkoutPaymentMethod: s,
360
339
  paymentFlowMetadata: a,
361
340
  doNotUseLegacyCCFlow: i
362
341
  });
363
- (s.provider === "apple_pay" || s.provider === "google_pay" || s.provider === "stripe_link") && (c[U.ZIP_CODE] || (c[U.ZIP_CODE] = "00000"));
364
- const d = Vt.safeParse(c);
365
- if (d.success)
366
- return d.data;
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);
344
+ if (l.success)
345
+ return l.data;
367
346
  {
368
- const l = d.error.format(), u = Ht(l);
369
- for (const [y, f] of Object.entries(u))
370
- r(y, f, y);
347
+ const d = l.error.format(), m = pt(d);
348
+ for (const [E, g] of Object.entries(m))
349
+ o(E, g, E);
371
350
  return null;
372
351
  }
373
- }, Fr = (e) => {
352
+ }, Qn = (e) => {
374
353
  try {
375
- return pr.parse(e);
354
+ return Nn.parse(e);
376
355
  } catch (t) {
377
356
  throw t;
378
357
  }
379
- }, Ze = (e, t, n, r, s) => {
358
+ }, Te = (e, t, r, o, s) => {
380
359
  const i = {
381
- payload: r,
382
- nonce: Zt(),
360
+ payload: o,
361
+ nonce: st(),
383
362
  formId: t,
384
- elementId: n
363
+ elementId: r
385
364
  };
386
365
  e.postMessage(JSON.stringify(i), s);
387
- };
388
- var V;
389
- (function(e) {
390
- e.Call = "call", e.Reply = "reply", e.Syn = "syn", e.SynAck = "synAck", e.Ack = "ack";
391
- })(V || (V = {}));
392
- var oe;
393
- (function(e) {
394
- e.Fulfilled = "fulfilled", e.Rejected = "rejected";
395
- })(oe || (oe = {}));
396
- var we;
397
- (function(e) {
398
- e.ConnectionDestroyed = "ConnectionDestroyed", e.ConnectionTimeout = "ConnectionTimeout", e.NoIframeSrc = "NoIframeSrc";
399
- })(we || (we = {}));
400
- var tt;
401
- (function(e) {
402
- e.DataCloneError = "DataCloneError";
403
- })(tt || (tt = {}));
404
- var ee;
405
- (function(e) {
406
- e.Message = "message";
407
- })(ee || (ee = {}));
408
- const Dr = (e, t) => {
409
- const n = [];
410
- let r = !1;
411
- return {
412
- destroy(s) {
413
- r || (r = !0, t(`${e}: Destroying connection`), n.forEach((i) => {
414
- i(s);
415
- }));
416
- },
417
- onDestroy(s) {
418
- r ? s() : n.push(s);
419
- }
420
- };
421
- }, xr = (e) => (...t) => {
422
- }, $r = {
423
- "http:": "80",
424
- "https:": "443"
425
- }, Nr = /^(https?:)?\/\/([^/:]+)?(:(\d+))?/, Lr = ["file:", "data:"], Ur = (e) => {
426
- if (e && Lr.find((c) => e.startsWith(c)))
427
- return "null";
428
- const t = document.location, n = Nr.exec(e);
429
- let r, s, i;
430
- n ? (r = n[1] ? n[1] : t.protocol, s = n[2], i = n[4]) : (r = t.protocol, s = t.hostname, i = t.port);
431
- const a = i && i !== $r[r] ? `:${i}` : "";
432
- return `${r}//${s}${a}`;
433
- }, Ct = ({ name: e, message: t, stack: n }) => ({
434
- name: e,
435
- message: t,
436
- stack: n
437
- }), Br = (e) => {
438
- const t = new Error();
439
- return Object.keys(e).forEach((n) => t[n] = e[n]), t;
440
- }, qr = (e, t, n) => {
441
- const { localName: r, local: s, remote: i, originForSending: a, originForReceiving: c } = e;
442
- let d = !1;
443
- const l = (u) => {
444
- if (u.source !== i || u.data.penpal !== V.Call)
445
- return;
446
- if (c !== "*" && u.origin !== c) {
447
- n(`${r} received message from origin ${u.origin} which did not match expected origin ${c}`);
448
- return;
449
- }
450
- const y = u.data, { methodName: f, args: m, id: g } = y;
451
- n(`${r}: Received ${f}() call`);
452
- const v = (C) => (x) => {
453
- if (n(`${r}: Sending ${f}() reply`), d) {
454
- n(`${r}: Unable to send ${f}() reply due to destroyed connection`);
455
- return;
456
- }
457
- const $ = {
458
- penpal: V.Reply,
459
- id: g,
460
- resolution: C,
461
- returnValue: x
462
- };
463
- C === oe.Rejected && x instanceof Error && ($.returnValue = Ct(x), $.returnValueIsError = !0);
464
- try {
465
- i.postMessage($, a);
466
- } catch (S) {
467
- if (S.name === tt.DataCloneError) {
468
- const Z = {
469
- penpal: V.Reply,
470
- id: g,
471
- resolution: oe.Rejected,
472
- returnValue: Ct(S),
473
- returnValueIsError: !0
474
- };
475
- i.postMessage(Z, a);
476
- }
477
- throw S;
478
- }
479
- };
480
- new Promise((C) => C(t[f].apply(t, m))).then(v(oe.Fulfilled), v(oe.Rejected));
481
- };
482
- return s.addEventListener(ee.Message, l), () => {
483
- d = !0, s.removeEventListener(ee.Message, l);
484
- };
485
- };
486
- let zr = 0;
487
- const Vr = () => ++zr, Wt = ".", Jt = (e) => e ? e.split(Wt) : [], Hr = (e) => e.join(Wt), Kr = (e, t) => {
488
- const n = Jt(t || "");
489
- return n.push(e), Hr(n);
490
- }, Yr = (e, t, n) => {
491
- const r = Jt(t);
492
- return r.reduce((s, i, a) => (typeof s[i] > "u" && (s[i] = {}), a === r.length - 1 && (s[i] = n), s[i]), e), e;
493
- }, Qt = (e, t) => {
494
- const n = {};
495
- return Object.keys(e).forEach((r) => {
496
- const s = e[r], i = Kr(r, t);
497
- typeof s == "object" && Object.assign(n, Qt(s, i)), typeof s == "function" && (n[i] = s);
498
- }), n;
499
- }, Gr = (e) => {
500
- const t = {};
501
- for (const n in e)
502
- Yr(t, n, e[n]);
503
- return t;
504
- }, Zr = (e, t, n, r, s) => {
505
- const { localName: i, local: a, remote: c, originForSending: d, originForReceiving: l } = t;
506
- let u = !1;
507
- s(`${i}: Connecting call sender`);
508
- const y = (m) => (...g) => {
509
- s(`${i}: Sending ${m}() call`);
510
- let v;
511
- try {
512
- c.closed && (v = !0);
513
- } catch {
514
- v = !0;
515
- }
516
- if (v && r(), u) {
517
- const C = new Error(`Unable to send ${m}() call due to destroyed connection`);
518
- throw C.code = we.ConnectionDestroyed, C;
519
- }
520
- return new Promise((C, x) => {
521
- const $ = Vr(), S = (W) => {
522
- if (W.source !== c || W.data.penpal !== V.Reply || W.data.id !== $)
523
- return;
524
- if (l !== "*" && W.origin !== l) {
525
- s(`${i} received message from origin ${W.origin} which did not match expected origin ${l}`);
526
- return;
527
- }
528
- const pe = W.data;
529
- s(`${i}: Received ${m}() reply`), a.removeEventListener(ee.Message, S);
530
- let te = pe.returnValue;
531
- pe.returnValueIsError && (te = Br(te)), (pe.resolution === oe.Fulfilled ? C : x)(te);
532
- };
533
- a.addEventListener(ee.Message, S);
534
- const Z = {
535
- penpal: V.Call,
536
- id: $,
537
- methodName: m,
538
- args: g
539
- };
540
- c.postMessage(Z, d);
541
- });
542
- }, f = n.reduce((m, g) => (m[g] = y(g), m), {});
543
- return Object.assign(e, Gr(f)), () => {
544
- u = !0;
545
- };
546
- }, Wr = (e, t, n, r, s) => {
547
- const { destroy: i, onDestroy: a } = r;
548
- let c, d;
549
- const l = {};
550
- return (u) => {
551
- if (t !== "*" && u.origin !== t) {
552
- s(`Parent: Handshake - Received ACK message from origin ${u.origin} which did not match expected origin ${t}`);
553
- return;
554
- }
555
- s("Parent: Handshake - Received ACK");
556
- const y = {
557
- localName: "Parent",
558
- local: window,
559
- remote: u.source,
560
- originForSending: n,
561
- originForReceiving: t
562
- };
563
- c && c(), c = qr(y, e, s), a(c), d && d.forEach((m) => {
564
- delete l[m];
565
- }), d = u.data.methodNames;
566
- const f = Zr(l, y, d, i, s);
567
- return a(f), l;
568
- };
569
- }, Jr = (e, t, n, r) => (s) => {
570
- if (!s.source)
571
- return;
572
- if (n !== "*" && s.origin !== n) {
573
- e(`Parent: Handshake - Received SYN message from origin ${s.origin} which did not match expected origin ${n}`);
574
- return;
575
- }
576
- e("Parent: Handshake - Received SYN, responding with SYN-ACK");
577
- const i = {
578
- penpal: V.SynAck,
579
- methodNames: Object.keys(t)
580
- };
581
- s.source.postMessage(i, r);
582
- }, Qr = 6e4, Xr = (e, t) => {
583
- const { destroy: n, onDestroy: r } = t, s = setInterval(() => {
584
- e.isConnected || (clearInterval(s), n());
585
- }, Qr);
586
- r(() => {
587
- clearInterval(s);
588
- });
589
- }, eo = (e, t) => {
590
- let n;
591
- return e !== void 0 && (n = window.setTimeout(() => {
592
- const r = new Error(`Connection timed out after ${e}ms`);
593
- r.code = we.ConnectionTimeout, t(r);
594
- }, e)), () => {
595
- clearTimeout(n);
596
- };
597
- }, to = (e) => {
598
- if (!e.src && !e.srcdoc) {
599
- const t = new Error("Iframe must have src or srcdoc property defined.");
600
- throw t.code = we.NoIframeSrc, t;
601
- }
602
- }, Xt = (e) => {
603
- let { iframe: t, methods: n = {}, childOrigin: r, timeout: s, debug: i = !1 } = e;
604
- const a = xr(i), c = Dr("Parent", a), { onDestroy: d, destroy: l } = c;
605
- r || (to(t), r = Ur(t.src));
606
- const u = r === "null" ? "*" : r, y = Qt(n), f = Jr(a, y, r, u), m = Wr(y, r, u, c, a);
607
- return {
608
- promise: new Promise((v, C) => {
609
- const x = eo(s, l), $ = (S) => {
610
- if (!(S.source !== t.contentWindow || !S.data)) {
611
- if (S.data.penpal === V.Syn) {
612
- f(S);
613
- return;
614
- }
615
- if (S.data.penpal === V.Ack) {
616
- const Z = m(S);
617
- Z && (x(), v(Z));
618
- return;
619
- }
620
- }
621
- };
622
- window.addEventListener(ee.Message, $), a("Parent: Awaiting handshake"), Xr(t, c), d((S) => {
623
- window.removeEventListener(ee.Message, $), S && C(S);
624
- });
625
- }),
626
- destroy() {
627
- l();
628
- }
629
- };
630
- }, no = async (e) => {
366
+ }, Xn = async (e) => {
631
367
  if (typeof e != "object" || !e) return !1;
632
368
  try {
633
- const t = { type: "ping" }, n = await e.send(t);
634
- if (n !== !0)
635
- throw new Error(`Expected 'true' after ping, got ${JSON.stringify(n)}`);
369
+ const t = { type: "ping" }, r = await e.send(t);
370
+ if (r !== !0)
371
+ throw new Error(`Expected 'true' after ping, got ${JSON.stringify(r)}`);
636
372
  return !0;
637
373
  } catch {
638
374
  return !1;
639
375
  }
640
- }, ro = (e, t) => !!e && t;
641
- async function oo(e) {
642
- const n = await Xt({
376
+ }, er = (e, t) => !!e && t;
377
+ async function tr(e) {
378
+ const r = await it({
643
379
  iframe: e,
644
380
  debug: !0
645
- }).promise, r = await no(n);
646
- if (!ro(n, r))
381
+ }).promise, o = await Xn(r);
382
+ if (!er(r, o))
647
383
  throw new Error("Got invalid CDE connection object");
648
- return n;
384
+ return r;
649
385
  }
650
- const P = (e) => o.nullable(e.optional());
651
- o.string().trim().min(1, { message: "Cannot be blank" });
652
- const so = o.object({
653
- cde_response_type: o.literal("error"),
654
- message: o.string(),
655
- headers: o.record(o.string(), o.string()).optional()
656
- }), io = o.enum(["usd", "brl"]), en = o.object({
657
- name: o.string(),
658
- amount_atom_off: P(o.number()),
659
- percent_off: P(o.number()),
660
- currency: P(o.string()),
661
- duration: o.string(),
662
- duration_in_months: P(o.number())
663
- }), tn = o.object({
664
- amount_subtotal_atom: o.number().int(),
665
- amount_total_atom: o.number().int(),
666
- currency: o.string(),
667
- description: P(o.string()),
668
- price_id: o.string(),
669
- billing_interval: P(o.string()),
670
- billing_interval_count: P(o.number().int()),
671
- quantity: o.number().int()
672
- }), ao = o.record(o.string(), o.any()), co = o.object({
673
- name: o.string(),
674
- settings: P(ao)
675
- }), Ne = o.object({
676
- provider: o.string(),
677
- processor_name: P(o.string()),
678
- metadata: P(o.record(o.string(), o.any()))
679
- }), lo = o.object({
680
- quantity: o.number()
681
- }), uo = o.object({
682
- id: P(o.string()),
683
- billing_interval: P(o.string()),
684
- billing_interval_count: P(o.number().int()),
685
- subscription_items: o.array(lo),
686
- trial_start: P(o.string()),
687
- trial_end: P(o.string())
688
- }), nn = o.object({
689
- amount_atom: o.number()
690
- }), mo = o.object({
691
- amount_atom: o.number(),
692
- amount_atom_considering_discount_applied: o.number(),
693
- currency: o.string(),
694
- discount_amount_atoms: o.array(nn),
695
- subscription_item_id: o.string()
696
- }), fo = o.object({
697
- coupon: en
698
- }), po = o.object({
699
- currency: o.string(),
700
- discounts: o.array(fo),
701
- hosted_invoice_url: P(o.string()),
702
- lines: o.array(mo),
703
- remaining_amount_atom: o.number(),
704
- tax_amount_atom: o.number(),
705
- total_amount_atom: o.number(),
706
- total_discount_amount_atoms: o.array(nn)
707
- }), vt = o.object({
708
- created: o.array(uo),
709
- invoices: o.array(po)
710
- }), rn = o.object({
711
- preview: vt,
712
- preview_post_trial: P(vt),
713
- coupons: o.array(en)
714
- }), St = o.object({
715
- status: o.literal("open"),
716
- token: o.string(),
717
- email: P(o.string()),
718
- line_items: o.array(tn),
719
- amount_subtotal_atom: o.number().int(),
720
- amount_total_atom: o.number().int(),
721
- brand: co,
722
- subs_preview: P(rn),
386
+ const b = (e) => n.nullable(e.optional());
387
+ n.string().trim().min(1, { message: "Cannot be blank" });
388
+ const nr = n.object({
389
+ cde_response_type: n.literal("error"),
390
+ message: n.string(),
391
+ headers: n.record(n.string(), n.string()).optional()
392
+ });
393
+ n.enum(["usd", "brl"]);
394
+ const ht = n.object({
395
+ name: n.string(),
396
+ amount_atom_off: b(n.number()),
397
+ percent_off: b(n.number()),
398
+ currency: b(n.string()),
399
+ duration: n.string(),
400
+ duration_in_months: b(n.number())
401
+ }), wt = n.object({
402
+ amount_subtotal_atom: n.number().int(),
403
+ amount_total_atom: n.number().int(),
404
+ currency: n.string(),
405
+ description: b(n.string()),
406
+ price_id: n.string(),
407
+ billing_interval: b(n.string()),
408
+ billing_interval_count: b(n.number().int()),
409
+ quantity: n.number().int()
410
+ }), rr = n.record(n.string(), n.any()), or = n.object({
411
+ name: n.string(),
412
+ settings: b(rr)
413
+ }), ge = n.object({
414
+ provider: n.string(),
415
+ processor_name: b(n.string()),
416
+ metadata: b(n.record(n.string(), n.any()))
417
+ }), sr = n.object({
418
+ quantity: n.number()
419
+ }), ir = n.object({
420
+ id: b(n.string()),
421
+ billing_interval: b(n.string()),
422
+ billing_interval_count: b(n.number().int()),
423
+ subscription_items: n.array(sr),
424
+ trial_start: b(n.string()),
425
+ trial_end: b(n.string())
426
+ }), Et = n.object({
427
+ amount_atom: n.number()
428
+ }), ar = n.object({
429
+ amount_atom: n.number(),
430
+ amount_atom_considering_discount_applied: n.number(),
431
+ currency: n.string(),
432
+ discount_amount_atoms: n.array(Et),
433
+ subscription_item_id: n.string()
434
+ }), cr = n.object({
435
+ coupon: ht
436
+ }), lr = n.object({
437
+ currency: n.string(),
438
+ discounts: n.array(cr),
439
+ hosted_invoice_url: b(n.string()),
440
+ lines: n.array(ar),
441
+ remaining_amount_atom: n.number(),
442
+ tax_amount_atom: n.number(),
443
+ 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({
453
+ status: n.literal("open"),
454
+ token: n.string(),
455
+ email: b(n.string()),
456
+ line_items: n.array(wt),
457
+ amount_subtotal_atom: n.number().int(),
458
+ amount_total_atom: n.number().int(),
459
+ brand: or,
460
+ subs_preview: b(Ct),
723
461
  // Null in setup mode
724
- methods_available: o.array(Ne)
725
- }), on = o.discriminatedUnion("mode", [
726
- o.object({
727
- mode: o.literal("setup"),
728
- currency: o.nullable(o.undefined())
729
- }).extend(St.shape),
730
- o.object({
731
- mode: o.enum(["payment", "subscription"]),
732
- currency: io
733
- }).extend(St.shape)
734
- ]), yo = o.object({
735
- status: o.literal("complete")
736
- }), go = o.object({
737
- status: o.literal("expired")
462
+ methods_available: n.array(ge)
463
+ }), bt = n.discriminatedUnion("mode", [
464
+ n.object({
465
+ mode: n.literal("setup"),
466
+ currency: n.nullable(n.undefined())
467
+ }).extend(Qe.shape),
468
+ n.object({
469
+ mode: n.enum(["payment", "subscription"]),
470
+ currency: n.string()
471
+ }).extend(Qe.shape)
472
+ ]), ur = n.object({
473
+ status: n.literal("complete")
474
+ }), dr = n.object({
475
+ status: n.literal("expired")
738
476
  });
739
- o.union([on, yo, go]);
740
- o.object({
741
- logo: o.string(),
742
- icon: o.string(),
743
- primary_color: o.string(),
744
- secondary_color: o.string()
477
+ n.union([bt, ur, dr]);
478
+ n.object({
479
+ logo: n.string(),
480
+ icon: n.string(),
481
+ primary_color: n.string(),
482
+ secondary_color: n.string()
745
483
  });
746
- const sn = o.object({
747
- invoice_urls: o.array(o.string()),
748
- subscription_ids: o.array(o.string()),
749
- customer_id: o.string()
484
+ const St = n.object({
485
+ invoice_urls: n.array(n.string()),
486
+ subscription_ids: n.array(n.string()),
487
+ customer_id: n.string()
750
488
  });
751
- o.object({
752
- secure_token: o.string(),
753
- payment_input: o.any(),
489
+ n.object({
490
+ secure_token: n.string(),
491
+ payment_input: n.any(),
754
492
  // Should follow AnyPaymentInput from CDE
755
- customer_email: o.string(),
756
- customer_zip_code: o.string(),
757
- customer_country: o.string(),
758
- line_items: o.array(tn),
759
- total_amount_atom: o.number().int(),
760
- cancel_at_end: o.boolean(),
761
- checkout_payment_method: Ne,
762
- promotion_code: o.string().optional(),
763
- do_not_use_legacy_cc_flow: o.boolean().optional()
493
+ customer_email: n.string(),
494
+ customer_zip_code: n.string(),
495
+ customer_country: n.string(),
496
+ line_items: n.array(wt),
497
+ total_amount_atom: n.number().int(),
498
+ cancel_at_end: n.boolean(),
499
+ checkout_payment_method: ge,
500
+ promotion_code: n.string().optional(),
501
+ do_not_use_legacy_cc_flow: n.boolean().optional()
764
502
  });
765
- const ho = o.object({
766
- payment_method_id: o.string()
503
+ const mr = n.object({
504
+ payment_method_id: n.string()
767
505
  });
768
- o.object({
769
- id: o.string(),
770
- return_url: o.string()
506
+ n.object({
507
+ id: n.string(),
508
+ return_url: n.string()
771
509
  });
772
- const _o = o.object({
773
- type: o.string(),
774
- loc: o.array(o.string()),
775
- msg: o.string(),
776
- url: o.string()
510
+ const fr = n.object({
511
+ type: n.string(),
512
+ loc: n.array(n.string()),
513
+ msg: n.string(),
514
+ url: n.string()
777
515
  });
778
- o.array(_o);
779
- const wo = o.object({
780
- required_user_actions: o.array(o.record(o.string(), o.any()))
516
+ n.array(fr);
517
+ const pr = n.object({
518
+ required_user_actions: n.array(n.record(n.string(), n.any()))
781
519
  });
782
- o.object({
783
- fields: lr,
784
- checkoutPaymentMethod: Ne
520
+ n.object({
521
+ fields: In,
522
+ checkoutPaymentMethod: ge
785
523
  });
786
- o.object({
787
- session_id: o.string(),
788
- non_cde_form_fields: Ee,
789
- checkout_payment_method: Ne
524
+ n.object({
525
+ session_id: n.string(),
526
+ non_cde_form_fields: oe,
527
+ checkout_payment_method: ge
790
528
  });
791
- const bo = o.object({
792
- required_user_actions: o.array(o.record(o.string(), o.any())),
793
- cc_pm_id: o.string()
529
+ const yr = n.object({
530
+ required_user_actions: n.array(n.record(n.string(), n.any())),
531
+ cc_pm_id: n.string()
794
532
  });
795
- o.record(o.any());
796
- const Eo = (e) => e.reduce((t, n) => t + n, 0);
797
- function Co(e, t) {
798
- var n = Object.setPrototypeOf;
799
- n ? n(e, t) : e.__proto__ = t;
533
+ n.record(n.any());
534
+ const _r = (e) => e.reduce((t, r) => t + r, 0);
535
+ function gr(e, t) {
536
+ var r = Object.setPrototypeOf;
537
+ r ? r(e, t) : e.__proto__ = t;
800
538
  }
801
- function vo(e, t) {
539
+ function hr(e, t) {
802
540
  t === void 0 && (t = e.constructor);
803
- var n = Error.captureStackTrace;
804
- n && n(e, t);
541
+ var r = Error.captureStackTrace;
542
+ r && r(e, t);
805
543
  }
806
- var So = /* @__PURE__ */ function() {
807
- var e = function(n, r) {
544
+ var wr = /* @__PURE__ */ function() {
545
+ var e = function(r, o) {
808
546
  return e = Object.setPrototypeOf || {
809
547
  __proto__: []
810
548
  } instanceof Array && function(s, i) {
@@ -812,112 +550,113 @@ var So = /* @__PURE__ */ function() {
812
550
  } || function(s, i) {
813
551
  for (var a in i)
814
552
  Object.prototype.hasOwnProperty.call(i, a) && (s[a] = i[a]);
815
- }, e(n, r);
553
+ }, e(r, o);
816
554
  };
817
- return function(t, n) {
818
- if (typeof n != "function" && n !== null) throw new TypeError("Class extends value " + String(n) + " is not a constructor or null");
819
- e(t, n);
820
- function r() {
555
+ return function(t, r) {
556
+ if (typeof r != "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
557
+ e(t, r);
558
+ function o() {
821
559
  this.constructor = t;
822
560
  }
823
- t.prototype = n === null ? Object.create(n) : (r.prototype = n.prototype, new r());
561
+ t.prototype = r === null ? Object.create(r) : (o.prototype = r.prototype, new o());
824
562
  };
825
- }(), Po = function(e) {
826
- So(t, e);
827
- function t(n, r) {
828
- var s = this.constructor, i = e.call(this, n, r) || this;
563
+ }(), Er = function(e) {
564
+ wr(t, e);
565
+ function t(r, o) {
566
+ var s = this.constructor, i = e.call(this, r, o) || this;
829
567
  return Object.defineProperty(i, "name", {
830
568
  value: s.name,
831
569
  enumerable: !1,
832
570
  configurable: !0
833
- }), Co(i, s.prototype), vo(i), i;
571
+ }), gr(i, s.prototype), hr(i), i;
834
572
  }
835
573
  return t;
836
574
  }(Error);
837
- class an extends Po {
575
+ class Pt extends Er {
838
576
  constructor(t) {
839
- const n = `[cde-client] Error querying CDE: ${t.message}`;
840
- super(n), this.response = t;
577
+ const r = `[cde-client] Error querying CDE: ${t.message}`;
578
+ super(r), this.response = t;
841
579
  }
842
580
  get originalErrorMessage() {
843
581
  return this.response.message;
844
582
  }
845
583
  }
846
- const H = async (e, t, n) => {
847
- const r = await e.send(t);
848
- if (Oo(r))
849
- throw new an(r);
850
- if (!Ro(r, n)) {
851
- const s = n.safeParse(r);
584
+ const x = async (e, t, r) => {
585
+ const o = await e.send(t);
586
+ if (br(o))
587
+ throw new Pt(o);
588
+ if (!Cr(o, r)) {
589
+ const s = r.safeParse(o);
852
590
  throw s.success ? new Error("Invalid state") : s.error;
853
591
  }
854
- return r;
855
- }, Ro = (e, t) => t.safeParse(e).success, Oo = (e) => so.safeParse(e).success, ko = async (e, t) => await H(e, { type: "get_checkout_preview", payload: t }, rn), Ce = async (e) => await H(e, { type: "get_prefill", payload: {} }, on), Ao = async (e, t) => await H(e, { type: "start_payment_flow_for_cc", payload: t }, bo), To = async (e, t) => await H(e, { type: "start_payment_flow_for_pr", payload: t }, wo), ct = async (e, t) => await H(e, { type: "confirm_payment_flow", payload: t }, yr), Io = async (e, t, n) => {
856
- const r = Date.now();
857
- for (n = n ?? 5e3; Date.now() - r < n; ) {
592
+ 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) => {
594
+ const o = Date.now();
595
+ for (r = r ?? 5e3; Date.now() - o < r; ) {
858
596
  const s = e.querySelector(`input[data-opid=${t}]`);
859
597
  if (s !== null) {
860
598
  if (!(s instanceof HTMLInputElement))
861
599
  throw new Error(`Invalid state: matched input element had wrong class: ${s.tagName}`);
862
600
  return s;
863
601
  }
864
- await Yt(300);
602
+ await _t(300);
865
603
  }
866
604
  return null;
867
- }, Mo = async (e, t, n) => {
868
- const r = await ko(e, {
605
+ }, Rr = async (e, t, r) => {
606
+ const o = await Sr(e, {
869
607
  secure_token: t,
870
- promotion_code: n
871
- }), s = new Set(r.preview.invoices.map((c) => c.currency));
608
+ promotion_code: r
609
+ }), s = new Set(o.preview.invoices.map((c) => c.currency));
872
610
  if (s.size !== 1)
873
611
  throw new Error(`Expected exactly one currency, got ${s.size}`);
874
- const i = s.values().next().value ?? "usd", a = Eo(r.preview.invoices.map((c) => c.remaining_amount_atom));
612
+ const i = s.values().next().value ?? "usd", a = _r(o.preview.invoices.map((c) => c.remaining_amount_atom));
875
613
  return {
876
614
  currency: i,
877
615
  amountAtom: a
878
616
  };
879
- }, cn = async (e, t, n, r) => {
880
- if (n)
617
+ }, vt = async (e, t, r, o) => {
618
+ if (r)
881
619
  return { amountAtom: 0, currency: "usd" };
882
620
  {
883
- r = r || void 0;
884
- const s = await Mo(e, t, r);
621
+ o = o || void 0;
622
+ const s = await Rr(e, t, o);
885
623
  return { amountAtom: s.amountAtom, currency: s.currency };
886
624
  }
887
- }, jo = async (e, t) => {
625
+ }, kr = async (e, t) => {
888
626
  if (e.size === 0)
889
627
  throw new Error("No CDE connections found");
890
628
  return await Promise.all(
891
629
  Array.from(e.values()).map(
892
- (r) => H(r, { type: "tokenize_card", payload: t }, _r)
630
+ (o) => x(o, { type: "tokenize_card", payload: t }, Un)
893
631
  )
894
632
  );
895
- }, Pt = async (e, t) => {
633
+ }, Xe = async (e, t) => {
896
634
  try {
897
- return await H(e, { type: "checkout_card_elements", payload: t }, sn);
898
- } catch (n) {
899
- throw n;
635
+ return await x(e, { type: "checkout_card_elements", payload: t }, St);
636
+ } catch (r) {
637
+ throw r;
900
638
  }
901
- }, Fo = async (e, t) => await H(e, { type: "setup_payment_method", payload: t }, ho), Do = async (e, t) => await H(e, { type: "checkout", payload: t }, sn), ln = 1e3, xo = async (e, t) => {
902
- const r = await Xt({
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({
903
641
  iframe: e,
904
642
  debug: !0,
905
- timeout: ln,
906
- childOrigin: t
643
+ timeout: Ot,
644
+ childOrigin: "*"
645
+ // TODO: use with proper childOrigin
907
646
  }).promise;
908
- return (await H(r, { type: "ping-3ds-status" }, wr)).status;
909
- }, $o = (e) => {
647
+ return (await x(o, { type: "ping-3ds-status" }, qn)).status;
648
+ }, jr = (e) => {
910
649
  if (typeof e != "string") return !1;
911
650
  try {
912
651
  return JSON.parse(e), !0;
913
652
  } catch {
914
653
  return !1;
915
654
  }
916
- }, No = "@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}", Lo = (e) => {
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) => {
917
656
  const t = document.createElement("template");
918
657
  t.innerHTML = `
919
658
  <style>
920
- ${No}
659
+ ${Mr}
921
660
  </style>
922
661
  <div class="overlay">
923
662
  <div class="container">
@@ -926,486 +665,214 @@ const H = async (e, t, n) => {
926
665
  </div>
927
666
  </div>
928
667
  `;
929
- const n = document.createElement("div"), r = n.attachShadow({ mode: "open" });
930
- r.appendChild(t.content.cloneNode(!0));
931
- const s = r.querySelector("#three-ds-iframe"), i = r.querySelector(".cancel-button");
932
- return document.body.appendChild(n), { host: n, iframe: s, cancelButton: i };
668
+ const r = document.createElement("div"), o = r.attachShadow({ mode: "open" });
669
+ o.appendChild(t.content.cloneNode(!0));
670
+ const s = o.querySelector("#three-ds-iframe"), i = o.querySelector(".cancel-button");
671
+ return document.body.appendChild(r), { host: r, iframe: s, cancelButton: i };
933
672
  };
934
- function Uo(e, t, n) {
935
- const r = async () => {
673
+ function Dr(e, t, r) {
674
+ const o = async () => {
936
675
  try {
937
- const i = await xo(e, n);
676
+ const i = await Ir(e, r);
938
677
  i && (clearInterval(s), t(i));
939
678
  } catch {
940
679
  }
941
680
  };
942
- r();
943
- const s = setInterval(r, ln);
681
+ o();
682
+ const s = setInterval(o, Ot);
944
683
  return s;
945
684
  }
946
- function Bo({
685
+ function Nr({
947
686
  elements: e,
948
687
  pollingInterval: t,
949
- resolve: n
688
+ resolve: r
950
689
  }) {
951
- const r = () => {
952
- clearInterval(t), e.host.remove(), n(Me.CANCELLED);
690
+ const o = () => {
691
+ clearInterval(t), e.host.remove(), r(me.CANCELLED);
953
692
  };
954
- return e.cancelButton.addEventListener("click", r), () => {
955
- e.cancelButton.removeEventListener("click", r);
693
+ return e.cancelButton.addEventListener("click", o), () => {
694
+ e.cancelButton.removeEventListener("click", o);
956
695
  };
957
696
  }
958
- async function qo({
697
+ async function xr({
959
698
  url: e,
960
699
  baseUrl: t
961
700
  }) {
962
- const n = Lo(e);
963
- return new Promise((r) => {
701
+ const r = Fr(e);
702
+ return new Promise((o) => {
964
703
  const s = (c) => {
965
704
  setTimeout(() => {
966
- n.host.remove();
967
- }, 1e3), r(c), a == null || a();
968
- }, i = Uo(n.iframe, s, new URL(t).origin), a = Bo({
969
- elements: n,
705
+ r.host.remove();
706
+ }, 1e3), o(c), a == null || a();
707
+ }, i = Dr(r.iframe, s, new URL(t).origin), a = Nr({
708
+ elements: r,
970
709
  pollingInterval: i,
971
- resolve: r
710
+ resolve: o
972
711
  });
973
712
  });
974
713
  }
975
- const We = 10, Rt = (e = 0) => (t) => `\x1B[${t + e}m`, Ot = (e = 0) => (t) => `\x1B[${38 + e};5;${t}m`, kt = (e = 0) => (t, n, r) => `\x1B[${38 + e};2;${t};${n};${r}m`, b = {
976
- modifier: {
977
- reset: [0, 0],
978
- // 21 isn't widely supported and 22 does the same thing
979
- bold: [1, 22],
980
- dim: [2, 22],
981
- italic: [3, 23],
982
- underline: [4, 24],
983
- overline: [53, 55],
984
- inverse: [7, 27],
985
- hidden: [8, 28],
986
- strikethrough: [9, 29]
987
- },
988
- color: {
989
- black: [30, 39],
990
- red: [31, 39],
991
- green: [32, 39],
992
- yellow: [33, 39],
993
- blue: [34, 39],
994
- magenta: [35, 39],
995
- cyan: [36, 39],
996
- white: [37, 39],
997
- // Bright color
998
- blackBright: [90, 39],
999
- gray: [90, 39],
1000
- // Alias of `blackBright`
1001
- grey: [90, 39],
1002
- // Alias of `blackBright`
1003
- redBright: [91, 39],
1004
- greenBright: [92, 39],
1005
- yellowBright: [93, 39],
1006
- blueBright: [94, 39],
1007
- magentaBright: [95, 39],
1008
- cyanBright: [96, 39],
1009
- whiteBright: [97, 39]
1010
- },
1011
- bgColor: {
1012
- bgBlack: [40, 49],
1013
- bgRed: [41, 49],
1014
- bgGreen: [42, 49],
1015
- bgYellow: [43, 49],
1016
- bgBlue: [44, 49],
1017
- bgMagenta: [45, 49],
1018
- bgCyan: [46, 49],
1019
- bgWhite: [47, 49],
1020
- // Bright color
1021
- bgBlackBright: [100, 49],
1022
- bgGray: [100, 49],
1023
- // Alias of `bgBlackBright`
1024
- bgGrey: [100, 49],
1025
- // Alias of `bgBlackBright`
1026
- bgRedBright: [101, 49],
1027
- bgGreenBright: [102, 49],
1028
- bgYellowBright: [103, 49],
1029
- bgBlueBright: [104, 49],
1030
- bgMagentaBright: [105, 49],
1031
- bgCyanBright: [106, 49],
1032
- bgWhiteBright: [107, 49]
1033
- }
1034
- };
1035
- Object.keys(b.modifier);
1036
- const zo = Object.keys(b.color), Vo = Object.keys(b.bgColor);
1037
- [...zo, ...Vo];
1038
- function Ho() {
1039
- const e = /* @__PURE__ */ new Map();
1040
- for (const [t, n] of Object.entries(b)) {
1041
- for (const [r, s] of Object.entries(n))
1042
- b[r] = {
1043
- open: `\x1B[${s[0]}m`,
1044
- close: `\x1B[${s[1]}m`
1045
- }, n[r] = b[r], e.set(s[0], s[1]);
1046
- Object.defineProperty(b, t, {
1047
- value: n,
1048
- enumerable: !1
1049
- });
1050
- }
1051
- return Object.defineProperty(b, "codes", {
1052
- value: e,
1053
- enumerable: !1
1054
- }), b.color.close = "\x1B[39m", b.bgColor.close = "\x1B[49m", b.color.ansi = Rt(), b.color.ansi256 = Ot(), b.color.ansi16m = kt(), b.bgColor.ansi = Rt(We), b.bgColor.ansi256 = Ot(We), b.bgColor.ansi16m = kt(We), Object.defineProperties(b, {
1055
- rgbToAnsi256: {
1056
- value(t, n, r) {
1057
- return t === n && n === r ? t < 8 ? 16 : t > 248 ? 231 : Math.round((t - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(t / 255 * 5) + 6 * Math.round(n / 255 * 5) + Math.round(r / 255 * 5);
1058
- },
1059
- enumerable: !1
1060
- },
1061
- hexToRgb: {
1062
- value(t) {
1063
- const n = /[a-f\d]{6}|[a-f\d]{3}/i.exec(t.toString(16));
1064
- if (!n)
1065
- return [0, 0, 0];
1066
- let [r] = n;
1067
- r.length === 3 && (r = [...r].map((i) => i + i).join(""));
1068
- const s = Number.parseInt(r, 16);
1069
- return [
1070
- /* eslint-disable no-bitwise */
1071
- s >> 16 & 255,
1072
- s >> 8 & 255,
1073
- s & 255
1074
- /* eslint-enable no-bitwise */
1075
- ];
1076
- },
1077
- enumerable: !1
1078
- },
1079
- hexToAnsi256: {
1080
- value: (t) => b.rgbToAnsi256(...b.hexToRgb(t)),
1081
- enumerable: !1
1082
- },
1083
- ansi256ToAnsi: {
1084
- value(t) {
1085
- if (t < 8)
1086
- return 30 + t;
1087
- if (t < 16)
1088
- return 90 + (t - 8);
1089
- let n, r, s;
1090
- if (t >= 232)
1091
- n = ((t - 232) * 10 + 8) / 255, r = n, s = n;
1092
- else {
1093
- t -= 16;
1094
- const c = t % 36;
1095
- n = Math.floor(t / 36) / 5, r = Math.floor(c / 6) / 5, s = c % 6 / 5;
1096
- }
1097
- const i = Math.max(n, r, s) * 2;
1098
- if (i === 0)
1099
- return 30;
1100
- let a = 30 + (Math.round(s) << 2 | Math.round(r) << 1 | Math.round(n));
1101
- return i === 2 && (a += 60), a;
1102
- },
1103
- enumerable: !1
1104
- },
1105
- rgbToAnsi: {
1106
- value: (t, n, r) => b.ansi256ToAnsi(b.rgbToAnsi256(t, n, r)),
1107
- enumerable: !1
1108
- },
1109
- hexToAnsi: {
1110
- value: (t) => b.ansi256ToAnsi(b.hexToAnsi256(t)),
1111
- enumerable: !1
1112
- }
1113
- }), b;
1114
- }
1115
- const z = Ho(), Re = (() => {
1116
- if (navigator.userAgentData) {
1117
- const e = navigator.userAgentData.brands.find(({ brand: t }) => t === "Chromium");
1118
- if (e && e.version > 93)
1119
- return 3;
1120
- }
1121
- return /\b(Chrome|Chromium)\//.test(navigator.userAgent) ? 1 : 0;
1122
- })(), At = Re !== 0 && {
1123
- level: Re,
1124
- hasBasic: !0,
1125
- has256: Re >= 2,
1126
- has16m: Re >= 3
1127
- }, Ko = {
1128
- stdout: At,
1129
- stderr: At
1130
- };
1131
- function Yo(e, t, n) {
1132
- let r = e.indexOf(t);
1133
- if (r === -1)
1134
- return e;
1135
- const s = t.length;
1136
- let i = 0, a = "";
1137
- do
1138
- a += e.slice(i, r) + t + n, i = r + s, r = e.indexOf(t, i);
1139
- while (r !== -1);
1140
- return a += e.slice(i), a;
1141
- }
1142
- function Go(e, t, n, r) {
1143
- let s = 0, i = "";
1144
- do {
1145
- const a = e[r - 1] === "\r";
1146
- i += e.slice(s, a ? r - 1 : r) + t + (a ? `\r
1147
- ` : `
1148
- `) + n, s = r + 1, r = e.indexOf(`
1149
- `, s);
1150
- } while (r !== -1);
1151
- return i += e.slice(s), i;
1152
- }
1153
- const { stdout: Tt, stderr: It } = Ko, nt = Symbol("GENERATOR"), de = Symbol("STYLER"), be = Symbol("IS_EMPTY"), Mt = [
1154
- "ansi",
1155
- "ansi",
1156
- "ansi256",
1157
- "ansi16m"
1158
- ], me = /* @__PURE__ */ Object.create(null), Zo = (e, t = {}) => {
1159
- if (t.level && !(Number.isInteger(t.level) && t.level >= 0 && t.level <= 3))
1160
- throw new Error("The `level` option should be an integer from 0 to 3");
1161
- const n = Tt ? Tt.level : 0;
1162
- e.level = t.level === void 0 ? n : t.level;
1163
- }, Wo = (e) => {
1164
- const t = (...n) => n.join(" ");
1165
- return Zo(t, e), Object.setPrototypeOf(t, ve.prototype), t;
1166
- };
1167
- function ve(e) {
1168
- return Wo(e);
1169
- }
1170
- Object.setPrototypeOf(ve.prototype, Function.prototype);
1171
- for (const [e, t] of Object.entries(z))
1172
- me[e] = {
1173
- get() {
1174
- const n = je(this, ot(t.open, t.close, this[de]), this[be]);
1175
- return Object.defineProperty(this, e, { value: n }), n;
1176
- }
1177
- };
1178
- me.visible = {
1179
- get() {
1180
- const e = je(this, this[de], !0);
1181
- return Object.defineProperty(this, "visible", { value: e }), e;
1182
- }
1183
- };
1184
- const rt = (e, t, n, ...r) => e === "rgb" ? t === "ansi16m" ? z[n].ansi16m(...r) : t === "ansi256" ? z[n].ansi256(z.rgbToAnsi256(...r)) : z[n].ansi(z.rgbToAnsi(...r)) : e === "hex" ? rt("rgb", t, n, ...z.hexToRgb(...r)) : z[n][e](...r), Jo = ["rgb", "hex", "ansi256"];
1185
- for (const e of Jo) {
1186
- me[e] = {
1187
- get() {
1188
- const { level: n } = this;
1189
- return function(...r) {
1190
- const s = ot(rt(e, Mt[n], "color", ...r), z.color.close, this[de]);
1191
- return je(this, s, this[be]);
1192
- };
1193
- }
1194
- };
1195
- const t = "bg" + e[0].toUpperCase() + e.slice(1);
1196
- me[t] = {
1197
- get() {
1198
- const { level: n } = this;
1199
- return function(...r) {
1200
- const s = ot(rt(e, Mt[n], "bgColor", ...r), z.bgColor.close, this[de]);
1201
- return je(this, s, this[be]);
1202
- };
1203
- }
1204
- };
1205
- }
1206
- const Qo = Object.defineProperties(() => {
1207
- }, {
1208
- ...me,
1209
- level: {
1210
- enumerable: !0,
1211
- get() {
1212
- return this[nt].level;
1213
- },
1214
- set(e) {
1215
- this[nt].level = e;
1216
- }
1217
- }
1218
- }), ot = (e, t, n) => {
1219
- let r, s;
1220
- return n === void 0 ? (r = e, s = t) : (r = n.openAll + e, s = t + n.closeAll), {
1221
- open: e,
1222
- close: t,
1223
- openAll: r,
1224
- closeAll: s,
1225
- parent: n
1226
- };
1227
- }, je = (e, t, n) => {
1228
- const r = (...s) => Xo(r, s.length === 1 ? "" + s[0] : s.join(" "));
1229
- return Object.setPrototypeOf(r, Qo), r[nt] = e, r[de] = t, r[be] = n, r;
1230
- }, Xo = (e, t) => {
1231
- if (e.level <= 0 || !t)
1232
- return e[be] ? "" : t;
1233
- let n = e[de];
1234
- if (n === void 0)
1235
- return t;
1236
- const { openAll: r, closeAll: s } = n;
1237
- if (t.includes("\x1B"))
1238
- for (; n !== void 0; )
1239
- t = Yo(t, n.close, n.open), n = n.parent;
1240
- const i = t.indexOf(`
1241
- `);
1242
- return i !== -1 && (t = Go(t, s, r, i)), r + t + s;
1243
- };
1244
- Object.defineProperties(ve.prototype, me);
1245
- const Oe = ve();
1246
- ve({ level: It ? It.level : 0 });
1247
- const un = (e) => async (t) => {
714
+ const Rt = (e) => async (t) => {
1248
715
  try {
1249
716
  t.flowCallbacks.onCheckoutStarted();
1250
- const n = await e(t);
1251
- if (n.mode === "setup")
1252
- t.flowCallbacks.onSetupPaymentMethodSuccess(n.result.payment_method_id);
1253
- else if (n.mode === "checkout")
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")
1254
721
  t.flowCallbacks.onCheckoutSuccess(
1255
- n.result.invoice_urls,
1256
- n.result.subscription_ids,
1257
- n.result.customer_id
722
+ r.result.invoice_urls,
723
+ r.result.subscription_ids,
724
+ r.result.customer_id
1258
725
  );
1259
726
  else
1260
- throw new Error(`Unhandled mode: ${n}`);
1261
- } catch (n) {
1262
- throw t.flowCallbacks.onCheckoutError(De(n)), n;
727
+ throw new Error(`Unhandled mode: ${r}`);
728
+ } catch (r) {
729
+ throw t.flowCallbacks.onCheckoutError(pe(r)), r;
1263
730
  }
1264
- }, es = (e) => async (t) => {
731
+ }, Lr = (e) => async (t) => {
1265
732
  try {
1266
733
  return await e(t);
1267
- } catch (n) {
1268
- const { err__: r } = ie("init-error-catcher");
1269
- return r(n), { isAvailable: !1, reason: De(n) };
734
+ } catch (r) {
735
+ const { err__: o } = J("init-error-catcher");
736
+ return o(r), { isAvailable: !1, reason: pe(r) };
1270
737
  }
1271
- }, ie = (e) => {
1272
- const t = (...r) => {
1273
- window.console.log(`${Oe.green.bold("ojs/")}${Oe.bold.gray(`${e}`)} `, ...r);
1274
- }, n = (...r) => {
1275
- window.console.error(`${Oe.red.bold("ojs/")}${Oe.bold.gray(`${e}`)} `, ...r);
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);
1276
743
  };
1277
744
  return {
1278
745
  log: t,
1279
- err: n,
746
+ err: r,
1280
747
  log__: t,
1281
- err__: n
748
+ err__: r
1282
749
  };
1283
- }, { log__: ts, err__: dn } = ie("common-cc"), mn = (e, t) => {
1284
- const n = Ee.safeParse(e);
1285
- if (!n.success) {
1286
- const r = n.error.format(), s = Ht(r);
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);
1287
754
  for (const [i, a] of Object.entries(s))
1288
755
  t(i, a, i);
1289
- throw dn("Got validation errors in non-CDE form fields", s), new Error("Got validation errors in non-CDE form fields");
756
+ throw kt("Got validation errors in non-CDE form fields", s), new Error("Got validation errors in non-CDE form fields");
1290
757
  }
1291
- return n.data;
1292
- }, ns = (e, t) => {
1293
- for (const n of e)
1294
- if (n.success === !1)
1295
- throw n.errors.forEach((r) => {
1296
- const s = qt.safeParse(r.elementType);
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);
1297
764
  if (!s.success)
1298
- dn(`Unknown field name in onValidationError: ${r.elementType}`);
765
+ kt(`Unknown field name in onValidationError: ${o.elementType}`);
1299
766
  else {
1300
767
  const i = s.data;
1301
- t(i, r.errors);
768
+ t(i, o.errors);
1302
769
  }
1303
- }), ts(`Error tokenizing card: got validation errors: ${JSON.stringify(n.errors)}`), new Error("Got validation errors while tokenizing card");
1304
- }, { err__: Je } = ie("commmon"), fn = (e) => {
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) => {
1305
772
  if (e.payment_methods.length !== 1)
1306
773
  throw new Error(`Expected exactly one payment method, got ${e.payment_methods.length}`);
1307
774
  return { payment_method_id: e.payment_methods[0].id };
1308
- }, rs = (e, t) => {
1309
- const n = e.find((r) => t.safeParse(r).success);
1310
- if (!n)
1311
- throw Je(`No CPMs found for model ${t}`), Je(e), Je("zodModel"), new Error(`No CPMs found for model ${t}`);
1312
- return t.parse(n);
1313
- }, { log__: k, err__: jt } = ie("common-cc"), { log__: Ft } = ie("stripe-cc"), os = un(
1314
- async ({ context: e, checkoutPaymentMethod: t, nonCdeFormInputs: n, flowCallbacks: r }) => {
1315
- var l;
1316
- k("├ Running common CC flow...", { checkoutPaymentMethod: t });
1317
- const s = Array.from(e.cdeConnections.values())[0], i = await Ce(s);
1318
- k(`├ Validating non-CDE form fields [Mode: ${i.mode}]`);
1319
- const a = mn(n, r.onValidationError);
1320
- k(`├ Tokenizing card info in CDE [Session: ${e.elementsSessionId}]`);
1321
- const c = await jo(e.cdeConnections, {
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(
781
+ async ({ context: e, checkoutPaymentMethod: t, nonCdeFormInputs: r, flowCallbacks: o }) => {
782
+ var d;
783
+ P("├ Running common CC flow...", { checkoutPaymentMethod: t });
784
+ const s = Array.from(e.cdeConnections.values())[0], i = await se(s);
785
+ P(`├ Validating non-CDE form fields [Mode: ${i.mode}]`);
786
+ const a = Tt(r, o.onValidationError);
787
+ P(`├ Tokenizing card info in CDE [Session: ${e.elementsSessionId}]`);
788
+ const c = await kr(e.cdeConnections, {
1322
789
  session_id: e.elementsSessionId
1323
790
  });
1324
- ns(c, r.onValidationError);
1325
- const d = {
791
+ Ur(c, o.onValidationError);
792
+ const l = {
1326
793
  session_id: e.elementsSessionId,
1327
794
  checkout_payment_method: t,
1328
795
  non_cde_form_fields: a
1329
796
  };
1330
797
  try {
1331
798
  if (i.mode === "setup") {
1332
- k(`├ Setting up payment method in CDE [Token: ${i.token}]`);
1333
- const u = await Fo(s, d);
1334
- return k(`╰ Setup completed successfully [PM ID: ${u.payment_method_id}]`), { mode: "setup", result: u };
799
+ 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 };
1335
802
  } else {
1336
- k(`├ Initial checkout flow. Checking out card info in CDE [Session: ${e.elementsSessionId}]`);
1337
- const u = await Pt(s, d);
1338
- return k("╰ Checkout completed successfully."), { mode: "checkout", result: u };
803
+ 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 };
1339
806
  }
1340
- } catch (u) {
1341
- if (u instanceof an && u.originalErrorMessage === "3DS_REQUIRED") {
1342
- k("├ Card requires 3DS, starting non-legacy payment flow");
1343
- const y = ((l = u.response.headers) == null ? void 0 : l["op-should-use-new-flow"]) === "true", f = await Ao(s, d);
1344
- if (k(`├ op-should-use-new-flow: ${y}`), k("├ Payment flow result:", f), y ? await as(f, e.baseUrl) : await cs(f), i.mode === "setup") {
1345
- k(`├ Confirming payment flow [cc_pm_id: ${f.cc_pm_id}]`);
1346
- const m = await ct(s, {
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, {
1347
814
  secure_token: i.token,
1348
- existing_cc_pm_id: f.cc_pm_id
815
+ existing_cc_pm_id: g.cc_pm_id
1349
816
  });
1350
- k("├ Confirm payment flow result received Result:", m);
1351
- const g = fn(m);
1352
- return k(`╰ Setup completed successfully [PM ID: ${g.payment_method_id}]`), { mode: "setup", result: g };
817
+ 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 };
1353
820
  } else {
1354
- k(`├ Checking out after 3DS flow [Flow: ${y ? "new" : "legacy"}]`);
1355
- const m = await Pt(s, {
1356
- ...d,
1357
- existing_cc_pm_id: f.cc_pm_id,
1358
- do_not_use_legacy_cc_flow: !y
821
+ P(`├ Checking out after 3DS flow [Flow: ${E ? "new" : "legacy"}]`);
822
+ const _ = await Xe(s, {
823
+ ...l,
824
+ existing_cc_pm_id: g.cc_pm_id,
825
+ do_not_use_legacy_cc_flow: !E
1359
826
  });
1360
- return k("╰ Checkout completed successfully."), { mode: "checkout", result: m };
827
+ return P("╰ Checkout completed successfully."), { mode: "checkout", result: _ };
1361
828
  }
1362
829
  }
1363
- throw jt("╰ Error checking out card info in CDE"), jt(u), u;
830
+ throw et("╰ Error checking out card info in CDE"), et(m), m;
1364
831
  }
1365
832
  }
1366
- ), ss = (e) => {
1367
- const t = e.required_user_actions.find((n) => n.type === "stripe_3ds");
833
+ ), Hr = (e) => {
834
+ const t = e.required_user_actions.find((r) => r.type === "stripe_3ds");
1368
835
  if (!t)
1369
836
  throw new Error("No stripe 3DS action found");
1370
- return Kt.parse(t);
1371
- }, is = (e) => {
1372
- const t = e.required_user_actions.find((n) => n.type === "airwallex_payment_consent");
837
+ return yt.parse(t);
838
+ }, Vr = (e) => {
839
+ const t = e.required_user_actions.find((r) => r.type === "airwallex_payment_consent");
1373
840
  if (!t)
1374
841
  throw new Error("No common 3DS action found");
1375
- return br.parse(t);
1376
- }, as = async (e, t) => {
1377
- const n = is(e);
1378
- k(`├ Using common 3DS flow [URL: ${n.redirect_url}]`);
1379
- const r = await qo({ url: n.redirect_url, baseUrl: t });
1380
- if (k(`╰ 3DS verification completed [Status: ${r}]`), r === Me.CANCELLED)
842
+ return zn.parse(t);
843
+ }, Kr = async (e, t) => {
844
+ const r = Vr(e);
845
+ 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)
1381
848
  throw new Error("3DS verification cancelled");
1382
- if (r === Me.FAILURE)
849
+ if (o === me.FAILURE)
1383
850
  throw new Error("3DS verification failed");
1384
- }, cs = async (e) => {
1385
- const t = ss(e);
1386
- Ft(`├ Using stripe 3DS flow [Client Secret: ${t.client_secret.substring(0, 8)}...]`), await Gt(t), Ft("╰ Stripe 3DS flow completed successfully");
1387
- }, { log__: F, err__: ls } = ie("stripe-pr"), us = o.object({
1388
- provider: o.union([o.literal("apple_pay"), o.literal("google_pay")]),
1389
- processor_name: o.literal("stripe"),
1390
- metadata: o.object({
1391
- stripe_pk: o.string()
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({
855
+ provider: n.union([n.literal("apple_pay"), n.literal("google_pay")]),
856
+ processor_name: n.literal("stripe"),
857
+ metadata: n.object({
858
+ stripe_pk: n.string()
1392
859
  })
1393
- }), ds = es(
860
+ }), Wr = Lr(
1394
861
  async ({ context: e }) => {
1395
- F("Checking if there are any CPMs for Stripe PR...");
1396
- const t = rs(e.checkoutPaymentMethods, us);
1397
- F("Initializing Stripe PR flow...");
1398
- const n = Array.from(e.cdeConnections.values())[0], r = await Ce(n), s = r.mode === "setup";
1399
- F("Getting initial preview amount");
1400
- const i = await cn(n, r.token, s, void 0), a = await vr(
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(
1401
868
  t.metadata.stripe_pk,
1402
869
  i.amountAtom,
1403
870
  i.currency,
1404
871
  s
1405
872
  );
1406
- F("Checking if can make payment");
873
+ T("Checking if can make payment");
1407
874
  const c = await a.canMakePayment();
1408
- return c === null ? (ls("canMakePayment returned null"), { isAvailable: !1, reason: "canMakePayment returned null" }) : (F("Stripe PR flow initialized successfully. Can make payment", c), {
875
+ return c === null ? (Zr("canMakePayment returned null"), { isAvailable: !1, reason: "canMakePayment returned null" }) : (T("Stripe PR flow initialized successfully. Can make payment", c), {
1409
876
  isAvailable: !0,
1410
877
  pr: a,
1411
878
  availableProviders: {
@@ -1414,217 +881,218 @@ const un = (e) => async (t) => {
1414
881
  }
1415
882
  });
1416
883
  }
1417
- ), ms = un(
884
+ ), Br = Rt(
1418
885
  async ({
1419
886
  context: e,
1420
887
  checkoutPaymentMethod: t,
1421
- nonCdeFormInputs: n,
1422
- flowCallbacks: r,
888
+ nonCdeFormInputs: r,
889
+ flowCallbacks: o,
1423
890
  customParams: s,
1424
891
  initResult: i
1425
892
  }) => {
1426
- if (F("Running Stripe PR flow..."), s.provider !== t.provider)
893
+ if (T("Running Stripe PR flow..."), s.provider !== t.provider)
1427
894
  throw new Error(`Provider mismatch. Expected ${s.provider}, got ${t.provider}`);
1428
895
  const a = Array.from(e.cdeConnections.values())[0], c = i.pr;
1429
- F("Validating non-CDE form fields");
1430
- const d = fs(n), l = mn(d, r.onValidationError);
1431
896
  if (s != null && s.overridePaymentRequest) {
1432
- const g = s.overridePaymentRequest;
1433
- F("Overriding PR amount with", g), ps(c, g.amount, g.pending);
897
+ const h = s.overridePaymentRequest;
898
+ T("Overriding PR amount with", h), Qr(c, h.amount, h.pending);
1434
899
  }
1435
- F("Showing PR dialog..."), c.show();
1436
- const u = await Sr(c);
1437
- F("PR dialog finished. Starting payment flow...");
1438
- const y = await To(a, {
1439
- fields: l,
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,
1440
907
  checkoutPaymentMethod: t
1441
- }), f = ys(y);
1442
- F("Confirming PR with Stripe..."), await Rr(f, u);
1443
- const m = await Ce(a);
1444
- if (m.mode === "setup") {
1445
- F("Confirming payment flow for setup...");
1446
- const g = await ct(a, {
1447
- secure_token: m.token
908
+ }), g = Xr(E);
909
+ T("Confirming PR with Stripe..."), await Jn(g, l);
910
+ const _ = await se(a);
911
+ if (_.mode === "setup") {
912
+ T("Confirming payment flow for setup...");
913
+ const h = await xe(a, {
914
+ secure_token: _.token
1448
915
  });
1449
- return { mode: "setup", result: fn(g) };
916
+ return { mode: "setup", result: At(h) };
1450
917
  } else {
1451
- F("Performing checkout...");
1452
- const g = {
1453
- secure_token: m.token,
918
+ T("Performing checkout...");
919
+ const h = {
920
+ secure_token: _.token,
1454
921
  payment_input: {
1455
922
  provider_type: t.provider
1456
923
  },
1457
- customer_email: l[U.EMAIL],
1458
- customer_zip_code: l[U.ZIP_CODE],
1459
- customer_country: l[U.COUNTRY],
1460
- promotion_code: l[U.PROMOTION_CODE],
1461
- line_items: m.line_items,
1462
- total_amount_atom: m.amount_total_atom,
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],
928
+ line_items: _.line_items,
929
+ total_amount_atom: _.amount_total_atom,
1463
930
  cancel_at_end: !1,
1464
931
  checkout_payment_method: t
1465
932
  };
1466
- return { mode: "checkout", result: await Do(a, g) };
933
+ return { mode: "checkout", result: await Ar(a, h) };
1467
934
  }
1468
935
  }
1469
- ), fs = (e) => {
1470
- const t = { ...e };
1471
- return t[U.ZIP_CODE] || (F("Overriding empty zip code (only for google pay and apple pay)"), t[U.ZIP_CODE] = "00000"), t;
1472
- }, ps = (e, t, n) => {
936
+ ), Gr = (e, t) => {
937
+ var a, c, l, d;
938
+ 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) => {
1473
941
  e.update({
1474
942
  total: {
1475
943
  amount: t.amountAtom,
1476
944
  label: "Total",
1477
- pending: n
945
+ pending: r
1478
946
  },
1479
947
  currency: t.currency
1480
948
  });
1481
- }, ys = (e) => {
949
+ }, Xr = (e) => {
1482
950
  if (e.required_user_actions.length !== 1)
1483
951
  throw new Error(`Error occurred.
1484
952
  Details: got ${e.required_user_actions.length} required user actions`);
1485
- return Er.parse(e.required_user_actions[0]);
1486
- }, Dt = (e, t, n) => {
1487
- const r = e.filter((s) => s.provider === t);
1488
- if (r.length === 0)
1489
- throw new Error(`No CPMs found with provider '${t}' and processor '${n}'`);
1490
- if (r.length !== 1)
1491
- throw new Error(`More than one CPM found with provider '${t}' and processor '${n}'`);
1492
- return r[0];
1493
- }, st = {
953
+ return Hn.parse(e.required_user_actions[0]);
954
+ }, nt = (e, t, r) => {
955
+ const o = e.filter((s) => s.provider === t);
956
+ if (o.length === 0)
957
+ throw new Error(`No CPMs found with provider '${t}' and processor '${r}'`);
958
+ if (o.length !== 1)
959
+ throw new Error(`More than one CPM found with provider '${t}' and processor '${r}'`);
960
+ return o[0];
961
+ }, Fe = {
1494
962
  // ✋ Note: For flows that require initialization, please add them to `init-flows.ts`
1495
963
  // Stripe
1496
964
  commonCC: {
1497
- run: os
965
+ run: zr
1498
966
  },
1499
967
  stripePR: {
1500
- init: ds,
1501
- run: ms
968
+ init: Wr,
969
+ run: Br
1502
970
  }
1503
971
  // 👉 Add more flows here
1504
972
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1505
973
  };
1506
- function pn(e) {
974
+ function It(e) {
1507
975
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
1508
976
  }
1509
- var Le = {};
1510
- Object.defineProperty(Le, "__esModule", {
977
+ var he = {};
978
+ Object.defineProperty(he, "__esModule", {
1511
979
  value: !0
1512
980
  });
1513
- Le.Observable = void 0;
1514
- const yn = (e) => !!Symbol[e], lt = (e) => yn(e) ? Symbol[e] : "@@" + e, gs = lt("iterator"), it = lt("observable"), gn = lt("species");
1515
- function Fe(e, t) {
1516
- let n = e[t];
1517
- if (n != null) {
1518
- if (typeof n != "function") throw new TypeError(n + " is not a function");
1519
- return n;
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) {
984
+ let r = e[t];
985
+ if (r != null) {
986
+ if (typeof r != "function") throw new TypeError(r + " is not a function");
987
+ return r;
1520
988
  }
1521
989
  }
1522
- function he(e) {
990
+ function ne(e) {
1523
991
  let t = e.constructor;
1524
- return t !== void 0 && (t = t[gn], t === null && (t = void 0)), t !== void 0 ? t : Ue;
992
+ return t !== void 0 && (t = t[Mt], t === null && (t = void 0)), t !== void 0 ? t : we;
1525
993
  }
1526
- function hs(e) {
1527
- return e instanceof Ue;
994
+ function to(e) {
995
+ return e instanceof we;
1528
996
  }
1529
- function fe(e) {
1530
- fe.log ? fe.log(e) : setTimeout(() => {
997
+ function X(e) {
998
+ X.log ? X.log(e) : setTimeout(() => {
1531
999
  throw e;
1532
1000
  });
1533
1001
  }
1534
- function Ae(e) {
1002
+ function le(e) {
1535
1003
  Promise.resolve().then(() => {
1536
1004
  try {
1537
1005
  e();
1538
1006
  } catch (t) {
1539
- fe(t);
1007
+ X(t);
1540
1008
  }
1541
1009
  });
1542
1010
  }
1543
- function hn(e) {
1011
+ function Ft(e) {
1544
1012
  let t = e._cleanup;
1545
1013
  if (t !== void 0 && (e._cleanup = void 0, !!t))
1546
1014
  try {
1547
1015
  if (typeof t == "function")
1548
1016
  t();
1549
1017
  else {
1550
- let n = Fe(t, "unsubscribe");
1551
- n && n.call(t);
1018
+ let r = fe(t, "unsubscribe");
1019
+ r && r.call(t);
1552
1020
  }
1553
- } catch (n) {
1554
- fe(n);
1021
+ } catch (r) {
1022
+ X(r);
1555
1023
  }
1556
1024
  }
1557
- function at(e) {
1025
+ function Ne(e) {
1558
1026
  e._observer = void 0, e._queue = void 0, e._state = "closed";
1559
1027
  }
1560
- function _s(e) {
1028
+ function no(e) {
1561
1029
  let t = e._queue;
1562
1030
  if (t) {
1563
1031
  e._queue = void 0, e._state = "ready";
1564
- for (let n = 0; n < t.length && (_n(e, t[n].type, t[n].value), e._state !== "closed"); ++n)
1032
+ for (let r = 0; r < t.length && (Dt(e, t[r].type, t[r].value), e._state !== "closed"); ++r)
1565
1033
  ;
1566
1034
  }
1567
1035
  }
1568
- function _n(e, t, n) {
1036
+ function Dt(e, t, r) {
1569
1037
  e._state = "running";
1570
- let r = e._observer;
1038
+ let o = e._observer;
1571
1039
  try {
1572
- let s = Fe(r, t);
1040
+ let s = fe(o, t);
1573
1041
  switch (t) {
1574
1042
  case "next":
1575
- s && s.call(r, n);
1043
+ s && s.call(o, r);
1576
1044
  break;
1577
1045
  case "error":
1578
- if (at(e), s) s.call(r, n);
1579
- else throw n;
1046
+ if (Ne(e), s) s.call(o, r);
1047
+ else throw r;
1580
1048
  break;
1581
1049
  case "complete":
1582
- at(e), s && s.call(r);
1050
+ Ne(e), s && s.call(o);
1583
1051
  break;
1584
1052
  }
1585
1053
  } catch (s) {
1586
- fe(s);
1054
+ X(s);
1587
1055
  }
1588
- e._state === "closed" ? hn(e) : e._state === "running" && (e._state = "ready");
1056
+ e._state === "closed" ? Ft(e) : e._state === "running" && (e._state = "ready");
1589
1057
  }
1590
- function Qe(e, t, n) {
1058
+ function Ie(e, t, r) {
1591
1059
  if (e._state !== "closed") {
1592
1060
  if (e._state === "buffering") {
1593
1061
  e._queue.push({
1594
1062
  type: t,
1595
- value: n
1063
+ value: r
1596
1064
  });
1597
1065
  return;
1598
1066
  }
1599
1067
  if (e._state !== "ready") {
1600
1068
  e._state = "buffering", e._queue = [{
1601
1069
  type: t,
1602
- value: n
1603
- }], Ae(() => _s(e));
1070
+ value: r
1071
+ }], le(() => no(e));
1604
1072
  return;
1605
1073
  }
1606
- _n(e, t, n);
1074
+ Dt(e, t, r);
1607
1075
  }
1608
1076
  }
1609
- class ws {
1610
- constructor(t, n) {
1077
+ class ro {
1078
+ constructor(t, r) {
1611
1079
  this._cleanup = void 0, this._observer = t, this._queue = void 0, this._state = "initializing";
1612
- let r = this, s = {
1080
+ let o = this, s = {
1613
1081
  get closed() {
1614
- return r._state === "closed";
1082
+ return o._state === "closed";
1615
1083
  },
1616
1084
  next(i) {
1617
- Qe(r, "next", i);
1085
+ Ie(o, "next", i);
1618
1086
  },
1619
1087
  error(i) {
1620
- Qe(r, "error", i);
1088
+ Ie(o, "error", i);
1621
1089
  },
1622
1090
  complete() {
1623
- Qe(r, "complete");
1091
+ Ie(o, "complete");
1624
1092
  }
1625
1093
  };
1626
1094
  try {
1627
- this._cleanup = n.call(void 0, s);
1095
+ this._cleanup = r.call(void 0, s);
1628
1096
  } catch (i) {
1629
1097
  s.error(i);
1630
1098
  }
@@ -1634,12 +1102,12 @@ class ws {
1634
1102
  return this._state === "closed";
1635
1103
  }
1636
1104
  unsubscribe() {
1637
- this._state !== "closed" && (at(this), hn(this));
1105
+ this._state !== "closed" && (Ne(this), Ft(this));
1638
1106
  }
1639
1107
  }
1640
- let Ue = class Te {
1108
+ let we = class ue {
1641
1109
  constructor(t) {
1642
- if (!(this instanceof Te)) throw new TypeError("Observable cannot be called as a function");
1110
+ if (!(this instanceof ue)) throw new TypeError("Observable cannot be called as a function");
1643
1111
  if (typeof t != "function") throw new TypeError("Observable initializer must be a function");
1644
1112
  this._subscriber = t;
1645
1113
  }
@@ -1648,112 +1116,112 @@ let Ue = class Te {
1648
1116
  next: t,
1649
1117
  error: arguments[1],
1650
1118
  complete: arguments[2]
1651
- }), new ws(t, this._subscriber);
1119
+ }), new ro(t, this._subscriber);
1652
1120
  }
1653
1121
  forEach(t) {
1654
- return new Promise((n, r) => {
1122
+ return new Promise((r, o) => {
1655
1123
  if (typeof t != "function") {
1656
- r(new TypeError(t + " is not a function"));
1124
+ o(new TypeError(t + " is not a function"));
1657
1125
  return;
1658
1126
  }
1659
1127
  function s() {
1660
- i.unsubscribe(), n();
1128
+ i.unsubscribe(), r();
1661
1129
  }
1662
1130
  let i = this.subscribe({
1663
1131
  next(a) {
1664
1132
  try {
1665
1133
  t(a, s);
1666
1134
  } catch (c) {
1667
- r(c), i.unsubscribe();
1135
+ o(c), i.unsubscribe();
1668
1136
  }
1669
1137
  },
1670
- error: r,
1671
- complete: n
1138
+ error: o,
1139
+ complete: r
1672
1140
  });
1673
1141
  });
1674
1142
  }
1675
1143
  map(t) {
1676
1144
  if (typeof t != "function") throw new TypeError(t + " is not a function");
1677
- let n = he(this);
1678
- return new n((r) => this.subscribe({
1145
+ let r = ne(this);
1146
+ return new r((o) => this.subscribe({
1679
1147
  next(s) {
1680
1148
  try {
1681
1149
  s = t(s);
1682
1150
  } catch (i) {
1683
- return r.error(i);
1151
+ return o.error(i);
1684
1152
  }
1685
- r.next(s);
1153
+ o.next(s);
1686
1154
  },
1687
1155
  error(s) {
1688
- r.error(s);
1156
+ o.error(s);
1689
1157
  },
1690
1158
  complete() {
1691
- r.complete();
1159
+ o.complete();
1692
1160
  }
1693
1161
  }));
1694
1162
  }
1695
1163
  filter(t) {
1696
1164
  if (typeof t != "function") throw new TypeError(t + " is not a function");
1697
- let n = he(this);
1698
- return new n((r) => this.subscribe({
1165
+ let r = ne(this);
1166
+ return new r((o) => this.subscribe({
1699
1167
  next(s) {
1700
1168
  try {
1701
1169
  if (!t(s)) return;
1702
1170
  } catch (i) {
1703
- return r.error(i);
1171
+ return o.error(i);
1704
1172
  }
1705
- r.next(s);
1173
+ o.next(s);
1706
1174
  },
1707
1175
  error(s) {
1708
- r.error(s);
1176
+ o.error(s);
1709
1177
  },
1710
1178
  complete() {
1711
- r.complete();
1179
+ o.complete();
1712
1180
  }
1713
1181
  }));
1714
1182
  }
1715
1183
  reduce(t) {
1716
1184
  if (typeof t != "function") throw new TypeError(t + " is not a function");
1717
- let n = he(this), r = arguments.length > 1, s = !1, a = arguments[1];
1718
- return new n((c) => this.subscribe({
1719
- next(d) {
1720
- let l = !s;
1721
- if (s = !0, !l || r)
1185
+ let r = ne(this), o = arguments.length > 1, s = !1, a = arguments[1];
1186
+ return new r((c) => this.subscribe({
1187
+ next(l) {
1188
+ let d = !s;
1189
+ if (s = !0, !d || o)
1722
1190
  try {
1723
- a = t(a, d);
1724
- } catch (u) {
1725
- return c.error(u);
1191
+ a = t(a, l);
1192
+ } catch (m) {
1193
+ return c.error(m);
1726
1194
  }
1727
1195
  else
1728
- a = d;
1196
+ a = l;
1729
1197
  },
1730
- error(d) {
1731
- c.error(d);
1198
+ error(l) {
1199
+ c.error(l);
1732
1200
  },
1733
1201
  complete() {
1734
- if (!s && !r) return c.error(new TypeError("Cannot reduce an empty sequence"));
1202
+ if (!s && !o) return c.error(new TypeError("Cannot reduce an empty sequence"));
1735
1203
  c.next(a), c.complete();
1736
1204
  }
1737
1205
  }));
1738
1206
  }
1739
1207
  async all() {
1740
1208
  let t = [];
1741
- return await this.forEach((n) => t.push(n)), t;
1209
+ return await this.forEach((r) => t.push(r)), t;
1742
1210
  }
1743
1211
  concat(...t) {
1744
- let n = he(this);
1745
- return new n((r) => {
1212
+ let r = ne(this);
1213
+ return new r((o) => {
1746
1214
  let s, i = 0;
1747
1215
  function a(c) {
1748
1216
  s = c.subscribe({
1749
- next(d) {
1750
- r.next(d);
1217
+ next(l) {
1218
+ o.next(l);
1751
1219
  },
1752
- error(d) {
1753
- r.error(d);
1220
+ error(l) {
1221
+ o.error(l);
1754
1222
  },
1755
1223
  complete() {
1756
- i === t.length ? (s = void 0, r.complete()) : a(n.from(t[i++]));
1224
+ i === t.length ? (s = void 0, o.complete()) : a(r.from(t[i++]));
1757
1225
  }
1758
1226
  });
1759
1227
  }
@@ -1764,70 +1232,70 @@ let Ue = class Te {
1764
1232
  }
1765
1233
  flatMap(t) {
1766
1234
  if (typeof t != "function") throw new TypeError(t + " is not a function");
1767
- let n = he(this);
1768
- return new n((r) => {
1235
+ let r = ne(this);
1236
+ return new r((o) => {
1769
1237
  let s = [], i = this.subscribe({
1770
1238
  next(c) {
1771
1239
  if (t)
1772
1240
  try {
1773
1241
  c = t(c);
1774
- } catch (l) {
1775
- return r.error(l);
1242
+ } catch (d) {
1243
+ return o.error(d);
1776
1244
  }
1777
- let d = n.from(c).subscribe({
1778
- next(l) {
1779
- r.next(l);
1245
+ let l = r.from(c).subscribe({
1246
+ next(d) {
1247
+ o.next(d);
1780
1248
  },
1781
- error(l) {
1782
- r.error(l);
1249
+ error(d) {
1250
+ o.error(d);
1783
1251
  },
1784
1252
  complete() {
1785
- let l = s.indexOf(d);
1786
- l >= 0 && s.splice(l, 1), a();
1253
+ let d = s.indexOf(l);
1254
+ d >= 0 && s.splice(d, 1), a();
1787
1255
  }
1788
1256
  });
1789
- s.push(d);
1257
+ s.push(l);
1790
1258
  },
1791
1259
  error(c) {
1792
- r.error(c);
1260
+ o.error(c);
1793
1261
  },
1794
1262
  complete() {
1795
1263
  a();
1796
1264
  }
1797
1265
  });
1798
1266
  function a() {
1799
- i.closed && s.length === 0 && r.complete();
1267
+ i.closed && s.length === 0 && o.complete();
1800
1268
  }
1801
1269
  return () => {
1802
1270
  s.forEach((c) => c.unsubscribe()), i.unsubscribe();
1803
1271
  };
1804
1272
  });
1805
1273
  }
1806
- [it]() {
1274
+ [De]() {
1807
1275
  return this;
1808
1276
  }
1809
1277
  static from(t) {
1810
- let n = typeof this == "function" ? this : Te;
1278
+ let r = typeof this == "function" ? this : ue;
1811
1279
  if (t == null) throw new TypeError(t + " is not an object");
1812
- let r = Fe(t, it);
1813
- if (r) {
1814
- let s = r.call(t);
1280
+ let o = fe(t, De);
1281
+ if (o) {
1282
+ let s = o.call(t);
1815
1283
  if (Object(s) !== s) throw new TypeError(s + " is not an object");
1816
- return hs(s) && s.constructor === n ? s : new n((i) => s.subscribe(i));
1284
+ return to(s) && s.constructor === r ? s : new r((i) => s.subscribe(i));
1817
1285
  }
1818
- if (yn("iterator") && (r = Fe(t, gs), r))
1819
- return new n((s) => {
1820
- Ae(() => {
1286
+ if (jt("iterator") && (o = fe(t, eo), o))
1287
+ return new r((s) => {
1288
+ le(() => {
1821
1289
  if (!s.closed) {
1822
- for (let i of r.call(t))
1290
+ for (let i of o.call(t))
1823
1291
  if (s.next(i), s.closed) return;
1824
1292
  s.complete();
1825
1293
  }
1826
1294
  });
1827
1295
  });
1828
1296
  if (Array.isArray(t))
1829
- return new n((s) => {
1830
- Ae(() => {
1297
+ return new r((s) => {
1298
+ le(() => {
1831
1299
  if (!s.closed) {
1832
1300
  for (let i = 0; i < t.length; ++i)
1833
1301
  if (s.next(t[i]), s.closed) return;
@@ -1838,446 +1306,446 @@ let Ue = class Te {
1838
1306
  throw new TypeError(t + " is not observable");
1839
1307
  }
1840
1308
  static of(...t) {
1841
- let n = typeof this == "function" ? this : Te;
1842
- return new n((r) => {
1843
- Ae(() => {
1844
- if (!r.closed) {
1309
+ let r = typeof this == "function" ? this : ue;
1310
+ return new r((o) => {
1311
+ le(() => {
1312
+ if (!o.closed) {
1845
1313
  for (let s = 0; s < t.length; ++s)
1846
- if (r.next(t[s]), r.closed) return;
1847
- r.complete();
1314
+ if (o.next(t[s]), o.closed) return;
1315
+ o.complete();
1848
1316
  }
1849
1317
  });
1850
1318
  });
1851
1319
  }
1852
- static get [gn]() {
1320
+ static get [Mt]() {
1853
1321
  return this;
1854
1322
  }
1855
1323
  };
1856
- Le.Observable = Ue;
1857
- Object.defineProperty(Ue, Symbol("extensions"), {
1324
+ he.Observable = we;
1325
+ Object.defineProperty(we, Symbol("extensions"), {
1858
1326
  value: {
1859
- symbol: it,
1860
- hostReportError: fe
1327
+ symbol: De,
1328
+ hostReportError: X
1861
1329
  },
1862
1330
  configurable: !0
1863
1331
  });
1864
- var bs = Le.Observable;
1865
- const Es = /* @__PURE__ */ pn(bs), { log__: Cs, err__: vs } = ie("init-flows"), Ss = (e) => ({
1332
+ var oo = he.Observable;
1333
+ const so = /* @__PURE__ */ It(oo), { log__: io, err__: ao } = J("init-flows"), co = (e) => ({
1866
1334
  // Stripe PR
1867
- stripePR: Ps("stripePR", st.stripePR.init({ context: e }))
1335
+ stripePR: lo("stripePR", Fe.stripePR.init({ context: e }))
1868
1336
  // 👉 Add initialization flows here
1869
- }), Ps = (e, t) => {
1870
- const n = new Es((r) => {
1871
- r.next({ status: "loading" }), t.then((s) => {
1872
- r.next({ status: "loaded", result: s });
1337
+ }), lo = (e, t) => {
1338
+ const r = new so((o) => {
1339
+ o.next({ status: "loading" }), t.then((s) => {
1340
+ o.next({ status: "loaded", result: s });
1873
1341
  }).catch((s) => {
1874
- r.next({ status: "error", message: s.message });
1342
+ o.next({ status: "error", message: s.message });
1875
1343
  });
1876
1344
  });
1877
- return n.subscribe({
1878
- next: (r) => {
1879
- Cs(`${e} flow result`, r);
1345
+ return r.subscribe({
1346
+ next: (o) => {
1347
+ io(`${e} flow result`, o);
1880
1348
  },
1881
- error: (r) => {
1882
- throw vs(`${e} flow initialization error:
1883
- ${JSON.stringify(r)}`), r;
1349
+ error: (o) => {
1350
+ throw ao(`${e} flow initialization error:
1351
+ ${JSON.stringify(o)}`), o;
1884
1352
  }
1885
- }), n;
1886
- }, ke = {
1353
+ }), r;
1354
+ }, ce = {
1887
1355
  isLoading: !0,
1888
1356
  isAvailable: !1,
1889
1357
  startFlow: async () => {
1890
1358
  }
1891
- }, xt = {
1359
+ }, rt = {
1892
1360
  isLoading: !1,
1893
1361
  isAvailable: !1,
1894
1362
  startFlow: async () => {
1895
1363
  }
1896
1364
  };
1897
- var ut = { exports: {} }, Rs = xn;
1898
- function wn(e, t, n) {
1899
- var r = typeof t == "function";
1900
- Rs.useEffect(function() {
1365
+ var $e = { exports: {} }, uo = rn;
1366
+ function Nt(e, t, r) {
1367
+ var o = typeof t == "function";
1368
+ uo.useEffect(function() {
1901
1369
  var s, i = !0, a = e(function() {
1902
1370
  return i;
1903
1371
  });
1904
1372
  return Promise.resolve(a).then(function(c) {
1905
1373
  s = c;
1906
1374
  }), function() {
1907
- i = !1, r && t(s);
1375
+ i = !1, o && t(s);
1908
1376
  };
1909
- }, r ? n : t);
1377
+ }, o ? r : t);
1910
1378
  }
1911
- ut.exports = wn;
1912
- ut.exports.useAsyncEffect = wn;
1913
- var Os = ut.exports;
1914
- const $t = /* @__PURE__ */ pn(Os);
1915
- function ks(e, t = 0) {
1916
- const n = _e(!1), r = _e(), s = _e(e), i = se(() => n.current, []), a = se(() => {
1917
- n.current = !1, r.current && clearTimeout(r.current), r.current = setTimeout(() => {
1918
- n.current = !0, s.current();
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(() => {
1385
+ r.current = !1, o.current && clearTimeout(o.current), o.current = setTimeout(() => {
1386
+ r.current = !0, s.current();
1919
1387
  }, t);
1920
- }, [t]), c = se(() => {
1921
- n.current = null, r.current && clearTimeout(r.current);
1388
+ }, [t]), c = Z(() => {
1389
+ r.current = null, o.current && clearTimeout(o.current);
1922
1390
  }, []);
1923
- return G(() => {
1391
+ return q(() => {
1924
1392
  s.current = e;
1925
- }, [e]), G(() => (a(), c), [t]), [i, c, a];
1393
+ }, [e]), q(() => (a(), c), [t]), [i, c, a];
1926
1394
  }
1927
- function As(e, t = 0, n = []) {
1928
- const [r, s, i] = ks(e, t);
1929
- return G(i, n), [r, s];
1395
+ function po(e, t = 0, r = []) {
1396
+ const [o, s, i] = fo(e, t);
1397
+ return q(i, r), [o, s];
1930
1398
  }
1931
- const Ts = (e, t, n, r) => {
1932
- const [s, i] = E(""), [a, c] = E(""), [d, l] = E(null), [u, y] = E(!1), [f, m] = E(null);
1933
- return $t(async () => {
1934
- if (!r || !e)
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 () => {
1402
+ if (!o || !e)
1935
1403
  return;
1936
- const g = await Io(r, U.PROMOTION_CODE);
1937
- g == null || g.addEventListener("input", () => {
1938
- y(!0), m(null), i(g.value);
1404
+ const h = await Or(o, C.PROMOTION_CODE);
1405
+ h == null || h.addEventListener("input", () => {
1406
+ E(!0), _(null), i(h.value);
1939
1407
  });
1940
- }, [!!r, e]), As(
1408
+ }, [!!o, e]), po(
1941
1409
  () => {
1942
1410
  e && c(s);
1943
1411
  },
1944
1412
  1e3,
1945
1413
  [s, e]
1946
- ), $t(
1947
- async (g) => {
1414
+ ), ot(
1415
+ async (h) => {
1948
1416
  try {
1949
- if (!t || !n || !e)
1417
+ if (!t || !r || !e)
1950
1418
  return;
1951
- const C = (await Ce(t)).mode === "setup", x = await cn(t, n, C, a);
1952
- g() && (m(null), l(x));
1953
- } catch (v) {
1954
- g() && m(De(v));
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));
1955
1423
  } finally {
1956
- g() && y(!1);
1424
+ h() && E(!1);
1957
1425
  }
1958
1426
  },
1959
- [!t, !n, a, e]
1427
+ [!t, !r, a, e]
1960
1428
  ), {
1961
- amount: d,
1962
- isLoading: u,
1963
- error: f
1429
+ amount: l,
1430
+ isLoading: m,
1431
+ error: g
1964
1432
  };
1965
- }, bn = (e = {}) => {
1966
- const [t, n] = E(e), r = ue(
1433
+ }, xt = (e = {}) => {
1434
+ const [t, r] = w(e), o = Q(
1967
1435
  () => ({
1968
1436
  set: (i, a) => {
1969
- n((c) => ({
1437
+ r((c) => ({
1970
1438
  ...c,
1971
1439
  [i]: a
1972
1440
  }));
1973
1441
  },
1974
1442
  setAll: (i) => {
1975
- n(i);
1443
+ r(i);
1976
1444
  },
1977
1445
  remove: (i) => {
1978
- n((a) => {
1979
- const { [i]: c, ...d } = a;
1980
- return d;
1446
+ r((a) => {
1447
+ const { [i]: c, ...l } = a;
1448
+ return l;
1981
1449
  });
1982
1450
  },
1983
- reset: () => n(e)
1451
+ reset: () => r(e)
1984
1452
  }),
1985
1453
  // eslint-disable-next-line react-hooks/exhaustive-deps
1986
- [n]
1454
+ [r]
1987
1455
  ), s = {
1988
- get: se((i) => t[i], [t]),
1989
- ...r
1456
+ get: Z((i) => t[i], [t]),
1457
+ ...o
1990
1458
  };
1991
1459
  return [t, s];
1992
- }, Is = () => {
1993
- const [e, t] = bn({
1460
+ }, _o = () => {
1461
+ const [e, t] = xt({
1994
1462
  card: void 0,
1995
1463
  "card-cvc": void 0,
1996
1464
  "card-expiry": void 0,
1997
1465
  "card-number": void 0
1998
- }), n = Object.values(e).filter((r) => r !== void 0)[0] ?? null;
1466
+ }), r = Object.values(e).filter((o) => o !== void 0)[0] ?? null;
1999
1467
  return {
2000
1468
  cdeConns: e,
2001
- anyCdeConn: n,
2002
- connectToCdeIframe: async (r, s) => {
2003
- t.set(r, await oo(s));
1469
+ anyCdeConn: r,
1470
+ connectToCdeIframe: async (o, s) => {
1471
+ t.set(o, await tr(s));
2004
1472
  }
2005
1473
  };
2006
- }, Ms = (e) => {
2007
- const t = e.replace("ojs-", "").replace("-element", ""), n = Zn.safeParse(t);
2008
- if (!n.success)
1474
+ }, go = (e) => {
1475
+ const t = e.replace("ojs-", "").replace("-element", ""), r = gn.safeParse(t);
1476
+ if (!r.success)
2009
1477
  throw new Error(
2010
1478
  `Invalid element id: ${e}, it needs to be in the format "ojs-{elementType}-element" (e.g. "ojs-card-number-element")`
2011
1479
  );
2012
- return n.data;
2013
- }, xs = (e) => {
1480
+ return r.data;
1481
+ }, Po = (e) => {
2014
1482
  const {
2015
1483
  children: t,
2016
- checkoutSecureToken: n,
2017
- className: r,
1484
+ checkoutSecureToken: r,
1485
+ className: o,
2018
1486
  onFocus: s,
2019
1487
  onBlur: i,
2020
1488
  onChange: a,
2021
1489
  onLoad: c,
2022
- onLoadError: d,
2023
- onValidationError: l,
2024
- onCheckoutStarted: u,
2025
- onCheckoutSuccess: y,
2026
- onCheckoutError: f,
2027
- onSetupPaymentMethodSuccess: m,
2028
- baseUrl: g,
2029
- enableDynamicPreviews: v
2030
- } = e, C = g ?? Un, [x, $] = E(void 0), [S, Z] = E([]), [W, pe] = E("1px"), [te, En] = E(!1), [B, qe] = E(void 0), [dt, ne] = E(!1), [re, Cn] = E([]), [ye, vn] = E({}), [mt, Se] = E(0), [ft, J] = E(!1), [K, Sn] = E(void 0), [pt, Pn] = E(void 0), [yt, Rn] = E(void 0), [Y, On] = E(void 0), [ze] = E(void 0), ae = ue(() => `opjs-form-${Zt()}`, []), D = _e(null), { cdeConns: gt, anyCdeConn: ce, connectToCdeIframe: kn } = Is(), [An, Tn] = E(null), [ht, le] = bn({
2031
- apple_pay: ke,
2032
- google_pay: ke
1490
+ onLoadError: l,
1491
+ onValidationError: d,
1492
+ onCheckoutStarted: m,
1493
+ onCheckoutSuccess: E,
1494
+ onCheckoutError: g,
1495
+ 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
2033
1501
  });
2034
- G(() => {
2035
- const p = { version: "0.1.6", release_version: "0.1.6-alpha.7c15e03" };
2036
- window.ojs_version = p;
1502
+ q(() => {
1503
+ const u = { version: "0.1.7", release_version: "0.1.7" };
1504
+ window.ojs_version = u;
2037
1505
  }, []);
2038
- const In = Ts(
2039
- v ?? !1,
2040
- ce,
2041
- n,
2042
- D.current
2043
- ), Ve = se(
2044
- (p) => {
2045
- if (p.origin !== C || !p.source) return;
2046
- const N = p.source;
2047
- if (!$o(p.data))
1506
+ const Qt = yo(
1507
+ I ?? !1,
1508
+ B,
1509
+ r,
1510
+ 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))
2048
1516
  return;
2049
- const j = JSON.parse(p.data), _ = Fr(j), Q = _.elementId;
2050
- if (_.formId !== ae || !Q || _.nonce in S)
1517
+ const A = JSON.parse(u.data), p = Qn(A), H = p.elementId;
1518
+ if (p.formId !== W || !H || p.nonce in Ue)
2051
1519
  return;
2052
- Z((M) => [...M, _.nonce]);
2053
- const w = _.payload, I = w.type;
2054
- if (I === h.enum.LAYOUT) {
2055
- const M = w.height ? `${w.height}px` : "100%";
2056
- pe(M);
2057
- } else if (I === h.enum.FOCUS && s)
2058
- s(_.elementId);
2059
- else if (I === h.enum.BLUR && i)
2060
- i(_.elementId);
2061
- else if (I === h.enum.CHANGE && a)
2062
- a(_.elementId);
2063
- else if (I === h.enum.LOADED) {
2064
- const M = re.find((R) => R.contentWindow === N);
2065
- if (ne(!1), !M)
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)
2066
1534
  return;
2067
- vn((R) => ({ ...R, [Q]: N })), Rn(w.totalAmountAtoms), Pn(w.currency), On(w.checkoutPaymentMethods), K || Sn(w.sessionId);
2068
- } else if (I === h.enum.TOKENIZE_STARTED)
2069
- ne(!0);
2070
- else if (I === h.enum.CHECKOUT_STARTED)
2071
- u && u();
2072
- else if (I === h.enum.PAYMENT_FLOW_STARTED) {
2073
- if (!B)
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)
2074
1542
  throw new Error("extraData not populated");
2075
- if (!ce)
1543
+ if (!B)
2076
1544
  throw new Error("Not connected to CDE");
2077
1545
  (async () => {
2078
- const R = w.nextActionMetadata.type;
2079
- if (R !== void 0) if (R === "stripe_3ds")
2080
- await Or(w);
2081
- else if (R === "stripe_payment_request") {
2082
- if (!ze)
1546
+ const S = y.nextActionMetadata.type;
1547
+ if (S !== void 0) if (S === "stripe_3ds")
1548
+ await Wn(y);
1549
+ else if (S === "stripe_payment_request") {
1550
+ if (!Pe)
2083
1551
  throw new Error("Stripe PM not set");
2084
- await Pr(w, ze);
1552
+ await Zn(y, Pe);
2085
1553
  } else
2086
- throw new Error(`Unknown next action type: ${R}`);
2087
- const L = await Ce(ce);
2088
- if (L.mode === "setup") {
2089
- const { payment_methods: q } = await ct(ce, {
2090
- secure_token: L.token,
2091
- existing_cc_pm_id: B.existingCCPMId
1554
+ 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
2092
1560
  });
2093
- if (q.length !== 1)
2094
- throw new Error(`Expected exactly one payment method, got ${q.length}`);
2095
- return ne(!1), Se(0), J(!1), m && m(q[0].id), {
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), {
2096
1564
  proceedToCheckout: !1
2097
1565
  };
2098
1566
  } else
2099
1567
  return {
2100
1568
  proceedToCheckout: !0
2101
1569
  };
2102
- })().then(({ proceedToCheckout: R }) => {
2103
- var q;
2104
- if (!R)
1570
+ })().then(({ proceedToCheckout: S }) => {
1571
+ var N;
1572
+ if (!S)
2105
1573
  return;
2106
- let L;
2107
- if (B.checkoutPaymentMethod.provider === "credit_card" && (L = (q = w.startPFMetadata) == null ? void 0 : q.cc_pm_id, !L))
1574
+ let F;
1575
+ if (D.checkoutPaymentMethod.provider === "credit_card" && (F = (N = y.startPFMetadata) == null ? void 0 : N.cc_pm_id, !F))
2108
1576
  throw new Error("CC PM ID not found");
2109
- Ze(
2110
- N,
2111
- ae,
2112
- Q,
2113
- { ...B, type: "CHECKOUT", doNotUseLegacyCCFlow: !0, existingCCPMId: L },
2114
- C
2115
- ), J(!0), qe(void 0), u && u();
2116
- }).catch((R) => {
2117
- const L = De(R);
2118
- ne(!1), J(!1), f && f(L);
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();
1584
+ }).catch((S) => {
1585
+ const F = pe(S);
1586
+ K(!1), z(!1), g && g(F);
2119
1587
  });
2120
- } else if (I === h.enum.TOKENIZE_SUCCESS && B) {
2121
- const M = mt + 1, R = M === Object.keys(ye).length;
2122
- !ft && (R || w.isReadyForCheckout) ? (Ze(N, ae, Q, B, C), J(!0), qe(void 0)) : Se(M);
2123
- } else if (I === h.enum.CHECKOUT_SUCCESS)
2124
- ne(!1), Se(0), J(!1), y && y(w.invoiceUrls, w.subscriptionIds, w.customerId);
2125
- else if (I === h.enum.SETUP_PAYMENT_METHOD_SUCCESS)
2126
- ne(!1), Se(0), J(!1), m && m(w.paymentMethodId);
2127
- else if (I === h.enum.LOAD_ERROR)
2128
- d && d(w.message);
2129
- else if (I === h.enum.VALIDATION_ERROR) {
2130
- const M = B == null ? void 0 : B.checkoutPaymentMethod.provider;
2131
- (M === "credit_card" || M === void 0) && l && l(w.elementType, w.errors, Q);
2132
- } else if (I === h.enum.TOKENIZE_ERROR || I === h.enum.CHECKOUT_ERROR)
2133
- if (w.message === "3DS_REQUIRED") {
2134
- const M = Y == null ? void 0 : Y.find((R) => R.provider === "credit_card");
2135
- if (!K || !D.current || !l || !M) return;
2136
- for (const [R, L] of Object.entries(ye)) {
2137
- if (!L) continue;
2138
- const q = jr(
2139
- h.enum.START_PAYMENT_FLOW,
2140
- K,
2141
- D.current,
2142
- l,
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,
1608
+ $,
1609
+ j.current,
1610
+ d,
2143
1611
  // Only stripe supports frontend 3DS right now,
2144
1612
  // so we pass processor_name: 'stripe' to tell delegator to only use stripe
2145
- { ...M, processor_name: "stripe" },
1613
+ { ...k, processor_name: "stripe" },
2146
1614
  !1
2147
1615
  );
2148
- if (q) {
2149
- J(!0), qe(q), Ze(L, ae, R, q, C);
1616
+ if (N) {
1617
+ z(!0), Se(N), Te(F, W, S, N, L);
2150
1618
  break;
2151
1619
  }
2152
1620
  }
2153
1621
  } else
2154
- ne(!1), J(!1), f && f(w.message);
1622
+ K(!1), z(!1), g && g(y.message);
2155
1623
  },
2156
1624
  [
2157
- ae,
2158
- K,
2159
- S,
2160
- B,
2161
- re,
2162
- ye,
2163
- mt,
2164
- ft,
1625
+ W,
1626
+ $,
1627
+ Ue,
1628
+ D,
1629
+ Y,
1630
+ ee,
1631
+ ze,
1632
+ He,
2165
1633
  i,
2166
1634
  a,
2167
1635
  s,
2168
- d,
2169
- u,
2170
- y,
2171
- m,
2172
- f,
2173
1636
  l,
2174
- C,
2175
- ze,
2176
- Y,
2177
- ce
1637
+ m,
1638
+ E,
1639
+ _,
1640
+ g,
1641
+ d,
1642
+ L,
1643
+ Pe,
1644
+ U,
1645
+ B
2178
1646
  ]
2179
- ), _t = ue(() => {
2180
- const p = () => {
1647
+ ), Je = Q(() => {
1648
+ const u = () => {
2181
1649
  };
2182
1650
  return {
2183
- onCheckoutError: ge("onCheckoutError", f ?? p),
2184
- onCheckoutStarted: ge("onCheckoutStarted", u ?? p),
2185
- onCheckoutSuccess: ge("onCheckoutSuccess", y ?? p),
2186
- onSetupPaymentMethodSuccess: ge("onSetupPaymentMethodSuccess", m ?? p),
2187
- onValidationError: ge("onValidationError", l ?? p)
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)
2188
1656
  };
2189
- }, [f, u, y, m, l]), He = () => {
2190
- if (!D.current || !K || !Y) return null;
2191
- const p = /* @__PURE__ */ new Map();
2192
- return Object.entries(gt).forEach(([j, _]) => {
2193
- _ && p.set(j, _);
2194
- }), p.size === 0 ? null : {
2195
- formDiv: D.current,
2196
- elementsSessionId: K,
2197
- checkoutPaymentMethods: Y,
2198
- cdeConnections: p,
2199
- baseUrl: new URL(C).origin
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 : {
1663
+ formDiv: j.current,
1664
+ elementsSessionId: $,
1665
+ checkoutPaymentMethods: U,
1666
+ cdeConnections: u,
1667
+ baseUrl: new URL(L).origin
2200
1668
  };
2201
- }, wt = (p, N, j) => {
2202
- const _ = He();
2203
- if (!(!_ || !D.current))
2204
- return st.stripePR.run({
2205
- context: _,
2206
- checkoutPaymentMethod: Dt(_.checkoutPaymentMethods, p),
2207
- nonCdeFormInputs: et(D.current),
2208
- flowCallbacks: _t,
2209
- customParams: { provider: p, overridePaymentRequest: j == null ? void 0 : j.overridePaymentRequest },
2210
- initResult: N
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
2211
1679
  });
2212
1680
  };
2213
- G(() => {
2214
- if (An !== null) return;
2215
- const p = He();
2216
- if (!p) return;
2217
- const N = Ss(p);
2218
- Tn(N), N.stripePR.subscribe((j) => {
2219
- if (j.status === "loading")
2220
- le.set("apple_pay", ke), le.set("google_pay", ke);
2221
- else if (j.status === "error")
2222
- le.set("apple_pay", xt), le.set("google_pay", xt);
2223
- else if (j.status === "loaded") {
2224
- const _ = j.result, Q = _.isAvailable && _.availableProviders.applePay, Ye = _.isAvailable && _.availableProviders.googlePay;
2225
- le.set("apple_pay", {
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", {
2226
1694
  isLoading: !1,
2227
- isAvailable: Q,
2228
- startFlow: async (w) => Q ? wt("apple_pay", _, w) : void 0
2229
- }), le.set("google_pay", {
1695
+ isAvailable: H,
1696
+ startFlow: async (y) => H ? We("apple_pay", p, y) : void 0
1697
+ }), G.set("google_pay", {
2230
1698
  isLoading: !1,
2231
- isAvailable: Ye,
2232
- startFlow: async (w) => Ye ? wt("google_pay", _, w) : void 0
1699
+ isAvailable: ke,
1700
+ startFlow: async (y) => ke ? We("google_pay", p, y) : void 0
2233
1701
  });
2234
1702
  }
2235
1703
  });
2236
- }, [D.current, K, Y, Object.keys(gt).length]);
2237
- const Mn = () => {
2238
- const p = He();
2239
- !D.current || !K || !ce || !Y || !p || st.commonCC.run({
2240
- context: p,
2241
- checkoutPaymentMethod: Dt(Y, "credit_card"),
2242
- nonCdeFormInputs: et(D.current),
2243
- flowCallbacks: _t,
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,
2244
1712
  customParams: void 0,
2245
1713
  // This flow requires no custom params
2246
1714
  initResult: void 0
2247
1715
  // This flow requires no initialization
2248
1716
  });
2249
- }, Ke = se(
2250
- (p) => {
2251
- dt && p.preventDefault();
1717
+ }, Re = Z(
1718
+ (u) => {
1719
+ qe && u.preventDefault();
2252
1720
  },
2253
- [dt]
1721
+ [qe]
2254
1722
  );
2255
- G(() => {
2256
- if (te || !D.current) return;
2257
- re.length > 0 && re.length === Object.keys(ye).length && (En(!0), c && c(yt, pt));
2258
- }, [re, ye, te, c, yt, pt]), G(() => ($(window.location.origin), window.addEventListener("message", Ve), window.addEventListener("beforeunload", Ke), () => {
2259
- window.removeEventListener("beforeunload", Ke), window.removeEventListener("message", Ve);
2260
- }), [K, Ve, Ke]);
2261
- const jn = se(
2262
- async (p) => {
2263
- if (re.find((_) => _.contentWindow === p.contentWindow)) return;
2264
- Cn((_) => [..._, p]);
2265
- const j = Ms(p.id);
2266
- await kn(j, p);
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);
2267
1735
  },
2268
1736
  // eslint-disable-next-line react-hooks/exhaustive-deps
2269
- [re]
2270
- ), Fn = {
2271
- formId: ae,
2272
- formHeight: W,
2273
- referer: x,
2274
- checkoutSecureToken: n,
2275
- registerIframe: jn,
2276
- baseUrl: C
2277
- }, Dn = {
2278
- submit: Mn,
2279
- applePay: ht.apple_pay,
2280
- googlePay: ht.google_pay,
1737
+ [Y]
1738
+ ), tn = {
1739
+ formId: W,
1740
+ formHeight: Ut,
1741
+ referer: Ce,
1742
+ checkoutSecureToken: r,
1743
+ registerIframe: en,
1744
+ baseUrl: L
1745
+ }, nn = {
1746
+ submit: Xt,
1747
+ applePay: Ze.apple_pay,
1748
+ googlePay: Ze.google_pay,
2281
1749
  // stripeLink: {
2282
1750
  // TODO: uncomment if we need stripe elements later.
2283
1751
  // Better if we can make stripe link work in prod without elements.
@@ -2285,40 +1753,40 @@ const Ts = (e, t, n, r) => {
2285
1753
  // authElement: stripeElements.isReady ? StripeLinkAuthElement : NoOpElement,
2286
1754
  // pr: paymentRequests.stripe_link,
2287
1755
  // },
2288
- loaded: te,
2289
- preview: In
1756
+ loaded: be,
1757
+ preview: Qt
2290
1758
  };
2291
- return /* @__PURE__ */ X(Nt.Provider, { value: Fn, children: /* @__PURE__ */ X("div", { className: r, ref: D, children: t(Dn) }) });
2292
- }, Be = (e) => {
2293
- const { subPath: t, styles: n } = e, { formId: r, referer: s, formHeight: i, checkoutSecureToken: a, registerIframe: c, baseUrl: d } = Ln(), [l, u] = E(!1), y = _e(null), f = ue(() => n ? kr(n) : "", [n]), m = ue(() => ({
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(() => ({
2294
1762
  border: "none",
2295
1763
  width: "100%",
2296
1764
  height: i
2297
- }), [i]), g = ue(() => {
1765
+ }), [i]), h = Q(() => {
2298
1766
  if (!a || !s) return "";
2299
- const v = new URLSearchParams();
2300
- return v.append("referer", s), v.append("styles", f), v.append("formId", r), v.append("secureToken", a), v.toString();
2301
- }, [f, r, s, a]);
2302
- return G(() => u(!0), []), G(() => {
2303
- !y.current || !l || c(y.current);
2304
- }, [l]), a ? /* @__PURE__ */ X(
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(
2305
1773
  "iframe",
2306
1774
  {
2307
1775
  id: `ojs-${t}-element`,
2308
1776
  name: `${t}-element`,
2309
1777
  className: "ojs-iframe",
2310
- src: `${d}/app/v1/${t}-element/?${g}`,
2311
- style: m,
2312
- ref: y
1778
+ src: `${l}/app/v1/${t}-element/?${h}`,
1779
+ style: _,
1780
+ ref: E
2313
1781
  }
2314
- ) : /* @__PURE__ */ X("div", {});
2315
- }, $s = ({ styles: e }) => /* @__PURE__ */ X(Be, { styles: e, subPath: "card-cvc" }), Ns = ({ styles: e }) => /* @__PURE__ */ X(Be, { styles: e, subPath: "card" }), Ls = ({ styles: e }) => /* @__PURE__ */ X(Be, { styles: e, subPath: "card-expiry" }), Us = ({ styles: e }) => /* @__PURE__ */ X(Be, { styles: e, subPath: "card-number" });
1782
+ ) : /* @__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" });
2316
1784
  export {
2317
- $s as CardCvcElement,
2318
- Ns as CardElement,
2319
- Ls as CardExpiryElement,
2320
- Us as CardNumberElement,
2321
- xs as ElementsForm,
2322
- U as FieldName,
2323
- Ln as useOpenPayElements
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
2324
1792
  };