@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
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.injectedScript = void 0;
|
|
4
|
+
/** Injection JavaScript for the Standard Checkout WebView */
|
|
5
|
+
exports.injectedScript = `
|
|
6
|
+
(function() {
|
|
7
|
+
// Log prefix for all messages originating from the standard checkout WebView
|
|
8
|
+
const LOG_PREFIX = 'STANDARD_WEBVIEW: ';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Formats an array of arguments into a single prefixed string for posting back to React Native.
|
|
12
|
+
* Objects are JSON-stringified; primitives are coerced to strings.
|
|
13
|
+
*/
|
|
14
|
+
function formatMessage(args) {
|
|
15
|
+
return args.map(function(arg) {
|
|
16
|
+
if (typeof arg === 'object') {
|
|
17
|
+
try {
|
|
18
|
+
return LOG_PREFIX + JSON.stringify(arg, null, 2);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return LOG_PREFIX + '[unserializable object]';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return LOG_PREFIX + String(arg);
|
|
24
|
+
}).join(' ');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Saving original console methods before overriding (must be declared before safePostMessage references them)
|
|
28
|
+
const originalLog = console.log;
|
|
29
|
+
const originalWarn = console.warn;
|
|
30
|
+
const originalError = console.error;
|
|
31
|
+
const originalInfo = console.info;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Safely posts a message to ReactNativeWebView with a guard check.
|
|
35
|
+
* Prevents crashes if the WebView bridge is not yet ready or has been torn down.
|
|
36
|
+
*/
|
|
37
|
+
function safePostMessage(payload) {
|
|
38
|
+
try {
|
|
39
|
+
if (window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === 'function') {
|
|
40
|
+
window.ReactNativeWebView.postMessage(JSON.stringify(payload));
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
originalError && originalError.call(console, LOG_PREFIX + 'Failed to post message to ReactNativeWebView', error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Overriding console methods to forward logs back to React Native
|
|
48
|
+
|
|
49
|
+
console.log = function(...args) {
|
|
50
|
+
originalLog.apply(console, args);
|
|
51
|
+
safePostMessage({
|
|
52
|
+
type: 'console',
|
|
53
|
+
level: 'log',
|
|
54
|
+
message: formatMessage(args)
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
console.warn = function(...args) {
|
|
59
|
+
originalWarn.apply(console, args);
|
|
60
|
+
safePostMessage({
|
|
61
|
+
type: 'console',
|
|
62
|
+
level: 'warn',
|
|
63
|
+
message: formatMessage(args)
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
console.error = function(...args) {
|
|
68
|
+
originalError.apply(console, args);
|
|
69
|
+
safePostMessage({
|
|
70
|
+
type: 'console',
|
|
71
|
+
level: 'error',
|
|
72
|
+
message: formatMessage(args)
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
console.info = function(...args) {
|
|
77
|
+
originalInfo.apply(console, args);
|
|
78
|
+
safePostMessage({
|
|
79
|
+
type: 'console',
|
|
80
|
+
level: 'info',
|
|
81
|
+
message: formatMessage(args)
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Intercepting fetch requests to log network activity
|
|
86
|
+
const originalFetch = window.fetch;
|
|
87
|
+
window.fetch = function(...args) {
|
|
88
|
+
const url = typeof args[0] === 'string' ? args[0] : args[0]?.url || 'Unknown URL';
|
|
89
|
+
safePostMessage({
|
|
90
|
+
type: 'console',
|
|
91
|
+
level: 'network',
|
|
92
|
+
message: LOG_PREFIX + 'FETCH REQUEST: ' + url
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return originalFetch.apply(this, args)
|
|
96
|
+
.then(response => {
|
|
97
|
+
safePostMessage({
|
|
98
|
+
type: 'console',
|
|
99
|
+
level: 'network',
|
|
100
|
+
message: LOG_PREFIX + 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
|
|
101
|
+
});
|
|
102
|
+
return response;
|
|
103
|
+
})
|
|
104
|
+
.catch(error => {
|
|
105
|
+
safePostMessage({
|
|
106
|
+
type: 'console',
|
|
107
|
+
level: 'error',
|
|
108
|
+
message: LOG_PREFIX + 'FETCH ERROR: ' + url + ' - ' + error.message
|
|
109
|
+
});
|
|
110
|
+
throw error;
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Intercepting XMLHttpRequest to log network activity
|
|
115
|
+
const originalOpen = XMLHttpRequest.prototype.open;
|
|
116
|
+
const originalSend = XMLHttpRequest.prototype.send;
|
|
117
|
+
|
|
118
|
+
XMLHttpRequest.prototype.open = function(method, url) {
|
|
119
|
+
this._url = url;
|
|
120
|
+
this._method = method;
|
|
121
|
+
return originalOpen.apply(this, arguments);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
XMLHttpRequest.prototype.send = function() {
|
|
125
|
+
safePostMessage({
|
|
126
|
+
type: 'console',
|
|
127
|
+
level: 'network',
|
|
128
|
+
message: LOG_PREFIX + 'XHR REQUEST: ' + this._method + ' ' + this._url
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
this.addEventListener('load', function() {
|
|
132
|
+
safePostMessage({
|
|
133
|
+
type: 'console',
|
|
134
|
+
level: 'network',
|
|
135
|
+
message: LOG_PREFIX + 'XHR RESPONSE: ' + this._url + ' - Status: ' + this.status
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
this.addEventListener('error', function() {
|
|
140
|
+
safePostMessage({
|
|
141
|
+
type: 'console',
|
|
142
|
+
level: 'error',
|
|
143
|
+
message: LOG_PREFIX + 'XHR ERROR: ' + this._url
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return originalSend.apply(this, arguments);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Intercepting programmatic form.submit() - force target="_blank" to "_self"
|
|
151
|
+
const originalSubmit = HTMLFormElement.prototype.submit;
|
|
152
|
+
HTMLFormElement.prototype.submit = function() {
|
|
153
|
+
if (this.target === '_blank') {
|
|
154
|
+
this.target = '_self';
|
|
155
|
+
}
|
|
156
|
+
return originalSubmit.call(this);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Intercepting window.open (for 3DS redirects, bank pages, etc.)
|
|
160
|
+
const originalWindowOpen = window.open;
|
|
161
|
+
window.open = function(url, target, features) {
|
|
162
|
+
safePostMessage({
|
|
163
|
+
type: 'window.open',
|
|
164
|
+
url: url,
|
|
165
|
+
target: target,
|
|
166
|
+
features: features
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Returning a mock window object so the caller does not crash on .close()/.focus() calls
|
|
170
|
+
return {
|
|
171
|
+
closed: false,
|
|
172
|
+
close: function() {
|
|
173
|
+
safePostMessage({
|
|
174
|
+
type: 'window.close'
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
focus: function() {},
|
|
178
|
+
blur: function() {}
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// Listening for unhandled errors
|
|
183
|
+
window.addEventListener('error', function(event) {
|
|
184
|
+
safePostMessage({
|
|
185
|
+
type: 'console',
|
|
186
|
+
level: 'error',
|
|
187
|
+
message: LOG_PREFIX + 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Listening for unhandled promise rejections
|
|
192
|
+
window.addEventListener('unhandledrejection', function(event) {
|
|
193
|
+
safePostMessage({
|
|
194
|
+
type: 'console',
|
|
195
|
+
level: 'error',
|
|
196
|
+
message: LOG_PREFIX + 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Listening for messages from the checkout page (payment events, lifecycle events)
|
|
201
|
+
window.addEventListener('message', function(event) {
|
|
202
|
+
console.log(LOG_PREFIX + 'Message received: ' + event.data);
|
|
203
|
+
safePostMessage({
|
|
204
|
+
type: 'message',
|
|
205
|
+
message: event.data
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Logging that injection is complete
|
|
210
|
+
console.log(LOG_PREFIX + 'GlomoPay WebView JavaScript injection complete');
|
|
211
|
+
|
|
212
|
+
true; // Required for injected JavaScript
|
|
213
|
+
})();
|
|
214
|
+
`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order type fetcher service.
|
|
3
|
+
* Calls the order API to determine whether a given orderId is an LRS or Standard checkout flow.
|
|
4
|
+
* Used by the unified GlomoCheckout component to delegate to the correct inner component.
|
|
5
|
+
*/
|
|
6
|
+
import { type GlomoServer } from "../config/base";
|
|
7
|
+
/** The two supported checkout flow types */
|
|
8
|
+
export type OrderType = "standard" | "lrs";
|
|
9
|
+
/** Discriminated union result - either a resolved order type or an error message */
|
|
10
|
+
export type OrderTypeResult = {
|
|
11
|
+
success: true;
|
|
12
|
+
orderType: OrderType;
|
|
13
|
+
} | {
|
|
14
|
+
success: false;
|
|
15
|
+
error: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Fetches the order type for the given orderId from the public API.
|
|
19
|
+
* Returns a discriminated union so the caller can handle success/failure without try-catch.
|
|
20
|
+
*/
|
|
21
|
+
export declare function fetchOrderType(options: {
|
|
22
|
+
orderId: string;
|
|
23
|
+
publicKey: string;
|
|
24
|
+
server?: GlomoServer;
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
devMode?: boolean;
|
|
27
|
+
}): Promise<OrderTypeResult>;
|
|
28
|
+
//# sourceMappingURL=order-type-fetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-type-fetcher.d.ts","sourceRoot":"","sources":["../../src/services/order-type-fetcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEvE,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,KAAK,CAAC;AAE3C,oFAAoF;AACpF,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1G;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC,eAAe,CAAC,CA4D3B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Order type fetcher service.
|
|
4
|
+
* Calls the order API to determine whether a given orderId is an LRS or Standard checkout flow.
|
|
5
|
+
* Used by the unified GlomoCheckout component to delegate to the correct inner component.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.fetchOrderType = fetchOrderType;
|
|
42
|
+
const axios_1 = __importStar(require("axios"));
|
|
43
|
+
const base_1 = require("../config/base");
|
|
44
|
+
/**
|
|
45
|
+
* Fetches the order type for the given orderId from the public API.
|
|
46
|
+
* Returns a discriminated union so the caller can handle success/failure without try-catch.
|
|
47
|
+
*/
|
|
48
|
+
async function fetchOrderType(options) {
|
|
49
|
+
var _a;
|
|
50
|
+
try {
|
|
51
|
+
// Resolving the API base URL from the server config
|
|
52
|
+
const config = (0, base_1.resolveServerConfig)(options.server);
|
|
53
|
+
const apiUrl = `${config.baseUrl.api}/api/public/v1/order/${options.orderId}`;
|
|
54
|
+
if (options.devMode) {
|
|
55
|
+
console.log(`[Glomo-RN-SDK] Order type API URL: ${apiUrl}`);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Calling the order API with the publicKey as Bearer token.
|
|
59
|
+
* Cache-busting headers prevent okhttp (Android) from sending If-None-Match on repeat calls,
|
|
60
|
+
* which would cause the server to return a 304 with an empty body and break order type detection.
|
|
61
|
+
*/
|
|
62
|
+
const response = await axios_1.default.get(apiUrl, {
|
|
63
|
+
headers: {
|
|
64
|
+
Authorization: `Bearer ${options.publicKey}`,
|
|
65
|
+
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
66
|
+
Pragma: "no-cache",
|
|
67
|
+
},
|
|
68
|
+
timeout: (_a = options.timeoutMs) !== null && _a !== void 0 ? _a : 30000,
|
|
69
|
+
});
|
|
70
|
+
const data = response.data;
|
|
71
|
+
// Validating that the returned order type is one of the expected values
|
|
72
|
+
if (data.orderType === "lrs" || data.orderType === "standard") {
|
|
73
|
+
if (options.devMode) {
|
|
74
|
+
console.log(`[Glomo-RN-SDK] Order type for orderId: ${options.orderId} successfully determined to be ${data.orderType}`);
|
|
75
|
+
}
|
|
76
|
+
return { success: true, orderType: data.orderType };
|
|
77
|
+
}
|
|
78
|
+
if (options.devMode) {
|
|
79
|
+
console.log(`[Glomo-RN-SDK] Unexpected orderType ${data.orderType} provided for ${options.orderId}`);
|
|
80
|
+
}
|
|
81
|
+
return { success: false, error: `Unexpected order type from ${apiUrl}: ${data.orderType}` };
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// Extracting the error message for logging and returning
|
|
85
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
86
|
+
const config = (0, base_1.resolveServerConfig)(options.server);
|
|
87
|
+
const apiUrl = `${config.baseUrl.api}/api/public/v1/order/${options.orderId}`;
|
|
88
|
+
if (options.devMode) {
|
|
89
|
+
// Logging additional response details for Axios errors (status code, response body)
|
|
90
|
+
if ((0, axios_1.isAxiosError)(error) && error.response) {
|
|
91
|
+
console.log(`[Glomo-RN-SDK] orderType determination failed for ${options.orderId} from ${apiUrl}: ${message} (${error.response.status}) and data:`, JSON.stringify(error.response.data));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.log(`[Glomo-RN-SDK] orderType determination failed for ${options.orderId} from ${apiUrl}: ${message}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { success: false, error: `Failed to determine order type for ${apiUrl}: ${message}` };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Unified v3 type definitions for GlomoCheckout */
|
|
2
|
+
import { type GlomoServer } from "../config/base";
|
|
3
|
+
import { type SdkError } from "../utils/analytics";
|
|
4
|
+
/** The payload for a successful or failed payment (unified across LRS and standard) */
|
|
5
|
+
export interface GlomoCheckoutPayload {
|
|
6
|
+
orderId: string;
|
|
7
|
+
paymentId: string;
|
|
8
|
+
signature: string;
|
|
9
|
+
}
|
|
10
|
+
/** The payload for a bank transfer submission */
|
|
11
|
+
export interface GlomoBankTransferPayload {
|
|
12
|
+
orderId: string;
|
|
13
|
+
senderAccountNumber: string;
|
|
14
|
+
transactionReference: string;
|
|
15
|
+
}
|
|
16
|
+
/** The payload for a pay via bank - bank connection successful event */
|
|
17
|
+
export interface GlomoPayViaBankConnectionPayload {
|
|
18
|
+
bankIdentifier: string;
|
|
19
|
+
cooldownPeriodInMinutes: number;
|
|
20
|
+
bankName: string;
|
|
21
|
+
bankImageSrc: string;
|
|
22
|
+
bankImageAlt: string;
|
|
23
|
+
}
|
|
24
|
+
/** Unified checkout statuses - superset of LRS + standard statuses */
|
|
25
|
+
export type CheckoutStatus = "ready" | "detecting_order_type" | "payment_in_progress" | "payment_successful" | "payment_failed" | "payment_cancelled" | "bank_transfer_submitted" | "pay_via_bank_completed";
|
|
26
|
+
/**
|
|
27
|
+
* Ref handle for the unified checkout component.
|
|
28
|
+
* start() is async (returns Promise<boolean>) because the unified flow first detects order type
|
|
29
|
+
* via an API call before delegating to either the LRS or Standard inner component.
|
|
30
|
+
*/
|
|
31
|
+
export interface GlomoCheckoutRef {
|
|
32
|
+
start: () => Promise<boolean>;
|
|
33
|
+
getStatus: () => CheckoutStatus;
|
|
34
|
+
}
|
|
35
|
+
/** Props for the unified checkout component */
|
|
36
|
+
export interface GlomoCheckoutProps {
|
|
37
|
+
server?: GlomoServer;
|
|
38
|
+
publicKey: string;
|
|
39
|
+
orderId: string;
|
|
40
|
+
onPaymentSuccess: (payload: GlomoCheckoutPayload) => void;
|
|
41
|
+
onPaymentFailure: (payload: GlomoCheckoutPayload) => void;
|
|
42
|
+
onConnectionError?: (error: unknown) => void;
|
|
43
|
+
onPaymentTerminate?: () => void;
|
|
44
|
+
onSdkError?: (error: Array<SdkError>) => void;
|
|
45
|
+
onBankTransferSubmitted?: (payload: GlomoBankTransferPayload | null | undefined) => void;
|
|
46
|
+
onPayViaBankCompleted?: (payload: {
|
|
47
|
+
status: string;
|
|
48
|
+
}) => void;
|
|
49
|
+
onPayViaBankBankConnectionSuccessful?: (payload: GlomoPayViaBankConnectionPayload | null | undefined) => void;
|
|
50
|
+
onUserRefusedCameraPermissions?: () => void;
|
|
51
|
+
devMode?: boolean;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/types/checkout.ts"],"names":[],"mappings":"AAAA,oDAAoD;AAEpD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,uFAAuF;AACvF,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,iDAAiD;AACjD,MAAM,WAAW,wBAAwB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,oBAAoB,EAAE,MAAM,CAAC;CAChC;AAED,wEAAwE;AACxE,MAAM,WAAW,gCAAgC;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,uBAAuB,EAAE,MAAM,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,sEAAsE;AACtE,MAAM,MAAM,cAAc,GACpB,OAAO,GACP,sBAAsB,GACtB,qBAAqB,GACrB,oBAAoB,GACpB,gBAAgB,GAChB,mBAAmB,GACnB,yBAAyB,GACzB,wBAAwB,CAAC;AAE/B;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,cAAc,CAAC;CACnC;AAED,+CAA+C;AAC/C,MAAM,WAAW,kBAAkB;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC1D,gBAAgB,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC1D,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IAC9C,uBAAuB,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;IACzF,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC9D,oCAAoC,CAAC,EAAE,CAAC,OAAO,EAAE,gCAAgC,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;IAC9G,8BAA8B,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Type definitions for the Standard Checkout flow */
|
|
2
|
+
import { type GlomoServer } from "../config/base";
|
|
3
|
+
import { type SdkError } from "../utils/analytics";
|
|
4
|
+
import { type GlomoBankTransferPayload, type GlomoPayViaBankConnectionPayload } from "./checkout";
|
|
5
|
+
/** Standard checkout statuses */
|
|
6
|
+
export type StandardCheckoutStatus = "ready" | "payment_in_progress" | "payment_successful" | "payment_failed" | "payment_cancelled" | "bank_transfer_submitted" | "pay_via_bank_completed";
|
|
7
|
+
/** The payload for a successful or failed standard payment */
|
|
8
|
+
export interface GlomoStandardCheckoutPayload {
|
|
9
|
+
orderId: string;
|
|
10
|
+
paymentId: string;
|
|
11
|
+
signature: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Ref handle for the standard checkout component.
|
|
15
|
+
* start() is synchronous (returns boolean) because the standard flow does not need to detect
|
|
16
|
+
* order type - unlike the unified GlomoCheckoutRef whose start() is async (returns Promise<boolean>).
|
|
17
|
+
*/
|
|
18
|
+
export interface GlomoStandardCheckoutRef {
|
|
19
|
+
start: () => boolean;
|
|
20
|
+
getStatus: () => StandardCheckoutStatus;
|
|
21
|
+
}
|
|
22
|
+
/** Props for the standard checkout component */
|
|
23
|
+
export interface GlomoStandardCheckoutProps {
|
|
24
|
+
server?: GlomoServer;
|
|
25
|
+
publicKey: string;
|
|
26
|
+
orderId: string;
|
|
27
|
+
onPaymentSuccess: (payload: GlomoStandardCheckoutPayload) => void;
|
|
28
|
+
onPaymentFailure: (payload: GlomoStandardCheckoutPayload) => void;
|
|
29
|
+
onConnectionError?: (error: unknown) => void;
|
|
30
|
+
onPaymentTerminate?: () => void;
|
|
31
|
+
onSdkError?: (error: Array<SdkError>) => void;
|
|
32
|
+
onBankTransferSubmitted?: (payload: GlomoBankTransferPayload | null | undefined) => void;
|
|
33
|
+
onPayViaBankCompleted?: (payload: {
|
|
34
|
+
status: string;
|
|
35
|
+
}) => void;
|
|
36
|
+
onPayViaBankBankConnectionSuccessful?: (payload: GlomoPayViaBankConnectionPayload | null | undefined) => void;
|
|
37
|
+
onUserRefusedCameraPermissions?: () => void;
|
|
38
|
+
devMode?: boolean;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=standard-checkout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-checkout.d.ts","sourceRoot":"","sources":["../../src/types/standard-checkout.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,wBAAwB,EAAE,KAAK,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAElG,iCAAiC;AACjC,MAAM,MAAM,sBAAsB,GAC5B,OAAO,GACP,qBAAqB,GACrB,oBAAoB,GACpB,gBAAgB,GAChB,mBAAmB,GACnB,yBAAyB,GACzB,wBAAwB,CAAC;AAE/B,8DAA8D;AAC9D,MAAM,WAAW,4BAA4B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACrC,KAAK,EAAE,MAAM,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,sBAAsB,CAAC;CAC3C;AAED,gDAAgD;AAChD,MAAM,WAAW,0BAA0B;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,CAAC,OAAO,EAAE,4BAA4B,KAAK,IAAI,CAAC;IAClE,gBAAgB,EAAE,CAAC,OAAO,EAAE,4BAA4B,KAAK,IAAI,CAAC;IAClE,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IAC9C,uBAAuB,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;IACzF,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC9D,oCAAoC,CAAC,EAAE,CAAC,OAAO,EAAE,gCAAgC,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;IAC9G,8BAA8B,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified wrapper hook - detects order type (LRS vs Standard) via the order API
|
|
3
|
+
* and delegates to the appropriate inner checkout hook once resolved.
|
|
4
|
+
*/
|
|
5
|
+
import { type GlomoCheckoutProps, type CheckoutStatus } from "./types/checkout";
|
|
6
|
+
import { type GlomoLrsCheckoutRef } from "./glomo-lrs-checkout";
|
|
7
|
+
import { type GlomoStandardCheckoutRef } from "./types/standard-checkout";
|
|
8
|
+
import { type OrderType } from "./services/order-type-fetcher";
|
|
9
|
+
/** The return values for the useGlomoCheckout hook */
|
|
10
|
+
export interface UseGlomoCheckoutReturn {
|
|
11
|
+
orderType: OrderType | null;
|
|
12
|
+
detecting: boolean;
|
|
13
|
+
start: () => Promise<boolean>;
|
|
14
|
+
getStatus: () => CheckoutStatus;
|
|
15
|
+
innerLrsRef: React.RefObject<GlomoLrsCheckoutRef>;
|
|
16
|
+
innerStandardRef: React.RefObject<GlomoStandardCheckoutRef>;
|
|
17
|
+
props: GlomoCheckoutProps;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The main unified checkout hook.
|
|
21
|
+
* Validates inputs, detects order type via API, then auto-starts the resolved inner component.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useGlomoCheckout(props: GlomoCheckoutProps): UseGlomoCheckoutReturn;
|
|
24
|
+
//# sourceMappingURL=use-glomo-checkout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-glomo-checkout.d.ts","sourceRoot":"","sources":["../src/use-glomo-checkout.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,KAAK,SAAS,EAAkB,MAAM,+BAA+B,CAAC;AAS/E,sDAAsD;AACtD,MAAM,WAAW,sBAAsB;IACnC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,cAAc,CAAC;IAChC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAClD,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAC;IAC5D,KAAK,EAAE,kBAAkB,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,kBAAkB,GAAG,sBAAsB,CAiMlF"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unified wrapper hook - detects order type (LRS vs Standard) via the order API
|
|
4
|
+
* and delegates to the appropriate inner checkout hook once resolved.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useGlomoCheckout = useGlomoCheckout;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const order_type_fetcher_1 = require("./services/order-type-fetcher");
|
|
10
|
+
const validation_1 = require("./utils/validation");
|
|
11
|
+
const analytics_1 = require("./utils/analytics");
|
|
12
|
+
/**
|
|
13
|
+
* The main unified checkout hook.
|
|
14
|
+
* Validates inputs, detects order type via API, then auto-starts the resolved inner component.
|
|
15
|
+
*/
|
|
16
|
+
function useGlomoCheckout(props) {
|
|
17
|
+
const { server, publicKey, orderId, onSdkError, devMode = false } = props;
|
|
18
|
+
// Order type resolved from the API - null until detection completes
|
|
19
|
+
const [orderType, setOrderType] = (0, react_1.useState)(null);
|
|
20
|
+
// Whether order type detection is in progress
|
|
21
|
+
const [detecting, setDetecting] = (0, react_1.useState)(false);
|
|
22
|
+
// Refs for the inner LRS and Standard checkout components
|
|
23
|
+
const innerLrsRef = (0, react_1.useRef)(null);
|
|
24
|
+
const innerStandardRef = (0, react_1.useRef)(null);
|
|
25
|
+
/**
|
|
26
|
+
* Tracking whether start() has been called and the inner component needs to be auto-started.
|
|
27
|
+
* This bridges the gap between order type resolution (async) and inner component mount (next render).
|
|
28
|
+
*/
|
|
29
|
+
const pendingStartRef = (0, react_1.useRef)(false);
|
|
30
|
+
/**
|
|
31
|
+
* Generation counter for stale fetch detection.
|
|
32
|
+
* Incremented on every start() call and on orderId/publicKey changes. After fetchOrderType
|
|
33
|
+
* resolves, the result is discarded if the generation has moved on (props changed mid-flight).
|
|
34
|
+
*/
|
|
35
|
+
const fetchGenerationRef = (0, react_1.useRef)(0);
|
|
36
|
+
/**
|
|
37
|
+
* Holds the resolve function for the pending start() promise.
|
|
38
|
+
* This allows the useEffect that auto-starts the inner component to resolve the merchant's
|
|
39
|
+
* awaited promise with the actual result of the inner start().
|
|
40
|
+
*/
|
|
41
|
+
const pendingStartResolveRef = (0, react_1.useRef)(null);
|
|
42
|
+
// Deriving the unified checkout status from the inner component's status
|
|
43
|
+
const getStatus = (0, react_1.useCallback)(() => {
|
|
44
|
+
if (detecting) {
|
|
45
|
+
return "detecting_order_type";
|
|
46
|
+
}
|
|
47
|
+
// Delegating to the inner component's getStatus() once order type is resolved
|
|
48
|
+
if (orderType === "lrs" && innerLrsRef.current) {
|
|
49
|
+
return innerLrsRef.current.getStatus();
|
|
50
|
+
}
|
|
51
|
+
if (orderType === "standard" && innerStandardRef.current) {
|
|
52
|
+
return innerStandardRef.current.getStatus();
|
|
53
|
+
}
|
|
54
|
+
return "ready";
|
|
55
|
+
}, [detecting, orderType]);
|
|
56
|
+
/**
|
|
57
|
+
* Initiator for the unified checkout flow.
|
|
58
|
+
* Validates inputs, calls the order type detection API, and marks the inner component for auto-start.
|
|
59
|
+
*/
|
|
60
|
+
const start = (0, react_1.useCallback)(async () => {
|
|
61
|
+
// If a previous start() call is still pending, resolve it as false before proceeding
|
|
62
|
+
if (pendingStartResolveRef.current) {
|
|
63
|
+
pendingStartResolveRef.current(false);
|
|
64
|
+
pendingStartResolveRef.current = null;
|
|
65
|
+
}
|
|
66
|
+
if (devMode) {
|
|
67
|
+
console.log("[Glomo-RN-SDK] start() called");
|
|
68
|
+
}
|
|
69
|
+
// Validating inputs before making the API call
|
|
70
|
+
const errors = [];
|
|
71
|
+
if (!(0, validation_1.isValidPublicKey)(publicKey)) {
|
|
72
|
+
errors.push({
|
|
73
|
+
type: "validation_error",
|
|
74
|
+
message: "Invalid publicKey: must start with 'live_', 'mock_', or 'test_' and be a valid string",
|
|
75
|
+
field: "publicKey",
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (!(0, validation_1.isValidOrderId)(orderId)) {
|
|
79
|
+
errors.push({
|
|
80
|
+
type: "validation_error",
|
|
81
|
+
message: "Invalid orderId: must start with 'order_' and be a valid string",
|
|
82
|
+
field: "orderId",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Reporting validation errors and aborting if any
|
|
86
|
+
if (errors.length > 0) {
|
|
87
|
+
if (devMode) {
|
|
88
|
+
console.error("[Glomo-RN-SDK] Validation failed.");
|
|
89
|
+
}
|
|
90
|
+
(0, validation_1.safeCallback)(onSdkError, [errors], "onSdkError", devMode);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
// Detecting order type via the API
|
|
94
|
+
setDetecting(true);
|
|
95
|
+
const thisGeneration = ++fetchGenerationRef.current;
|
|
96
|
+
if (devMode) {
|
|
97
|
+
console.log("[Glomo-RN-SDK] Detecting order type...");
|
|
98
|
+
}
|
|
99
|
+
(0, analytics_1.trackOrderTypeDetectionStarted)(orderId, publicKey, devMode);
|
|
100
|
+
const result = await (0, order_type_fetcher_1.fetchOrderType)({ orderId, publicKey, server, devMode });
|
|
101
|
+
// Discarding stale result if props changed while the fetch was in flight
|
|
102
|
+
if (thisGeneration !== fetchGenerationRef.current) {
|
|
103
|
+
if (devMode) {
|
|
104
|
+
console.log("[Glomo-RN-SDK] Discarding stale order type result (props changed mid-flight)");
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
setDetecting(false);
|
|
109
|
+
// Handling detection failure
|
|
110
|
+
if (!result.success) {
|
|
111
|
+
if (devMode) {
|
|
112
|
+
console.error(`[Glomo-RN-SDK] Order type detection failed: ${result.error}`);
|
|
113
|
+
}
|
|
114
|
+
(0, analytics_1.trackOrderTypeDetectionFailed)(orderId, publicKey, result.error, devMode);
|
|
115
|
+
(0, validation_1.safeCallback)(onSdkError, [[{ type: "validation_error", message: result.error }]], "onSdkError", devMode);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (devMode) {
|
|
119
|
+
console.log(`[Glomo-RN-SDK] Order type resolved: ${result.orderType}`);
|
|
120
|
+
}
|
|
121
|
+
(0, analytics_1.trackOrderTypeDetectionResolved)(orderId, publicKey, result.orderType, devMode);
|
|
122
|
+
// Setting the resolved order type - this triggers a re-render that mounts the inner component
|
|
123
|
+
setOrderType(result.orderType);
|
|
124
|
+
// Returning a promise that resolves only when the inner component's start() completes
|
|
125
|
+
return new Promise((resolve) => {
|
|
126
|
+
pendingStartResolveRef.current = resolve;
|
|
127
|
+
pendingStartRef.current = true;
|
|
128
|
+
});
|
|
129
|
+
}, [devMode, publicKey, orderId, server, onSdkError]);
|
|
130
|
+
/**
|
|
131
|
+
* Auto-starting the inner component after order type is resolved and the component has rendered.
|
|
132
|
+
* The pendingStartRef bridges the async gap: start() sets it, and this effect fires after
|
|
133
|
+
* the inner component mounts in the next render cycle.
|
|
134
|
+
*/
|
|
135
|
+
(0, react_1.useEffect)(() => {
|
|
136
|
+
if (!pendingStartRef.current || !orderType) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// Forwarding start() to the appropriate inner component
|
|
140
|
+
let started = false;
|
|
141
|
+
if (orderType === "lrs" && innerLrsRef.current) {
|
|
142
|
+
pendingStartRef.current = false;
|
|
143
|
+
started = innerLrsRef.current.start();
|
|
144
|
+
if (devMode) {
|
|
145
|
+
console.log(`[Glomo-RN-SDK] LRS inner start() returned: ${started}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (orderType === "standard" && innerStandardRef.current) {
|
|
149
|
+
pendingStartRef.current = false;
|
|
150
|
+
started = innerStandardRef.current.start();
|
|
151
|
+
if (devMode) {
|
|
152
|
+
console.log(`[Glomo-RN-SDK] Standard inner start() returned: ${started}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Resolving the merchant's awaited start() promise with the inner component's result
|
|
156
|
+
if (pendingStartResolveRef.current) {
|
|
157
|
+
pendingStartResolveRef.current(started);
|
|
158
|
+
pendingStartResolveRef.current = null;
|
|
159
|
+
}
|
|
160
|
+
}, [orderType, devMode]);
|
|
161
|
+
// Resetting order type state when orderId or publicKey changes to force re-detection
|
|
162
|
+
(0, react_1.useEffect)(() => {
|
|
163
|
+
// Invalidating any in-flight fetchOrderType call so its stale result is discarded
|
|
164
|
+
fetchGenerationRef.current++;
|
|
165
|
+
if (pendingStartResolveRef.current) {
|
|
166
|
+
pendingStartResolveRef.current(false);
|
|
167
|
+
pendingStartResolveRef.current = null;
|
|
168
|
+
}
|
|
169
|
+
setOrderType(null);
|
|
170
|
+
setDetecting(false);
|
|
171
|
+
pendingStartRef.current = false;
|
|
172
|
+
}, [orderId, publicKey]);
|
|
173
|
+
return {
|
|
174
|
+
orderType,
|
|
175
|
+
detecting,
|
|
176
|
+
start,
|
|
177
|
+
getStatus,
|
|
178
|
+
innerLrsRef,
|
|
179
|
+
innerStandardRef,
|
|
180
|
+
props,
|
|
181
|
+
};
|
|
182
|
+
}
|