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