@glomopay/react-native-sdk 3.0.1 → 3.1.0
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 +15 -0
- package/MIGRATION.md +50 -0
- package/README.md +131 -50
- package/lib/glomo-checkout.d.ts.map +1 -1
- package/lib/glomo-checkout.js +38 -1
- package/lib/glomo-standard-checkout.d.ts +20 -0
- package/lib/glomo-standard-checkout.d.ts.map +1 -1
- package/lib/glomo-standard-checkout.js +14 -3
- package/lib/glomo-subscriptions-checkout.d.ts +8 -0
- package/lib/glomo-subscriptions-checkout.d.ts.map +1 -0
- package/lib/glomo-subscriptions-checkout.js +85 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/types/checkout.d.ts +15 -3
- package/lib/types/checkout.d.ts.map +1 -1
- package/lib/types/subscriptions-checkout.d.ts +29 -0
- package/lib/types/subscriptions-checkout.d.ts.map +1 -0
- package/lib/types/subscriptions-checkout.js +3 -0
- package/lib/use-glomo-checkout.d.ts +34 -4
- package/lib/use-glomo-checkout.d.ts.map +1 -1
- package/lib/use-glomo-checkout.js +92 -13
- package/lib/use-standard-checkout.d.ts +11 -2
- package/lib/use-standard-checkout.d.ts.map +1 -1
- package/lib/use-standard-checkout.js +52 -35
- package/lib/utils/analytics.d.ts +87 -2
- package/lib/utils/analytics.d.ts.map +1 -1
- package/lib/utils/analytics.js +356 -15
- package/lib/utils/device-compliance.d.ts.map +1 -1
- package/lib/utils/device-compliance.js +0 -1
- package/package.json +15 -4
- package/src/glomo-checkout.tsx +79 -5
- package/src/glomo-standard-checkout.tsx +33 -4
- package/src/glomo-subscriptions-checkout.tsx +83 -0
- package/src/index.ts +1 -1
- package/src/types/checkout.ts +10 -3
- package/src/types/subscriptions-checkout.ts +31 -0
- package/src/use-glomo-checkout.tsx +158 -17
- package/src/use-standard-checkout.tsx +70 -52
- package/src/utils/analytics.ts +482 -17
- package/src/utils/device-compliance.ts +0 -1
|
@@ -10,23 +10,7 @@ import { initializeSegment } from "./config/segment";
|
|
|
10
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
|
-
import {
|
|
14
|
-
trackStandardStartAttempt,
|
|
15
|
-
trackStandardStartSuccess,
|
|
16
|
-
trackStandardStartFailure,
|
|
17
|
-
trackStandardWindowOpen,
|
|
18
|
-
trackStandardWindowClose,
|
|
19
|
-
trackStandardPaymentSuccess,
|
|
20
|
-
trackStandardPaymentFailure,
|
|
21
|
-
trackStandardPaymentTerminate,
|
|
22
|
-
trackStandardConnectionError,
|
|
23
|
-
trackStandardSdkError,
|
|
24
|
-
trackStandardInvalidMessageReceived,
|
|
25
|
-
trackStandardBankTransferSubmitted,
|
|
26
|
-
trackStandardPayViaBankCompleted,
|
|
27
|
-
trackStandardPayViaBankBankConnectionSuccessful,
|
|
28
|
-
type SdkError,
|
|
29
|
-
} from "./utils/analytics";
|
|
13
|
+
import { type SdkError, type CheckoutAnalyticsTrackers, standardCheckoutTrackers } from "./utils/analytics";
|
|
30
14
|
|
|
31
15
|
import { type GlomoBankTransferPayload, type GlomoPayViaBankConnectionPayload } from "./types/checkout";
|
|
32
16
|
import { type StandardCheckoutStatus, type GlomoStandardCheckoutPayload } from "./types/standard-checkout";
|
|
@@ -79,6 +63,16 @@ export interface UseStandardCheckoutReturn {
|
|
|
79
63
|
injectedFlow?: string;
|
|
80
64
|
}
|
|
81
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Internal options for useStandardCheckout.
|
|
68
|
+
* Used by subscription checkout to inject subscription-specific analytics trackers.
|
|
69
|
+
* Not exported to merchants.
|
|
70
|
+
*/
|
|
71
|
+
export interface UseStandardCheckoutInternalOptions {
|
|
72
|
+
analyticsTrackers?: CheckoutAnalyticsTrackers;
|
|
73
|
+
_skipOrderIdValidation?: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
82
76
|
/** The main SDK hook for the GlomoPay Standard Checkout flow */
|
|
83
77
|
export function useStandardCheckout(
|
|
84
78
|
{
|
|
@@ -96,8 +90,11 @@ export function useStandardCheckout(
|
|
|
96
90
|
onUserRefusedCameraPermissions,
|
|
97
91
|
devMode = false,
|
|
98
92
|
}: UseStandardCheckoutOptions,
|
|
99
|
-
mockMode: boolean
|
|
93
|
+
mockMode: boolean,
|
|
94
|
+
internalOptions?: UseStandardCheckoutInternalOptions
|
|
100
95
|
): UseStandardCheckoutReturn {
|
|
96
|
+
// Resolving analytics trackers - defaults to standard, subscription flow overrides
|
|
97
|
+
const trackers = internalOptions?.analyticsTrackers ?? standardCheckoutTrackers;
|
|
101
98
|
// Refs for the WebViews
|
|
102
99
|
const mainWebViewRef = useRef<WebView>(null);
|
|
103
100
|
const flowWebViewRef = useRef<WebView>(null);
|
|
@@ -204,7 +201,14 @@ export function useStandardCheckout(
|
|
|
204
201
|
// Calling onConnectionError callback if provided
|
|
205
202
|
safeCallback(onConnectionError, [nativeEvent], "onConnectionError", devMode);
|
|
206
203
|
// Tracking connection error
|
|
207
|
-
|
|
204
|
+
trackers.trackConnectionError(
|
|
205
|
+
orderId,
|
|
206
|
+
nativeEvent?.code,
|
|
207
|
+
publicKey,
|
|
208
|
+
devMode,
|
|
209
|
+
mockMode,
|
|
210
|
+
checkoutUrl
|
|
211
|
+
);
|
|
208
212
|
} else {
|
|
209
213
|
if (devMode) {
|
|
210
214
|
console.error("[Glomo-RN-SDK Standard] WebView error:", nativeEvent);
|
|
@@ -216,7 +220,7 @@ export function useStandardCheckout(
|
|
|
216
220
|
}
|
|
217
221
|
}
|
|
218
222
|
},
|
|
219
|
-
[devMode, onConnectionError, checkoutUrl, orderId, publicKey, mockMode]
|
|
223
|
+
[devMode, onConnectionError, checkoutUrl, orderId, publicKey, mockMode, trackers]
|
|
220
224
|
);
|
|
221
225
|
|
|
222
226
|
// Handler for the WebView HTTP errors
|
|
@@ -252,7 +256,7 @@ export function useStandardCheckout(
|
|
|
252
256
|
console.warn("[Glomo-RN-SDK Standard] Invalid message data from MainWebView");
|
|
253
257
|
}
|
|
254
258
|
// Tracking invalid message received
|
|
255
|
-
|
|
259
|
+
trackers.trackInvalidMessageReceived(
|
|
256
260
|
"main",
|
|
257
261
|
data,
|
|
258
262
|
checkoutUrl,
|
|
@@ -289,7 +293,7 @@ export function useStandardCheckout(
|
|
|
289
293
|
setFlowWebViewUrl(url);
|
|
290
294
|
setShowFlowWebView(true);
|
|
291
295
|
// Tracking window.open interception
|
|
292
|
-
|
|
296
|
+
trackers.trackWindowOpen("main", url, orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
293
297
|
} else {
|
|
294
298
|
if (devMode) {
|
|
295
299
|
console.log(
|
|
@@ -310,7 +314,7 @@ export function useStandardCheckout(
|
|
|
310
314
|
setShowFlowWebView(false);
|
|
311
315
|
setFlowWebViewUrl("");
|
|
312
316
|
// Tracking window.close interception
|
|
313
|
-
|
|
317
|
+
trackers.trackWindowClose("main", orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
314
318
|
return;
|
|
315
319
|
}
|
|
316
320
|
|
|
@@ -334,7 +338,7 @@ export function useStandardCheckout(
|
|
|
334
338
|
setStatus("payment_successful");
|
|
335
339
|
safeCallback(onPaymentSuccess, [payload], "onPaymentSuccess", devMode);
|
|
336
340
|
// Tracking payment success callback
|
|
337
|
-
|
|
341
|
+
trackers.trackPaymentSuccess(
|
|
338
342
|
payload.orderId,
|
|
339
343
|
payload.paymentId,
|
|
340
344
|
publicKey,
|
|
@@ -365,7 +369,7 @@ export function useStandardCheckout(
|
|
|
365
369
|
setStatus("payment_failed");
|
|
366
370
|
safeCallback(onPaymentFailure, [payload], "onPaymentFailure", devMode);
|
|
367
371
|
// Tracking payment failure callback
|
|
368
|
-
|
|
372
|
+
trackers.trackPaymentFailure(
|
|
369
373
|
payload.orderId,
|
|
370
374
|
payload.paymentId,
|
|
371
375
|
publicKey,
|
|
@@ -403,7 +407,7 @@ export function useStandardCheckout(
|
|
|
403
407
|
"onBankTransferSubmitted",
|
|
404
408
|
devMode
|
|
405
409
|
);
|
|
406
|
-
|
|
410
|
+
trackers.trackBankTransferSubmitted(orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
407
411
|
return;
|
|
408
412
|
}
|
|
409
413
|
|
|
@@ -427,7 +431,7 @@ export function useStandardCheckout(
|
|
|
427
431
|
"onPayViaBankBankConnectionSuccessful",
|
|
428
432
|
devMode
|
|
429
433
|
);
|
|
430
|
-
|
|
434
|
+
trackers.trackPayViaBankBankConnectionSuccessful(
|
|
431
435
|
orderId,
|
|
432
436
|
publicKey,
|
|
433
437
|
payload?.bankIdentifier ?? "",
|
|
@@ -470,7 +474,7 @@ export function useStandardCheckout(
|
|
|
470
474
|
"onPayViaBankCompleted",
|
|
471
475
|
devMode
|
|
472
476
|
);
|
|
473
|
-
|
|
477
|
+
trackers.trackPayViaBankCompleted(
|
|
474
478
|
orderId,
|
|
475
479
|
publicKey,
|
|
476
480
|
payload?.status ?? "unknown",
|
|
@@ -491,7 +495,7 @@ export function useStandardCheckout(
|
|
|
491
495
|
setFlowWebViewUrl("");
|
|
492
496
|
safeCallback(onPaymentTerminate, [], "onPaymentTerminate", devMode);
|
|
493
497
|
// Tracking payment terminate callback
|
|
494
|
-
|
|
498
|
+
trackers.trackPaymentTerminate(
|
|
495
499
|
orderId,
|
|
496
500
|
"checkout_closed",
|
|
497
501
|
publicKey,
|
|
@@ -520,6 +524,7 @@ export function useStandardCheckout(
|
|
|
520
524
|
orderId,
|
|
521
525
|
publicKey,
|
|
522
526
|
checkoutUrl,
|
|
527
|
+
trackers,
|
|
523
528
|
]
|
|
524
529
|
);
|
|
525
530
|
|
|
@@ -538,7 +543,7 @@ export function useStandardCheckout(
|
|
|
538
543
|
console.warn("[Glomo-RN-SDK Standard] Invalid message data from FlowWebView");
|
|
539
544
|
}
|
|
540
545
|
// Tracking invalid message received
|
|
541
|
-
|
|
546
|
+
trackers.trackInvalidMessageReceived(
|
|
542
547
|
"flow",
|
|
543
548
|
data,
|
|
544
549
|
flowWebViewUrl,
|
|
@@ -573,7 +578,7 @@ export function useStandardCheckout(
|
|
|
573
578
|
}
|
|
574
579
|
setFlowWebViewUrl(url);
|
|
575
580
|
// Tracking window.open interception
|
|
576
|
-
|
|
581
|
+
trackers.trackWindowOpen("flow", url, orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
577
582
|
} else {
|
|
578
583
|
if (devMode) {
|
|
579
584
|
console.log(
|
|
@@ -594,7 +599,7 @@ export function useStandardCheckout(
|
|
|
594
599
|
setShowFlowWebView(false);
|
|
595
600
|
setFlowWebViewUrl("");
|
|
596
601
|
// Tracking window.close interception
|
|
597
|
-
|
|
602
|
+
trackers.trackWindowClose("flow", orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
598
603
|
return;
|
|
599
604
|
}
|
|
600
605
|
|
|
@@ -618,7 +623,7 @@ export function useStandardCheckout(
|
|
|
618
623
|
setStatus("payment_successful");
|
|
619
624
|
safeCallback(onPaymentSuccess, [payload], "onPaymentSuccess", devMode);
|
|
620
625
|
// Tracking payment success callback
|
|
621
|
-
|
|
626
|
+
trackers.trackPaymentSuccess(
|
|
622
627
|
payload.orderId,
|
|
623
628
|
payload.paymentId,
|
|
624
629
|
publicKey,
|
|
@@ -652,7 +657,7 @@ export function useStandardCheckout(
|
|
|
652
657
|
setStatus("payment_failed");
|
|
653
658
|
safeCallback(onPaymentFailure, [payload], "onPaymentFailure", devMode);
|
|
654
659
|
// Tracking payment failure callback
|
|
655
|
-
|
|
660
|
+
trackers.trackPaymentFailure(
|
|
656
661
|
payload.orderId,
|
|
657
662
|
payload.paymentId,
|
|
658
663
|
publicKey,
|
|
@@ -694,7 +699,7 @@ export function useStandardCheckout(
|
|
|
694
699
|
"onPayViaBankBankConnectionSuccessful",
|
|
695
700
|
devMode
|
|
696
701
|
);
|
|
697
|
-
|
|
702
|
+
trackers.trackPayViaBankBankConnectionSuccessful(
|
|
698
703
|
orderId,
|
|
699
704
|
publicKey,
|
|
700
705
|
payload?.bankIdentifier ?? "",
|
|
@@ -732,7 +737,7 @@ export function useStandardCheckout(
|
|
|
732
737
|
"onPayViaBankCompleted",
|
|
733
738
|
devMode
|
|
734
739
|
);
|
|
735
|
-
|
|
740
|
+
trackers.trackPayViaBankCompleted(
|
|
736
741
|
orderId,
|
|
737
742
|
publicKey,
|
|
738
743
|
payload?.status ?? "unknown",
|
|
@@ -760,6 +765,7 @@ export function useStandardCheckout(
|
|
|
760
765
|
publicKey,
|
|
761
766
|
flowWebViewUrl,
|
|
762
767
|
checkoutUrl,
|
|
768
|
+
trackers,
|
|
763
769
|
]
|
|
764
770
|
);
|
|
765
771
|
|
|
@@ -797,13 +803,13 @@ export function useStandardCheckout(
|
|
|
797
803
|
safeCallback(onPaymentTerminate, [], "onPaymentTerminate", devMode);
|
|
798
804
|
// Tracking payment terminate callback (user dismiss/back button)
|
|
799
805
|
const terminateSource = Platform.OS === "ios" ? "user_dismiss" : "back_button";
|
|
800
|
-
|
|
806
|
+
trackers.trackPaymentTerminate(orderId, terminateSource, publicKey, devMode, mockMode, checkoutUrl);
|
|
801
807
|
} catch (error) {
|
|
802
808
|
if (devMode) {
|
|
803
809
|
console.error("[Glomo-RN-SDK Standard] Error in handleModalBackButton:", error);
|
|
804
810
|
}
|
|
805
811
|
}
|
|
806
|
-
}, [showFlowWebView, devMode, onPaymentTerminate, status, orderId, publicKey, mockMode, checkoutUrl]);
|
|
812
|
+
}, [showFlowWebView, devMode, onPaymentTerminate, status, orderId, publicKey, mockMode, checkoutUrl, trackers]);
|
|
807
813
|
|
|
808
814
|
/** Closes the flow WebView and returns to the main checkout */
|
|
809
815
|
const handleFlowBack = useCallback(() => {
|
|
@@ -812,8 +818,8 @@ export function useStandardCheckout(
|
|
|
812
818
|
}
|
|
813
819
|
setShowFlowWebView(false);
|
|
814
820
|
setFlowWebViewUrl("");
|
|
815
|
-
|
|
816
|
-
}, [devMode, orderId, publicKey, mockMode, checkoutUrl]);
|
|
821
|
+
trackers.trackWindowClose("flow", orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
822
|
+
}, [devMode, orderId, publicKey, mockMode, checkoutUrl, trackers]);
|
|
817
823
|
|
|
818
824
|
/**
|
|
819
825
|
* Handler for WebView permission requests (e.g. camera access for bank authentication).
|
|
@@ -931,7 +937,7 @@ export function useStandardCheckout(
|
|
|
931
937
|
}
|
|
932
938
|
|
|
933
939
|
// Tracking start attempt with current status
|
|
934
|
-
|
|
940
|
+
trackers.trackStartAttempt(status, orderId, publicKey, devMode, mockMode, checkoutUrl, jailbreakDetectionInfo);
|
|
935
941
|
|
|
936
942
|
if (deviceComplianceCheck === true) {
|
|
937
943
|
// Device detected as compromised
|
|
@@ -946,7 +952,7 @@ export function useStandardCheckout(
|
|
|
946
952
|
];
|
|
947
953
|
safeCallback(onSdkError, [errors], "onSdkError", devMode);
|
|
948
954
|
// Tracking start() failure
|
|
949
|
-
|
|
955
|
+
trackers.trackStartFailure(
|
|
950
956
|
"device_forbidden",
|
|
951
957
|
orderId,
|
|
952
958
|
publicKey,
|
|
@@ -974,8 +980,8 @@ export function useStandardCheckout(
|
|
|
974
980
|
},
|
|
975
981
|
];
|
|
976
982
|
safeCallback(onSdkError, [errors], "onSdkError", devMode);
|
|
977
|
-
|
|
978
|
-
|
|
983
|
+
trackers.trackSdkError(errors, orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
984
|
+
trackers.trackStartFailure(
|
|
979
985
|
"validation_error",
|
|
980
986
|
orderId,
|
|
981
987
|
publicKey,
|
|
@@ -1000,7 +1006,7 @@ export function useStandardCheckout(
|
|
|
1000
1006
|
errors.push(error);
|
|
1001
1007
|
}
|
|
1002
1008
|
|
|
1003
|
-
if (!isValidOrderId(orderId)) {
|
|
1009
|
+
if (!internalOptions?._skipOrderIdValidation && !isValidOrderId(orderId)) {
|
|
1004
1010
|
const error: SdkError = {
|
|
1005
1011
|
type: "validation_error",
|
|
1006
1012
|
message: "Invalid orderId: must start with 'order_' and be a valid string",
|
|
@@ -1030,8 +1036,8 @@ export function useStandardCheckout(
|
|
|
1030
1036
|
}
|
|
1031
1037
|
safeCallback(onSdkError, [errors], "onSdkError", devMode);
|
|
1032
1038
|
// Tracking start() failure
|
|
1033
|
-
|
|
1034
|
-
|
|
1039
|
+
trackers.trackSdkError(errors, orderId, publicKey, devMode, mockMode, checkoutUrl);
|
|
1040
|
+
trackers.trackStartFailure(
|
|
1035
1041
|
"validation_error",
|
|
1036
1042
|
orderId,
|
|
1037
1043
|
publicKey,
|
|
@@ -1051,7 +1057,7 @@ export function useStandardCheckout(
|
|
|
1051
1057
|
);
|
|
1052
1058
|
}
|
|
1053
1059
|
// Tracking start() failure
|
|
1054
|
-
|
|
1060
|
+
trackers.trackStartFailure(
|
|
1055
1061
|
"payment_successful",
|
|
1056
1062
|
orderId,
|
|
1057
1063
|
publicKey,
|
|
@@ -1076,7 +1082,7 @@ export function useStandardCheckout(
|
|
|
1076
1082
|
console.log(`[Glomo-RN-SDK Standard] Cannot start checkout. Unknown status: ${status}.`);
|
|
1077
1083
|
}
|
|
1078
1084
|
// Tracking start() failure
|
|
1079
|
-
|
|
1085
|
+
trackers.trackStartFailure(
|
|
1080
1086
|
"invalid_status",
|
|
1081
1087
|
orderId,
|
|
1082
1088
|
publicKey,
|
|
@@ -1094,7 +1100,7 @@ export function useStandardCheckout(
|
|
|
1094
1100
|
console.error("[Glomo-RN-SDK Standard] Cannot start checkout. Invalid checkout URL.");
|
|
1095
1101
|
}
|
|
1096
1102
|
// Tracking start() failure
|
|
1097
|
-
|
|
1103
|
+
trackers.trackStartFailure(
|
|
1098
1104
|
"invalid_url",
|
|
1099
1105
|
orderId,
|
|
1100
1106
|
publicKey,
|
|
@@ -1118,12 +1124,24 @@ export function useStandardCheckout(
|
|
|
1118
1124
|
setStatus("payment_in_progress");
|
|
1119
1125
|
|
|
1120
1126
|
// Tracking successful start
|
|
1121
|
-
|
|
1127
|
+
trackers.trackStartSuccess(orderId, publicKey, devMode, mockMode, checkoutUrl, jailbreakDetectionInfo);
|
|
1122
1128
|
|
|
1123
1129
|
// Opening the checkout modal
|
|
1124
1130
|
setShowCheckout(true);
|
|
1125
1131
|
return true;
|
|
1126
|
-
}, [
|
|
1132
|
+
}, [
|
|
1133
|
+
devMode,
|
|
1134
|
+
status,
|
|
1135
|
+
publicKey,
|
|
1136
|
+
orderId,
|
|
1137
|
+
baseCheckoutUrl,
|
|
1138
|
+
checkoutUrl,
|
|
1139
|
+
mockMode,
|
|
1140
|
+
onSdkError,
|
|
1141
|
+
server,
|
|
1142
|
+
trackers,
|
|
1143
|
+
internalOptions,
|
|
1144
|
+
]);
|
|
1127
1145
|
|
|
1128
1146
|
// Initializing Segment analytics
|
|
1129
1147
|
useEffect(() => {
|