@glomopay/react-native-sdk 2.0.2 → 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.
Files changed (70) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +261 -310
  3. package/lib/config/base.d.ts +17 -11
  4. package/lib/config/base.d.ts.map +1 -1
  5. package/lib/config/base.js +19 -7
  6. package/lib/config/segment.js +3 -3
  7. package/lib/glomo-checkout.d.ts +8 -0
  8. package/lib/glomo-checkout.d.ts.map +1 -0
  9. package/lib/glomo-checkout.js +69 -0
  10. package/lib/glomo-lrs-checkout.js +9 -9
  11. package/lib/glomo-standard-checkout.d.ts +5 -0
  12. package/lib/glomo-standard-checkout.d.ts.map +1 -0
  13. package/lib/glomo-standard-checkout.js +218 -0
  14. package/lib/index.d.ts +5 -4
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +7 -5
  17. package/lib/injections/index.d.ts +1 -0
  18. package/lib/injections/index.d.ts.map +1 -1
  19. package/lib/injections/index.js +2 -0
  20. package/lib/injections/webview-flow.injection.d.ts.map +1 -1
  21. package/lib/injections/webview-flow.injection.js +106 -69
  22. package/lib/injections/webview-main.injection.d.ts.map +1 -1
  23. package/lib/injections/webview-main.injection.js +112 -77
  24. package/lib/injections/webview-standard.injection.d.ts +3 -0
  25. package/lib/injections/webview-standard.injection.d.ts.map +1 -0
  26. package/lib/injections/webview-standard.injection.js +214 -0
  27. package/lib/services/order-type-fetcher.d.ts +28 -0
  28. package/lib/services/order-type-fetcher.d.ts.map +1 -0
  29. package/lib/services/order-type-fetcher.js +99 -0
  30. package/lib/types/checkout.d.ts +53 -0
  31. package/lib/types/checkout.d.ts.map +1 -0
  32. package/lib/types/checkout.js +3 -0
  33. package/lib/types/standard-checkout.d.ts +40 -0
  34. package/lib/types/standard-checkout.d.ts.map +1 -0
  35. package/lib/types/standard-checkout.js +3 -0
  36. package/lib/use-glomo-checkout.d.ts +24 -0
  37. package/lib/use-glomo-checkout.d.ts.map +1 -0
  38. package/lib/use-glomo-checkout.js +182 -0
  39. package/lib/use-lrs-checkout.d.ts +9 -4
  40. package/lib/use-lrs-checkout.d.ts.map +1 -1
  41. package/lib/use-lrs-checkout.js +76 -93
  42. package/lib/use-standard-checkout.d.ts +65 -0
  43. package/lib/use-standard-checkout.d.ts.map +1 -0
  44. package/lib/use-standard-checkout.js +832 -0
  45. package/lib/utils/analytics.d.ts +102 -1
  46. package/lib/utils/analytics.d.ts.map +1 -1
  47. package/lib/utils/analytics.js +294 -21
  48. package/lib/utils/device-compliance.js +3 -3
  49. package/lib/utils/validation.d.ts.map +1 -1
  50. package/lib/utils/validation.js +7 -6
  51. package/package.json +3 -2
  52. package/src/config/base.ts +36 -17
  53. package/src/config/segment.ts +3 -3
  54. package/src/glomo-checkout.tsx +73 -0
  55. package/src/glomo-lrs-checkout.tsx +9 -9
  56. package/src/glomo-standard-checkout.tsx +324 -0
  57. package/src/index.ts +13 -7
  58. package/src/injections/index.ts +2 -0
  59. package/src/injections/webview-flow.injection.ts +106 -69
  60. package/src/injections/webview-main.injection.ts +112 -77
  61. package/src/injections/webview-standard.injection.ts +211 -0
  62. package/src/services/order-type-fetcher.ts +86 -0
  63. package/src/types/checkout.ts +65 -0
  64. package/src/types/standard-checkout.ts +49 -0
  65. package/src/use-glomo-checkout.tsx +228 -0
  66. package/src/use-lrs-checkout.tsx +91 -111
  67. package/src/use-standard-checkout.tsx +1185 -0
  68. package/src/utils/analytics.ts +431 -22
  69. package/src/utils/device-compliance.ts +3 -3
  70. package/src/utils/validation.ts +7 -8
@@ -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 GlomoLrsServer } from "./config/base";
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?: GlomoLrsServer;
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.checkoutBaseUrl;
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("[GlomoPay RN SDK] Generated invalid checkout URL:", finalUrl);
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("[GlomoPay RN SDK] Checkout URL:", finalUrl);
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("[GlomoPay RN SDK] Error building checkout URL:", 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, onSdkError]);
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.educationCarouselBaseUrl;
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("[GlomoPay RN SDK] Generated invalid education carousel URL:", finalUrl);
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("[GlomoPay RN SDK] Education Carousel URL:", finalUrl);
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("[GlomoPay RN SDK] Error building education carousel URL:", 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, mockMode]);
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
- `[GlomoPay RN SDK] Carousel state snapshot: status=${status}, showCheckout=${showCheckout}, showFlowWebView=${showFlowWebView}, flowWebViewUrl=${flowWebViewUrl || "<empty>"}, educationCarouselState=${educationCarouselState}, educationCarouselUrl=${educationCarouselUrl || "<empty>"}`
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("[GlomoPay RN SDK] Connection error:", nativeEvent);
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("[GlomoPay RN SDK] WebView error:", nativeEvent);
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("[GlomoPay RN SDK] Error in handleError:", 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("[GlomoPay RN SDK] WebView HTTP error:", nativeEvent);
290
+ console.error("[Glomo-RN-SDK LRS] WebView HTTP error:", nativeEvent);
320
291
  }
321
292
  } catch (error) {
322
293
  if (devMode) {
323
- console.error("[GlomoPay RN SDK] Error in handleHttpError:", 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("[GlomoPay RN SDK] Invalid message data from MainWebView");
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("[GlomoPay RN SDK] MainWebView Message received:", message.type, message);
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(`[GlomoPay RN SDK] [WebView ${level.toUpperCase()}]`, message.message);
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(`[GlomoPay RN SDK] window.open called from MainWebView: ${url}`);
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
- "[GlomoPay RN SDK] Invalid URL in window.open from MainWebView:",
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("[GlomoPay RN SDK] Child window close requested from MainWebView");
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("[GlomoPay RN SDK] Payment successful via merchant callback!");
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("[GlomoPay RN SDK] Invalid payment success payload:", payload);
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("[GlomoPay RN SDK] Payment failed via merchant callback");
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("[GlomoPay RN SDK] Invalid payment failure payload:", payload);
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("[GlomoPay RN SDK] Checkout closed event received");
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("[GlomoPay RN SDK] Error parsing MainWebView message:", 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("[GlomoPay RN SDK] Invalid message data from FlowWebView");
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("[GlomoPay RN SDK] FlowWebView Message received:", message.type, message);
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(`[GlomoPay RN SDK] [Flow] ${message.message}`);
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(`[GlomoPay RN SDK] window.open called from FlowWebView: ${url}`);
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
- "[GlomoPay RN SDK] Invalid URL in window.open from FlowWebView:",
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("[GlomoPay RN SDK] FlowWebView close requested");
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("[GlomoPay RN SDK] Payment successful via FlowWebView callback!");
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
- "[GlomoPay RN SDK] Invalid payment success payload from FlowWebView:",
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("[GlomoPay RN SDK] Payment failed via FlowWebView callback");
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
- "[GlomoPay RN SDK] Invalid payment failure payload from FlowWebView:",
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("[GlomoPay RN SDK] Error parsing FlowWebView message:", 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("[GlomoPay RN SDK] Invalid message data from EducationCarouselWebView");
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("[GlomoPay RN SDK] EducationCarouselWebView Message received:", message.type, message);
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(`[GlomoPay RN SDK] [EducationCarousel] ${message.message}`);
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
- `[GlomoPay RN SDK] Education carousel signal received: value=${String(message.value)} source=${message.source || "unknown"} payload=${JSON.stringify(message.payload || {})}`
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("[GlomoPay RN SDK] Error parsing EducationCarouselWebView message:", 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("[GlomoPay RN SDK] Navigation state:", navState);
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("[GlomoPay RN SDK] Modal dismissed/back button pressed");
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("[GlomoPay RN SDK] In progress payment cancelled");
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("[GlomoPay RN SDK] Ignoring checkout status update for: " + status);
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("[GlomoPay RN SDK] Error in handleModalBackButton:", 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("[GlomoPay RN SDK] Flow WebView back button pressed");
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(`[GlomoPay RN SDK] Attempting to start checkout of ${checkoutUrl} from status: ${status}`);
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("[GlomoPay RN SDK] Cannot start checkout. Device is rooted or jailbroken.");
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,7 +769,7 @@ 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
- "[GlomoPay RN SDK] 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."
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
 
@@ -863,7 +835,7 @@ export function useLrsCheckout(
863
835
 
864
836
  if (errors.length > 0) {
865
837
  if (devMode) {
866
- console.error(`[GlomoPay RN SDK] Cannot start checkout. Validation failed.`);
838
+ console.error(`[Glomo-RN-SDK LRS] Cannot start checkout. Validation failed.`);
867
839
  }
868
840
  safeCallback(onSdkError, [errors], "onSdkError", devMode);
869
841
  // Tracking start() failure
@@ -884,7 +856,7 @@ export function useLrsCheckout(
884
856
  if (status === "payment_successful") {
885
857
  if (devMode) {
886
858
  console.log(
887
- `[GlomoPay RN SDK] Cannot start checkout. Current status: ${status}. Payment already successful.`
859
+ `[Glomo-RN-SDK LRS] Cannot start checkout. Current status: ${status}. Payment already successful.`
888
860
  );
889
861
  }
890
862
  // Tracking start() failure
@@ -905,10 +877,12 @@ export function useLrsCheckout(
905
877
  status !== "ready" &&
906
878
  status !== "payment_cancelled" &&
907
879
  status !== "payment_failed" &&
908
- status !== "payment_in_progress"
880
+ status !== "payment_in_progress" &&
881
+ status !== "bank_transfer_submitted" &&
882
+ status !== "pay_via_bank_completed"
909
883
  ) {
910
884
  if (devMode) {
911
- console.log(`[GlomoPay RN SDK] Cannot start checkout. Unknown status: ${status}.`);
885
+ console.log(`[Glomo-RN-SDK LRS] Cannot start checkout. Unknown status: ${status}.`);
912
886
  }
913
887
  // Tracking start() failure
914
888
  trackStartFailure(
@@ -926,7 +900,7 @@ export function useLrsCheckout(
926
900
 
927
901
  if (!checkoutUrl) {
928
902
  if (devMode) {
929
- console.error("[GlomoPay RN SDK] Cannot start checkout. Invalid checkout URL.");
903
+ console.error("[Glomo-RN-SDK LRS] Cannot start checkout. Invalid checkout URL.");
930
904
  }
931
905
  // Tracking start() failure
932
906
  trackStartFailure(
@@ -943,7 +917,7 @@ export function useLrsCheckout(
943
917
  }
944
918
 
945
919
  if (devMode) {
946
- console.log("[GlomoPay RN SDK] Starting checkout from previous state: " + status);
920
+ console.log("[Glomo-RN-SDK LRS] Starting checkout from previous state: " + status);
947
921
  }
948
922
 
949
923
  setShowFlowWebView(false);
@@ -956,7 +930,7 @@ export function useLrsCheckout(
956
930
 
957
931
  setShowCheckout(true);
958
932
  return true;
959
- }, [devMode, status, publicKey, orderId, baseCheckoutUrl, checkoutUrl, mockMode, onSdkError]);
933
+ }, [devMode, status, publicKey, orderId, baseCheckoutUrl, checkoutUrl, mockMode, onSdkError, server]);
960
934
 
961
935
  // Initializing Segment analytics
962
936
  useEffect(() => {
@@ -967,10 +941,16 @@ export function useLrsCheckout(
967
941
  useEffect(() => {
968
942
  if (orderId && publicKey) {
969
943
  // Only resetting the checkout flow if the current status is that of a terminal state
970
- if (status === "payment_successful" || status === "payment_failed" || status === "payment_cancelled") {
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
+ ) {
971
951
  if (devMode) {
972
952
  console.log(
973
- `[GlomoPay RN SDK] Resetting checkout status ${status} for new orderId ${orderId} and publicKey ${publicKey}`
953
+ `[Glomo-RN-SDK LRS] Resetting checkout status ${status} for new orderId ${orderId} and publicKey ${publicKey}`
974
954
  );
975
955
  }
976
956
  setStatus("ready");