@glomopay/react-native-sdk 2.0.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +261 -314
- package/lib/config/base.d.ts +17 -11
- package/lib/config/base.d.ts.map +1 -1
- package/lib/config/base.js +19 -7
- package/lib/config/segment.js +3 -3
- package/lib/glomo-checkout.d.ts +8 -0
- package/lib/glomo-checkout.d.ts.map +1 -0
- package/lib/glomo-checkout.js +69 -0
- package/lib/glomo-lrs-checkout.d.ts.map +1 -1
- package/lib/glomo-lrs-checkout.js +9 -9
- package/lib/glomo-standard-checkout.d.ts +5 -0
- package/lib/glomo-standard-checkout.d.ts.map +1 -0
- package/lib/glomo-standard-checkout.js +218 -0
- package/lib/index.d.ts +5 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -5
- package/lib/injections/index.d.ts +1 -0
- package/lib/injections/index.d.ts.map +1 -1
- package/lib/injections/index.js +2 -0
- package/lib/injections/webview-flow.injection.d.ts.map +1 -1
- package/lib/injections/webview-flow.injection.js +106 -69
- package/lib/injections/webview-main.injection.d.ts.map +1 -1
- package/lib/injections/webview-main.injection.js +112 -77
- package/lib/injections/webview-standard.injection.d.ts +3 -0
- package/lib/injections/webview-standard.injection.d.ts.map +1 -0
- package/lib/injections/webview-standard.injection.js +214 -0
- package/lib/services/order-type-fetcher.d.ts +28 -0
- package/lib/services/order-type-fetcher.d.ts.map +1 -0
- package/lib/services/order-type-fetcher.js +99 -0
- package/lib/types/checkout.d.ts +53 -0
- package/lib/types/checkout.d.ts.map +1 -0
- package/lib/types/checkout.js +3 -0
- package/lib/types/standard-checkout.d.ts +40 -0
- package/lib/types/standard-checkout.d.ts.map +1 -0
- package/lib/types/standard-checkout.js +3 -0
- package/lib/use-glomo-checkout.d.ts +24 -0
- package/lib/use-glomo-checkout.d.ts.map +1 -0
- package/lib/use-glomo-checkout.js +182 -0
- package/lib/use-lrs-checkout.d.ts +9 -4
- package/lib/use-lrs-checkout.d.ts.map +1 -1
- package/lib/use-lrs-checkout.js +91 -93
- package/lib/use-standard-checkout.d.ts +65 -0
- package/lib/use-standard-checkout.d.ts.map +1 -0
- package/lib/use-standard-checkout.js +832 -0
- package/lib/utils/analytics.d.ts +102 -1
- package/lib/utils/analytics.d.ts.map +1 -1
- package/lib/utils/analytics.js +294 -21
- package/lib/utils/device-compliance.js +3 -3
- package/lib/utils/validation.d.ts.map +1 -1
- package/lib/utils/validation.js +7 -6
- package/package.json +3 -2
- package/src/config/base.ts +36 -17
- package/src/config/segment.ts +3 -3
- package/src/glomo-checkout.tsx +73 -0
- package/src/glomo-lrs-checkout.tsx +13 -10
- package/src/glomo-standard-checkout.tsx +324 -0
- package/src/index.ts +13 -7
- package/src/injections/index.ts +2 -0
- package/src/injections/webview-flow.injection.ts +106 -69
- package/src/injections/webview-main.injection.ts +112 -77
- package/src/injections/webview-standard.injection.ts +211 -0
- package/src/services/order-type-fetcher.ts +86 -0
- package/src/types/checkout.ts +65 -0
- package/src/types/standard-checkout.ts +49 -0
- package/src/use-glomo-checkout.tsx +228 -0
- package/src/use-lrs-checkout.tsx +115 -111
- package/src/use-standard-checkout.tsx +1185 -0
- package/src/utils/analytics.ts +431 -22
- package/src/utils/device-compliance.ts +3 -3
- package/src/utils/validation.ts +7 -8
package/src/use-lrs-checkout.tsx
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
import React, { useState, useRef, useMemo, useCallback, useEffect } from "react";
|
|
4
4
|
import { Platform, type NativeSyntheticEvent } from "react-native";
|
|
5
5
|
|
|
6
|
-
import { WebViewNavigation, WebViewMessageEvent, type WebView } from "react-native-webview";
|
|
6
|
+
import { type WebViewNavigation, type WebViewMessageEvent, type WebView } from "react-native-webview";
|
|
7
7
|
|
|
8
8
|
import { InjectionScripts } from "./injections/index";
|
|
9
9
|
import { initializeSegment } from "./config/segment";
|
|
10
|
-
import { resolveServerConfig, type
|
|
10
|
+
import { resolveServerConfig, type GlomoServer } from "./config/base";
|
|
11
11
|
import { isValidPublicKey, isValidOrderId, isValidUrl, isValidPaymentPayload, safeCallback } from "./utils/validation";
|
|
12
12
|
import { checkDeviceCompliance, isComplianceCheckAvailable } from "./utils/device-compliance";
|
|
13
13
|
import {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
trackPaymentTerminate,
|
|
22
22
|
trackConnectionError,
|
|
23
23
|
trackEducationStepsShown,
|
|
24
|
+
trackEducationStepsFailedToShow,
|
|
24
25
|
trackSdkError,
|
|
25
26
|
trackInvalidMessageReceived,
|
|
26
27
|
type SdkError,
|
|
@@ -41,7 +42,14 @@ export type LrsCheckoutStatus =
|
|
|
41
42
|
| "payment_failed"
|
|
42
43
|
|
|
43
44
|
// LRS checkout flow aborted midway. User can retry the flow on the same orderId
|
|
44
|
-
| "payment_cancelled"
|
|
45
|
+
| "payment_cancelled"
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* These are not currently emitted by LRS flows, but I'm intentionally including them so that the SDK is forwards compatible.
|
|
49
|
+
* The SDK would also then effectively handle these events without a patch if LRS gains bank transfer / pay-via-bank support in the future.
|
|
50
|
+
*/
|
|
51
|
+
| "bank_transfer_submitted"
|
|
52
|
+
| "pay_via_bank_completed";
|
|
45
53
|
|
|
46
54
|
/**
|
|
47
55
|
* Tracks whether the education carousel WebView has signalled that it has content to show.
|
|
@@ -59,7 +67,7 @@ export interface GlomoLrsCheckoutPayload {
|
|
|
59
67
|
|
|
60
68
|
/** The options for the useLrsCheckout hook */
|
|
61
69
|
export interface UseLrsCheckoutOptions {
|
|
62
|
-
server?:
|
|
70
|
+
server?: GlomoServer;
|
|
63
71
|
publicKey: string;
|
|
64
72
|
orderId: string;
|
|
65
73
|
onPaymentSuccess: (payload: GlomoLrsCheckoutPayload) => void;
|
|
@@ -120,7 +128,7 @@ export function useLrsCheckout(
|
|
|
120
128
|
|
|
121
129
|
// Resolving checkout and carousel URLs from the selected SDK server
|
|
122
130
|
const serverConfig = useMemo(() => resolveServerConfig(server), [server]);
|
|
123
|
-
const baseCheckoutUrl = serverConfig.
|
|
131
|
+
const baseCheckoutUrl = serverConfig.baseUrl.lrsCheckout;
|
|
124
132
|
|
|
125
133
|
/**
|
|
126
134
|
* The main checkout URL for the LRS flow
|
|
@@ -144,45 +152,22 @@ export function useLrsCheckout(
|
|
|
144
152
|
// Validating the final URL
|
|
145
153
|
if (!isValidUrl(finalUrl)) {
|
|
146
154
|
if (devMode) {
|
|
147
|
-
console.error("[
|
|
155
|
+
console.error("[Glomo-RN-SDK LRS] Generated invalid checkout URL:", finalUrl);
|
|
148
156
|
}
|
|
149
|
-
const errors: SdkError[] = [
|
|
150
|
-
{
|
|
151
|
-
type: "validation_error",
|
|
152
|
-
message: "Generated invalid checkout URL",
|
|
153
|
-
},
|
|
154
|
-
];
|
|
155
|
-
safeCallback(onSdkError, [errors], "onSdkError", devMode);
|
|
156
|
-
trackSdkError(
|
|
157
|
-
errors,
|
|
158
|
-
orderId,
|
|
159
|
-
publicKey,
|
|
160
|
-
devMode,
|
|
161
|
-
mockMode,
|
|
162
|
-
finalUrl ? finalUrl : finalUrl === null ? "null" : "undefined"
|
|
163
|
-
);
|
|
164
157
|
return "";
|
|
165
158
|
}
|
|
166
159
|
|
|
167
160
|
if (devMode) {
|
|
168
|
-
console.log("[
|
|
161
|
+
console.log("[Glomo-RN-SDK LRS] Checkout URL:", finalUrl);
|
|
169
162
|
}
|
|
170
163
|
return finalUrl;
|
|
171
164
|
} catch (error) {
|
|
172
165
|
if (devMode) {
|
|
173
|
-
console.error("[
|
|
166
|
+
console.error("[Glomo-RN-SDK LRS] Error building checkout URL:", error);
|
|
174
167
|
}
|
|
175
|
-
const errors: SdkError[] = [
|
|
176
|
-
{
|
|
177
|
-
type: "validation_error",
|
|
178
|
-
message: `Error building checkout URL: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
179
|
-
},
|
|
180
|
-
];
|
|
181
|
-
safeCallback(onSdkError, [errors], "onSdkError", devMode);
|
|
182
|
-
trackSdkError(errors, orderId, publicKey, devMode, mockMode, "");
|
|
183
168
|
return "";
|
|
184
169
|
}
|
|
185
|
-
}, [baseCheckoutUrl, orderId, publicKey, mockMode, devMode
|
|
170
|
+
}, [baseCheckoutUrl, orderId, publicKey, mockMode, devMode]);
|
|
186
171
|
|
|
187
172
|
/**
|
|
188
173
|
* The education carousel URL, built from the server config with the current orderId and publicKey.
|
|
@@ -190,7 +175,7 @@ export function useLrsCheckout(
|
|
|
190
175
|
*/
|
|
191
176
|
const educationCarouselUrl = useMemo(() => {
|
|
192
177
|
try {
|
|
193
|
-
const baseEducationCarouselUrl = serverConfig.
|
|
178
|
+
const baseEducationCarouselUrl = serverConfig.baseUrl.lrsEducationCarousel;
|
|
194
179
|
const separator = baseEducationCarouselUrl.includes("?") ? "&" : "?";
|
|
195
180
|
const finalUrl =
|
|
196
181
|
`${baseEducationCarouselUrl}${separator}orderId=${encodeURIComponent(orderId)}` +
|
|
@@ -198,43 +183,22 @@ export function useLrsCheckout(
|
|
|
198
183
|
|
|
199
184
|
if (!isValidUrl(finalUrl)) {
|
|
200
185
|
if (devMode) {
|
|
201
|
-
console.error("[
|
|
186
|
+
console.error("[Glomo-RN-SDK LRS] Generated invalid education carousel URL:", finalUrl);
|
|
202
187
|
}
|
|
203
|
-
const errors: SdkError[] = [
|
|
204
|
-
{
|
|
205
|
-
type: "validation_error",
|
|
206
|
-
message: "Generated invalid education carousel URL",
|
|
207
|
-
},
|
|
208
|
-
];
|
|
209
|
-
trackSdkError(
|
|
210
|
-
errors,
|
|
211
|
-
orderId,
|
|
212
|
-
publicKey,
|
|
213
|
-
devMode,
|
|
214
|
-
mockMode,
|
|
215
|
-
finalUrl ? finalUrl : finalUrl === null ? "null" : "undefined"
|
|
216
|
-
);
|
|
217
188
|
return "";
|
|
218
189
|
}
|
|
219
190
|
|
|
220
191
|
if (devMode) {
|
|
221
|
-
console.log("[
|
|
192
|
+
console.log("[Glomo-RN-SDK LRS] Education Carousel URL:", finalUrl);
|
|
222
193
|
}
|
|
223
194
|
return finalUrl;
|
|
224
195
|
} catch (error) {
|
|
225
196
|
if (devMode) {
|
|
226
|
-
console.error("[
|
|
197
|
+
console.error("[Glomo-RN-SDK LRS] Error building education carousel URL:", error);
|
|
227
198
|
}
|
|
228
|
-
const errors: SdkError[] = [
|
|
229
|
-
{
|
|
230
|
-
type: "validation_error",
|
|
231
|
-
message: `Error building education carousel URL: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
232
|
-
},
|
|
233
|
-
];
|
|
234
|
-
trackSdkError(errors, orderId, publicKey, devMode, mockMode, "");
|
|
235
199
|
return "";
|
|
236
200
|
}
|
|
237
|
-
}, [serverConfig, orderId, publicKey, devMode
|
|
201
|
+
}, [serverConfig, orderId, publicKey, devMode]);
|
|
238
202
|
|
|
239
203
|
// Checkout status state
|
|
240
204
|
const [status, setStatus] = useState<LrsCheckoutStatus>("ready");
|
|
@@ -249,11 +213,18 @@ export function useLrsCheckout(
|
|
|
249
213
|
useEffect(() => {
|
|
250
214
|
if (devMode) {
|
|
251
215
|
console.log(
|
|
252
|
-
`[
|
|
216
|
+
`[Glomo-RN-SDK LRS] Carousel state snapshot: status=${status}, showCheckout=${showCheckout}, showFlowWebView=${showFlowWebView}, flowWebViewUrl=${flowWebViewUrl || "<empty>"}, educationCarouselState=${educationCarouselState}, educationCarouselUrl=${educationCarouselUrl || "<empty>"}`
|
|
253
217
|
);
|
|
254
218
|
}
|
|
255
219
|
}, [devMode, status, showCheckout, showFlowWebView, flowWebViewUrl, educationCarouselState, educationCarouselUrl]);
|
|
256
220
|
|
|
221
|
+
// Tracking when the education carousel URL is invalid (empty) despite having valid orderId and publicKey
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
if (orderId && publicKey && !educationCarouselUrl) {
|
|
224
|
+
trackEducationStepsFailedToShow(orderId, publicKey, devMode, mockMode, checkoutUrl, "invalid_url");
|
|
225
|
+
}
|
|
226
|
+
}, [educationCarouselUrl, orderId, publicKey, devMode, mockMode, checkoutUrl]);
|
|
227
|
+
|
|
257
228
|
// Handler for the WebView errors
|
|
258
229
|
const handleError = useCallback(
|
|
259
230
|
(syntheticEvent: NativeSyntheticEvent<{ code?: number; domain?: string; description?: string }>) => {
|
|
@@ -283,7 +254,7 @@ export function useLrsCheckout(
|
|
|
283
254
|
|
|
284
255
|
if (isIOSConnectionError || isAndroidConnectionError) {
|
|
285
256
|
if (devMode) {
|
|
286
|
-
console.error("[
|
|
257
|
+
console.error("[Glomo-RN-SDK LRS] Connection error:", nativeEvent);
|
|
287
258
|
}
|
|
288
259
|
|
|
289
260
|
// Closing the checkout modal
|
|
@@ -298,12 +269,12 @@ export function useLrsCheckout(
|
|
|
298
269
|
trackConnectionError(orderId, nativeEvent?.code, publicKey, devMode, mockMode, checkoutUrl);
|
|
299
270
|
} else {
|
|
300
271
|
if (devMode) {
|
|
301
|
-
console.error("[
|
|
272
|
+
console.error("[Glomo-RN-SDK LRS] WebView error:", nativeEvent);
|
|
302
273
|
}
|
|
303
274
|
}
|
|
304
275
|
} catch (error) {
|
|
305
276
|
if (devMode) {
|
|
306
|
-
console.error("[
|
|
277
|
+
console.error("[Glomo-RN-SDK LRS] Error in handleError:", error);
|
|
307
278
|
}
|
|
308
279
|
}
|
|
309
280
|
},
|
|
@@ -316,11 +287,11 @@ export function useLrsCheckout(
|
|
|
316
287
|
try {
|
|
317
288
|
const { nativeEvent } = syntheticEvent;
|
|
318
289
|
if (devMode) {
|
|
319
|
-
console.error("[
|
|
290
|
+
console.error("[Glomo-RN-SDK LRS] WebView HTTP error:", nativeEvent);
|
|
320
291
|
}
|
|
321
292
|
} catch (error) {
|
|
322
293
|
if (devMode) {
|
|
323
|
-
console.error("[
|
|
294
|
+
console.error("[Glomo-RN-SDK LRS] Error in handleHttpError:", error);
|
|
324
295
|
}
|
|
325
296
|
}
|
|
326
297
|
},
|
|
@@ -334,7 +305,7 @@ export function useLrsCheckout(
|
|
|
334
305
|
const data = event.nativeEvent?.data;
|
|
335
306
|
if (!data || typeof data !== "string") {
|
|
336
307
|
if (devMode) {
|
|
337
|
-
console.warn("[
|
|
308
|
+
console.warn("[Glomo-RN-SDK LRS] Invalid message data from MainWebView");
|
|
338
309
|
}
|
|
339
310
|
// Tracking invalid message received
|
|
340
311
|
trackInvalidMessageReceived(
|
|
@@ -352,13 +323,13 @@ export function useLrsCheckout(
|
|
|
352
323
|
|
|
353
324
|
const message = JSON.parse(data);
|
|
354
325
|
if (devMode) {
|
|
355
|
-
console.log("[
|
|
326
|
+
console.log("[Glomo-RN-SDK LRS] MainWebView Message received:", message.type, message);
|
|
356
327
|
}
|
|
357
328
|
|
|
358
329
|
if (message.type === "console") {
|
|
359
330
|
if (devMode) {
|
|
360
331
|
const level = message.level || "log";
|
|
361
|
-
console.log(`[
|
|
332
|
+
console.log(`[Glomo-RN-SDK LRS] [WebView ${level.toUpperCase()}]`, message.message);
|
|
362
333
|
}
|
|
363
334
|
return;
|
|
364
335
|
}
|
|
@@ -367,7 +338,7 @@ export function useLrsCheckout(
|
|
|
367
338
|
const url = message.url;
|
|
368
339
|
if (url && typeof url === "string" && isValidUrl(url)) {
|
|
369
340
|
if (devMode) {
|
|
370
|
-
console.log(`[
|
|
341
|
+
console.log(`[Glomo-RN-SDK LRS] window.open called from MainWebView: ${url}`);
|
|
371
342
|
}
|
|
372
343
|
setFlowWebViewUrl(url);
|
|
373
344
|
setShowFlowWebView(true);
|
|
@@ -377,7 +348,7 @@ export function useLrsCheckout(
|
|
|
377
348
|
} else {
|
|
378
349
|
if (devMode) {
|
|
379
350
|
console.log(
|
|
380
|
-
"[
|
|
351
|
+
"[Glomo-RN-SDK LRS] Invalid URL in window.open from MainWebView:",
|
|
381
352
|
url,
|
|
382
353
|
typeof url === "undefined" ? "undefined" : ""
|
|
383
354
|
);
|
|
@@ -388,7 +359,7 @@ export function useLrsCheckout(
|
|
|
388
359
|
|
|
389
360
|
if (message.type === "window.close") {
|
|
390
361
|
if (devMode) {
|
|
391
|
-
console.log("[
|
|
362
|
+
console.log("[Glomo-RN-SDK LRS] Child window close requested from MainWebView");
|
|
392
363
|
}
|
|
393
364
|
setShowFlowWebView(false);
|
|
394
365
|
setFlowWebViewUrl("");
|
|
@@ -409,7 +380,7 @@ export function useLrsCheckout(
|
|
|
409
380
|
|
|
410
381
|
if (isValidPaymentPayload(payload)) {
|
|
411
382
|
if (devMode) {
|
|
412
|
-
console.log("[
|
|
383
|
+
console.log("[Glomo-RN-SDK LRS] Payment successful via merchant callback!");
|
|
413
384
|
}
|
|
414
385
|
setShowCheckout(false);
|
|
415
386
|
setShowFlowWebView(false);
|
|
@@ -428,7 +399,7 @@ export function useLrsCheckout(
|
|
|
428
399
|
);
|
|
429
400
|
} else {
|
|
430
401
|
if (devMode) {
|
|
431
|
-
console.error("[
|
|
402
|
+
console.error("[Glomo-RN-SDK LRS] Invalid payment success payload:", payload);
|
|
432
403
|
}
|
|
433
404
|
}
|
|
434
405
|
return;
|
|
@@ -440,7 +411,7 @@ export function useLrsCheckout(
|
|
|
440
411
|
|
|
441
412
|
if (isValidPaymentPayload(payload)) {
|
|
442
413
|
if (devMode) {
|
|
443
|
-
console.error("[
|
|
414
|
+
console.error("[Glomo-RN-SDK LRS] Payment failed via merchant callback");
|
|
444
415
|
}
|
|
445
416
|
setShowCheckout(false);
|
|
446
417
|
setShowFlowWebView(false);
|
|
@@ -459,7 +430,7 @@ export function useLrsCheckout(
|
|
|
459
430
|
);
|
|
460
431
|
} else {
|
|
461
432
|
if (devMode) {
|
|
462
|
-
console.error("[
|
|
433
|
+
console.error("[Glomo-RN-SDK LRS] Invalid payment failure payload:", payload);
|
|
463
434
|
}
|
|
464
435
|
}
|
|
465
436
|
return;
|
|
@@ -468,7 +439,7 @@ export function useLrsCheckout(
|
|
|
468
439
|
// Handling checkout.closed events
|
|
469
440
|
if (messageType === "checkout.closed") {
|
|
470
441
|
if (devMode) {
|
|
471
|
-
console.log("[
|
|
442
|
+
console.log("[Glomo-RN-SDK LRS] Checkout closed event received");
|
|
472
443
|
}
|
|
473
444
|
setShowCheckout(false);
|
|
474
445
|
setShowFlowWebView(false);
|
|
@@ -482,7 +453,7 @@ export function useLrsCheckout(
|
|
|
482
453
|
}
|
|
483
454
|
} catch (error) {
|
|
484
455
|
if (devMode) {
|
|
485
|
-
console.error("[
|
|
456
|
+
console.error("[Glomo-RN-SDK LRS] Error parsing MainWebView message:", error);
|
|
486
457
|
}
|
|
487
458
|
}
|
|
488
459
|
},
|
|
@@ -496,7 +467,7 @@ export function useLrsCheckout(
|
|
|
496
467
|
const data = event.nativeEvent?.data;
|
|
497
468
|
if (!data || typeof data !== "string") {
|
|
498
469
|
if (devMode) {
|
|
499
|
-
console.warn("[
|
|
470
|
+
console.warn("[Glomo-RN-SDK LRS] Invalid message data from FlowWebView");
|
|
500
471
|
}
|
|
501
472
|
// Tracking invalid message received
|
|
502
473
|
trackInvalidMessageReceived(
|
|
@@ -514,12 +485,12 @@ export function useLrsCheckout(
|
|
|
514
485
|
|
|
515
486
|
const message = JSON.parse(data);
|
|
516
487
|
if (devMode) {
|
|
517
|
-
console.log("[
|
|
488
|
+
console.log("[Glomo-RN-SDK LRS] FlowWebView Message received:", message.type, message);
|
|
518
489
|
}
|
|
519
490
|
|
|
520
491
|
if (message.type === "console") {
|
|
521
492
|
if (devMode) {
|
|
522
|
-
console.log(`[
|
|
493
|
+
console.log(`[Glomo-RN-SDK LRS] [Flow] ${message.message}`);
|
|
523
494
|
}
|
|
524
495
|
return;
|
|
525
496
|
}
|
|
@@ -528,7 +499,7 @@ export function useLrsCheckout(
|
|
|
528
499
|
const url = message.url;
|
|
529
500
|
if (url && typeof url === "string" && isValidUrl(url)) {
|
|
530
501
|
if (devMode) {
|
|
531
|
-
console.log(`[
|
|
502
|
+
console.log(`[Glomo-RN-SDK LRS] window.open called from FlowWebView: ${url}`);
|
|
532
503
|
}
|
|
533
504
|
setFlowWebViewUrl(url);
|
|
534
505
|
setEducationCarouselState("pending");
|
|
@@ -537,7 +508,7 @@ export function useLrsCheckout(
|
|
|
537
508
|
} else {
|
|
538
509
|
if (devMode) {
|
|
539
510
|
console.log(
|
|
540
|
-
"[
|
|
511
|
+
"[Glomo-RN-SDK LRS] Invalid URL in window.open from FlowWebView:",
|
|
541
512
|
url,
|
|
542
513
|
typeof url === "undefined" ? "undefined" : ""
|
|
543
514
|
);
|
|
@@ -548,7 +519,7 @@ export function useLrsCheckout(
|
|
|
548
519
|
|
|
549
520
|
if (message.type === "window.close") {
|
|
550
521
|
if (devMode) {
|
|
551
|
-
console.log("[
|
|
522
|
+
console.log("[Glomo-RN-SDK LRS] FlowWebView close requested");
|
|
552
523
|
}
|
|
553
524
|
setShowFlowWebView(false);
|
|
554
525
|
setFlowWebViewUrl("");
|
|
@@ -568,7 +539,7 @@ export function useLrsCheckout(
|
|
|
568
539
|
|
|
569
540
|
if (isValidPaymentPayload(payload)) {
|
|
570
541
|
if (devMode) {
|
|
571
|
-
console.log("[
|
|
542
|
+
console.log("[Glomo-RN-SDK LRS] Payment successful via FlowWebView callback!");
|
|
572
543
|
}
|
|
573
544
|
setShowFlowWebView(false);
|
|
574
545
|
setShowCheckout(false);
|
|
@@ -588,7 +559,7 @@ export function useLrsCheckout(
|
|
|
588
559
|
} else {
|
|
589
560
|
if (devMode) {
|
|
590
561
|
console.error(
|
|
591
|
-
"[
|
|
562
|
+
"[Glomo-RN-SDK LRS] Invalid payment success payload from FlowWebView:",
|
|
592
563
|
payload
|
|
593
564
|
);
|
|
594
565
|
}
|
|
@@ -602,7 +573,7 @@ export function useLrsCheckout(
|
|
|
602
573
|
|
|
603
574
|
if (isValidPaymentPayload(payload)) {
|
|
604
575
|
if (devMode) {
|
|
605
|
-
console.error("[
|
|
576
|
+
console.error("[Glomo-RN-SDK LRS] Payment failed via FlowWebView callback");
|
|
606
577
|
}
|
|
607
578
|
setShowFlowWebView(false);
|
|
608
579
|
setShowCheckout(false);
|
|
@@ -622,7 +593,7 @@ export function useLrsCheckout(
|
|
|
622
593
|
} else {
|
|
623
594
|
if (devMode) {
|
|
624
595
|
console.error(
|
|
625
|
-
"[
|
|
596
|
+
"[Glomo-RN-SDK LRS] Invalid payment failure payload from FlowWebView:",
|
|
626
597
|
payload
|
|
627
598
|
);
|
|
628
599
|
}
|
|
@@ -632,7 +603,7 @@ export function useLrsCheckout(
|
|
|
632
603
|
}
|
|
633
604
|
} catch (error) {
|
|
634
605
|
if (devMode) {
|
|
635
|
-
console.error("[
|
|
606
|
+
console.error("[Glomo-RN-SDK LRS] Error parsing FlowWebView message:", error);
|
|
636
607
|
}
|
|
637
608
|
}
|
|
638
609
|
},
|
|
@@ -646,19 +617,19 @@ export function useLrsCheckout(
|
|
|
646
617
|
const data = event.nativeEvent?.data;
|
|
647
618
|
if (!data || typeof data !== "string") {
|
|
648
619
|
if (devMode) {
|
|
649
|
-
console.warn("[
|
|
620
|
+
console.warn("[Glomo-RN-SDK LRS] Invalid message data from EducationCarouselWebView");
|
|
650
621
|
}
|
|
651
622
|
return;
|
|
652
623
|
}
|
|
653
624
|
|
|
654
625
|
const message = JSON.parse(data);
|
|
655
626
|
if (devMode) {
|
|
656
|
-
console.log("[
|
|
627
|
+
console.log("[Glomo-RN-SDK LRS] EducationCarouselWebView Message received:", message.type, message);
|
|
657
628
|
}
|
|
658
629
|
|
|
659
630
|
if (message.type === "console") {
|
|
660
631
|
if (devMode) {
|
|
661
|
-
console.log(`[
|
|
632
|
+
console.log(`[Glomo-RN-SDK LRS] [EducationCarousel] ${message.message}`);
|
|
662
633
|
}
|
|
663
634
|
return;
|
|
664
635
|
}
|
|
@@ -668,7 +639,7 @@ export function useLrsCheckout(
|
|
|
668
639
|
|
|
669
640
|
if (devMode) {
|
|
670
641
|
console.log(
|
|
671
|
-
`[
|
|
642
|
+
`[Glomo-RN-SDK LRS] Education carousel signal received: value=${String(message.value)} source=${message.source || "unknown"} payload=${JSON.stringify(message.payload || {})}`
|
|
672
643
|
);
|
|
673
644
|
}
|
|
674
645
|
|
|
@@ -678,7 +649,7 @@ export function useLrsCheckout(
|
|
|
678
649
|
}
|
|
679
650
|
} catch (error) {
|
|
680
651
|
if (devMode) {
|
|
681
|
-
console.error("[
|
|
652
|
+
console.error("[Glomo-RN-SDK LRS] Error parsing EducationCarouselWebView message:", error);
|
|
682
653
|
}
|
|
683
654
|
}
|
|
684
655
|
},
|
|
@@ -689,7 +660,7 @@ export function useLrsCheckout(
|
|
|
689
660
|
const handleNavigationStateChange = useCallback(
|
|
690
661
|
(navState: WebViewNavigation) => {
|
|
691
662
|
if (devMode) {
|
|
692
|
-
console.log("[
|
|
663
|
+
console.log("[Glomo-RN-SDK LRS] Navigation state:", navState);
|
|
693
664
|
}
|
|
694
665
|
},
|
|
695
666
|
[devMode]
|
|
@@ -699,22 +670,23 @@ export function useLrsCheckout(
|
|
|
699
670
|
const handleModalBackButton = useCallback(() => {
|
|
700
671
|
try {
|
|
701
672
|
if (devMode) {
|
|
702
|
-
console.log("[
|
|
673
|
+
console.log("[Glomo-RN-SDK LRS] Modal dismissed/back button pressed");
|
|
703
674
|
}
|
|
704
675
|
if (showFlowWebView) {
|
|
705
676
|
setShowFlowWebView(false);
|
|
706
677
|
setFlowWebViewUrl("");
|
|
707
|
-
setEducationCarouselState("pending");
|
|
708
678
|
}
|
|
679
|
+
// Resetting carousel state and closing the checkout modal regardless of flow WebView state
|
|
680
|
+
setEducationCarouselState("pending");
|
|
709
681
|
setShowCheckout(false);
|
|
710
682
|
if (status === "payment_in_progress") {
|
|
711
683
|
if (devMode) {
|
|
712
|
-
console.log("[
|
|
684
|
+
console.log("[Glomo-RN-SDK LRS] In progress payment cancelled");
|
|
713
685
|
}
|
|
714
686
|
setStatus("payment_cancelled");
|
|
715
687
|
} else {
|
|
716
688
|
if (devMode) {
|
|
717
|
-
console.log("[
|
|
689
|
+
console.log("[Glomo-RN-SDK LRS] Ignoring checkout status update for: " + status);
|
|
718
690
|
}
|
|
719
691
|
}
|
|
720
692
|
safeCallback(onPaymentTerminate, [], "onPaymentTerminate", devMode);
|
|
@@ -723,7 +695,7 @@ export function useLrsCheckout(
|
|
|
723
695
|
trackPaymentTerminate(orderId, terminateSource, publicKey, devMode, mockMode, checkoutUrl);
|
|
724
696
|
} catch (error) {
|
|
725
697
|
if (devMode) {
|
|
726
|
-
console.error("[
|
|
698
|
+
console.error("[Glomo-RN-SDK LRS] Error in handleModalBackButton:", error);
|
|
727
699
|
}
|
|
728
700
|
}
|
|
729
701
|
}, [showFlowWebView, devMode, onPaymentTerminate, status, orderId, publicKey, mockMode, checkoutUrl]);
|
|
@@ -731,7 +703,7 @@ export function useLrsCheckout(
|
|
|
731
703
|
/** Closes the flow WebView and returns to the main checkout */
|
|
732
704
|
const handleFlowBack = useCallback(() => {
|
|
733
705
|
if (devMode) {
|
|
734
|
-
console.log("[
|
|
706
|
+
console.log("[Glomo-RN-SDK LRS] Flow WebView back button pressed");
|
|
735
707
|
}
|
|
736
708
|
setShowFlowWebView(false);
|
|
737
709
|
setFlowWebViewUrl("");
|
|
@@ -764,7 +736,7 @@ export function useLrsCheckout(
|
|
|
764
736
|
};
|
|
765
737
|
|
|
766
738
|
if (devMode) {
|
|
767
|
-
console.log(`[
|
|
739
|
+
console.log(`[Glomo-RN-SDK LRS] Attempting to start checkout of ${checkoutUrl} from status: ${status}`);
|
|
768
740
|
}
|
|
769
741
|
|
|
770
742
|
// Tracking start attempt with current status
|
|
@@ -773,7 +745,7 @@ export function useLrsCheckout(
|
|
|
773
745
|
if (deviceComplianceCheck === true) {
|
|
774
746
|
// Device detected as compromised
|
|
775
747
|
if (devMode) {
|
|
776
|
-
console.error("[
|
|
748
|
+
console.error("[Glomo-RN-SDK LRS] Cannot start checkout. Device is rooted or jailbroken.");
|
|
777
749
|
}
|
|
778
750
|
const errors: SdkError[] = [
|
|
779
751
|
{
|
|
@@ -797,10 +769,34 @@ export function useLrsCheckout(
|
|
|
797
769
|
} else if (deviceComplianceCheck === null) {
|
|
798
770
|
// This warning was intentionally not gated behind a devMode check to ensure merchants are aware of the strong recommendation to install jail-monkey for enhanced security compliance.
|
|
799
771
|
console.warn(
|
|
800
|
-
"[
|
|
772
|
+
"[Glomo-RN-SDK LRS] Device security library not installed - the SDK won't be able to automatically detect rooted/jailbroken devices. It is HIGHLY recommended to install jail-monkey as per the README, and prevent LRS checkouts from compromised devices."
|
|
801
773
|
);
|
|
802
774
|
}
|
|
803
775
|
|
|
776
|
+
// Enforcing devMode requirement for development servers
|
|
777
|
+
const resolvedServer = server || "prod";
|
|
778
|
+
if (!devMode && resolvedServer !== "prod") {
|
|
779
|
+
const errors: SdkError[] = [
|
|
780
|
+
{
|
|
781
|
+
type: "validation_error",
|
|
782
|
+
message: "Development servers can only be used when devMode is enabled.",
|
|
783
|
+
},
|
|
784
|
+
];
|
|
785
|
+
safeCallback(onSdkError, [errors], "onSdkError", devMode);
|
|
786
|
+
trackSdkError(errors, orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
787
|
+
trackStartFailure(
|
|
788
|
+
"validation_error",
|
|
789
|
+
orderId,
|
|
790
|
+
publicKey,
|
|
791
|
+
devMode,
|
|
792
|
+
mockMode,
|
|
793
|
+
checkoutUrl,
|
|
794
|
+
jailbreakDetectionInfo
|
|
795
|
+
);
|
|
796
|
+
setShowCheckout(false);
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
|
|
804
800
|
// Checking validation errors with detailed field-level messages
|
|
805
801
|
const errors: SdkError[] = [];
|
|
806
802
|
|
|
@@ -839,7 +835,7 @@ export function useLrsCheckout(
|
|
|
839
835
|
|
|
840
836
|
if (errors.length > 0) {
|
|
841
837
|
if (devMode) {
|
|
842
|
-
console.error(`[
|
|
838
|
+
console.error(`[Glomo-RN-SDK LRS] Cannot start checkout. Validation failed.`);
|
|
843
839
|
}
|
|
844
840
|
safeCallback(onSdkError, [errors], "onSdkError", devMode);
|
|
845
841
|
// Tracking start() failure
|
|
@@ -860,7 +856,7 @@ export function useLrsCheckout(
|
|
|
860
856
|
if (status === "payment_successful") {
|
|
861
857
|
if (devMode) {
|
|
862
858
|
console.log(
|
|
863
|
-
`[
|
|
859
|
+
`[Glomo-RN-SDK LRS] Cannot start checkout. Current status: ${status}. Payment already successful.`
|
|
864
860
|
);
|
|
865
861
|
}
|
|
866
862
|
// Tracking start() failure
|
|
@@ -881,10 +877,12 @@ export function useLrsCheckout(
|
|
|
881
877
|
status !== "ready" &&
|
|
882
878
|
status !== "payment_cancelled" &&
|
|
883
879
|
status !== "payment_failed" &&
|
|
884
|
-
status !== "payment_in_progress"
|
|
880
|
+
status !== "payment_in_progress" &&
|
|
881
|
+
status !== "bank_transfer_submitted" &&
|
|
882
|
+
status !== "pay_via_bank_completed"
|
|
885
883
|
) {
|
|
886
884
|
if (devMode) {
|
|
887
|
-
console.log(`[
|
|
885
|
+
console.log(`[Glomo-RN-SDK LRS] Cannot start checkout. Unknown status: ${status}.`);
|
|
888
886
|
}
|
|
889
887
|
// Tracking start() failure
|
|
890
888
|
trackStartFailure(
|
|
@@ -902,7 +900,7 @@ export function useLrsCheckout(
|
|
|
902
900
|
|
|
903
901
|
if (!checkoutUrl) {
|
|
904
902
|
if (devMode) {
|
|
905
|
-
console.error("[
|
|
903
|
+
console.error("[Glomo-RN-SDK LRS] Cannot start checkout. Invalid checkout URL.");
|
|
906
904
|
}
|
|
907
905
|
// Tracking start() failure
|
|
908
906
|
trackStartFailure(
|
|
@@ -919,7 +917,7 @@ export function useLrsCheckout(
|
|
|
919
917
|
}
|
|
920
918
|
|
|
921
919
|
if (devMode) {
|
|
922
|
-
console.log("[
|
|
920
|
+
console.log("[Glomo-RN-SDK LRS] Starting checkout from previous state: " + status);
|
|
923
921
|
}
|
|
924
922
|
|
|
925
923
|
setShowFlowWebView(false);
|
|
@@ -932,7 +930,7 @@ export function useLrsCheckout(
|
|
|
932
930
|
|
|
933
931
|
setShowCheckout(true);
|
|
934
932
|
return true;
|
|
935
|
-
}, [devMode, status, publicKey, orderId, baseCheckoutUrl, checkoutUrl, mockMode, onSdkError]);
|
|
933
|
+
}, [devMode, status, publicKey, orderId, baseCheckoutUrl, checkoutUrl, mockMode, onSdkError, server]);
|
|
936
934
|
|
|
937
935
|
// Initializing Segment analytics
|
|
938
936
|
useEffect(() => {
|
|
@@ -943,10 +941,16 @@ export function useLrsCheckout(
|
|
|
943
941
|
useEffect(() => {
|
|
944
942
|
if (orderId && publicKey) {
|
|
945
943
|
// Only resetting the checkout flow if the current status is that of a terminal state
|
|
946
|
-
if (
|
|
944
|
+
if (
|
|
945
|
+
status === "payment_successful" ||
|
|
946
|
+
status === "payment_failed" ||
|
|
947
|
+
status === "payment_cancelled" ||
|
|
948
|
+
status === "bank_transfer_submitted" ||
|
|
949
|
+
status === "pay_via_bank_completed"
|
|
950
|
+
) {
|
|
947
951
|
if (devMode) {
|
|
948
952
|
console.log(
|
|
949
|
-
`[
|
|
953
|
+
`[Glomo-RN-SDK LRS] Resetting checkout status ${status} for new orderId ${orderId} and publicKey ${publicKey}`
|
|
950
954
|
);
|
|
951
955
|
}
|
|
952
956
|
setStatus("ready");
|