@glomopay/react-native-sdk 2.0.2 → 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 +79 -0
- package/MIGRATION.md +50 -0
- package/README.md +348 -316
- 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 +106 -0
- package/lib/glomo-lrs-checkout.js +9 -9
- package/lib/glomo-standard-checkout.d.ts +25 -0
- package/lib/glomo-standard-checkout.d.ts.map +1 -0
- package/lib/glomo-standard-checkout.js +229 -0
- 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 +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 +65 -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/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 +54 -0
- package/lib/use-glomo-checkout.d.ts.map +1 -0
- package/lib/use-glomo-checkout.js +261 -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 +76 -93
- package/lib/use-standard-checkout.d.ts +74 -0
- package/lib/use-standard-checkout.d.ts.map +1 -0
- package/lib/use-standard-checkout.js +849 -0
- package/lib/utils/analytics.d.ts +188 -2
- package/lib/utils/analytics.d.ts.map +1 -1
- package/lib/utils/analytics.js +636 -22
- package/lib/utils/device-compliance.d.ts.map +1 -1
- package/lib/utils/device-compliance.js +3 -4
- package/lib/utils/validation.d.ts.map +1 -1
- package/lib/utils/validation.js +7 -6
- package/package.json +17 -5
- package/src/config/base.ts +36 -17
- package/src/config/segment.ts +3 -3
- package/src/glomo-checkout.tsx +147 -0
- package/src/glomo-lrs-checkout.tsx +9 -9
- package/src/glomo-standard-checkout.tsx +353 -0
- package/src/glomo-subscriptions-checkout.tsx +83 -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 +72 -0
- package/src/types/standard-checkout.ts +49 -0
- package/src/types/subscriptions-checkout.ts +31 -0
- package/src/use-glomo-checkout.tsx +369 -0
- package/src/use-lrs-checkout.tsx +91 -111
- package/src/use-standard-checkout.tsx +1203 -0
- package/src/utils/analytics.ts +908 -34
- package/src/utils/device-compliance.ts +3 -4
- package/src/utils/validation.ts +7 -8
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/** Injection JavaScript for the Standard Checkout WebView */
|
|
2
|
+
export const injectedScript: string = `
|
|
3
|
+
(function() {
|
|
4
|
+
// Log prefix for all messages originating from the standard checkout WebView
|
|
5
|
+
const LOG_PREFIX = 'STANDARD_WEBVIEW: ';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Formats an array of arguments into a single prefixed string for posting back to React Native.
|
|
9
|
+
* Objects are JSON-stringified; primitives are coerced to strings.
|
|
10
|
+
*/
|
|
11
|
+
function formatMessage(args) {
|
|
12
|
+
return args.map(function(arg) {
|
|
13
|
+
if (typeof arg === 'object') {
|
|
14
|
+
try {
|
|
15
|
+
return LOG_PREFIX + JSON.stringify(arg, null, 2);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return LOG_PREFIX + '[unserializable object]';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return LOG_PREFIX + String(arg);
|
|
21
|
+
}).join(' ');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Saving original console methods before overriding (must be declared before safePostMessage references them)
|
|
25
|
+
const originalLog = console.log;
|
|
26
|
+
const originalWarn = console.warn;
|
|
27
|
+
const originalError = console.error;
|
|
28
|
+
const originalInfo = console.info;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Safely posts a message to ReactNativeWebView with a guard check.
|
|
32
|
+
* Prevents crashes if the WebView bridge is not yet ready or has been torn down.
|
|
33
|
+
*/
|
|
34
|
+
function safePostMessage(payload) {
|
|
35
|
+
try {
|
|
36
|
+
if (window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === 'function') {
|
|
37
|
+
window.ReactNativeWebView.postMessage(JSON.stringify(payload));
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
originalError && originalError.call(console, LOG_PREFIX + 'Failed to post message to ReactNativeWebView', error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Overriding console methods to forward logs back to React Native
|
|
45
|
+
|
|
46
|
+
console.log = function(...args) {
|
|
47
|
+
originalLog.apply(console, args);
|
|
48
|
+
safePostMessage({
|
|
49
|
+
type: 'console',
|
|
50
|
+
level: 'log',
|
|
51
|
+
message: formatMessage(args)
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
console.warn = function(...args) {
|
|
56
|
+
originalWarn.apply(console, args);
|
|
57
|
+
safePostMessage({
|
|
58
|
+
type: 'console',
|
|
59
|
+
level: 'warn',
|
|
60
|
+
message: formatMessage(args)
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
console.error = function(...args) {
|
|
65
|
+
originalError.apply(console, args);
|
|
66
|
+
safePostMessage({
|
|
67
|
+
type: 'console',
|
|
68
|
+
level: 'error',
|
|
69
|
+
message: formatMessage(args)
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
console.info = function(...args) {
|
|
74
|
+
originalInfo.apply(console, args);
|
|
75
|
+
safePostMessage({
|
|
76
|
+
type: 'console',
|
|
77
|
+
level: 'info',
|
|
78
|
+
message: formatMessage(args)
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Intercepting fetch requests to log network activity
|
|
83
|
+
const originalFetch = window.fetch;
|
|
84
|
+
window.fetch = function(...args) {
|
|
85
|
+
const url = typeof args[0] === 'string' ? args[0] : args[0]?.url || 'Unknown URL';
|
|
86
|
+
safePostMessage({
|
|
87
|
+
type: 'console',
|
|
88
|
+
level: 'network',
|
|
89
|
+
message: LOG_PREFIX + 'FETCH REQUEST: ' + url
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return originalFetch.apply(this, args)
|
|
93
|
+
.then(response => {
|
|
94
|
+
safePostMessage({
|
|
95
|
+
type: 'console',
|
|
96
|
+
level: 'network',
|
|
97
|
+
message: LOG_PREFIX + 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
|
|
98
|
+
});
|
|
99
|
+
return response;
|
|
100
|
+
})
|
|
101
|
+
.catch(error => {
|
|
102
|
+
safePostMessage({
|
|
103
|
+
type: 'console',
|
|
104
|
+
level: 'error',
|
|
105
|
+
message: LOG_PREFIX + 'FETCH ERROR: ' + url + ' - ' + error.message
|
|
106
|
+
});
|
|
107
|
+
throw error;
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Intercepting XMLHttpRequest to log network activity
|
|
112
|
+
const originalOpen = XMLHttpRequest.prototype.open;
|
|
113
|
+
const originalSend = XMLHttpRequest.prototype.send;
|
|
114
|
+
|
|
115
|
+
XMLHttpRequest.prototype.open = function(method, url) {
|
|
116
|
+
this._url = url;
|
|
117
|
+
this._method = method;
|
|
118
|
+
return originalOpen.apply(this, arguments);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
XMLHttpRequest.prototype.send = function() {
|
|
122
|
+
safePostMessage({
|
|
123
|
+
type: 'console',
|
|
124
|
+
level: 'network',
|
|
125
|
+
message: LOG_PREFIX + 'XHR REQUEST: ' + this._method + ' ' + this._url
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
this.addEventListener('load', function() {
|
|
129
|
+
safePostMessage({
|
|
130
|
+
type: 'console',
|
|
131
|
+
level: 'network',
|
|
132
|
+
message: LOG_PREFIX + 'XHR RESPONSE: ' + this._url + ' - Status: ' + this.status
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
this.addEventListener('error', function() {
|
|
137
|
+
safePostMessage({
|
|
138
|
+
type: 'console',
|
|
139
|
+
level: 'error',
|
|
140
|
+
message: LOG_PREFIX + 'XHR ERROR: ' + this._url
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return originalSend.apply(this, arguments);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// Intercepting programmatic form.submit() - force target="_blank" to "_self"
|
|
148
|
+
const originalSubmit = HTMLFormElement.prototype.submit;
|
|
149
|
+
HTMLFormElement.prototype.submit = function() {
|
|
150
|
+
if (this.target === '_blank') {
|
|
151
|
+
this.target = '_self';
|
|
152
|
+
}
|
|
153
|
+
return originalSubmit.call(this);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// Intercepting window.open (for 3DS redirects, bank pages, etc.)
|
|
157
|
+
const originalWindowOpen = window.open;
|
|
158
|
+
window.open = function(url, target, features) {
|
|
159
|
+
safePostMessage({
|
|
160
|
+
type: 'window.open',
|
|
161
|
+
url: url,
|
|
162
|
+
target: target,
|
|
163
|
+
features: features
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Returning a mock window object so the caller does not crash on .close()/.focus() calls
|
|
167
|
+
return {
|
|
168
|
+
closed: false,
|
|
169
|
+
close: function() {
|
|
170
|
+
safePostMessage({
|
|
171
|
+
type: 'window.close'
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
focus: function() {},
|
|
175
|
+
blur: function() {}
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Listening for unhandled errors
|
|
180
|
+
window.addEventListener('error', function(event) {
|
|
181
|
+
safePostMessage({
|
|
182
|
+
type: 'console',
|
|
183
|
+
level: 'error',
|
|
184
|
+
message: LOG_PREFIX + 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Listening for unhandled promise rejections
|
|
189
|
+
window.addEventListener('unhandledrejection', function(event) {
|
|
190
|
+
safePostMessage({
|
|
191
|
+
type: 'console',
|
|
192
|
+
level: 'error',
|
|
193
|
+
message: LOG_PREFIX + 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Listening for messages from the checkout page (payment events, lifecycle events)
|
|
198
|
+
window.addEventListener('message', function(event) {
|
|
199
|
+
console.log(LOG_PREFIX + 'Message received: ' + event.data);
|
|
200
|
+
safePostMessage({
|
|
201
|
+
type: 'message',
|
|
202
|
+
message: event.data
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Logging that injection is complete
|
|
207
|
+
console.log(LOG_PREFIX + 'GlomoPay WebView JavaScript injection complete');
|
|
208
|
+
|
|
209
|
+
true; // Required for injected JavaScript
|
|
210
|
+
})();
|
|
211
|
+
`;
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
|
|
7
|
+
import axios, { isAxiosError } from "axios";
|
|
8
|
+
import { resolveServerConfig, type GlomoServer } from "../config/base";
|
|
9
|
+
|
|
10
|
+
/** The two supported checkout flow types */
|
|
11
|
+
export type OrderType = "standard" | "lrs";
|
|
12
|
+
|
|
13
|
+
/** Discriminated union result - either a resolved order type or an error message */
|
|
14
|
+
export type OrderTypeResult = { success: true; orderType: OrderType } | { success: false; error: string };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Fetches the order type for the given orderId from the public API.
|
|
18
|
+
* Returns a discriminated union so the caller can handle success/failure without try-catch.
|
|
19
|
+
*/
|
|
20
|
+
export async function fetchOrderType(options: {
|
|
21
|
+
orderId: string;
|
|
22
|
+
publicKey: string;
|
|
23
|
+
server?: GlomoServer;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
devMode?: boolean;
|
|
26
|
+
}): Promise<OrderTypeResult> {
|
|
27
|
+
try {
|
|
28
|
+
// Resolving the API base URL from the server config
|
|
29
|
+
const config = resolveServerConfig(options.server);
|
|
30
|
+
const apiUrl = `${config.baseUrl.api}/api/public/v1/order/${options.orderId}`;
|
|
31
|
+
|
|
32
|
+
if (options.devMode) {
|
|
33
|
+
console.log(`[Glomo-RN-SDK] Order type API URL: ${apiUrl}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Calling the order API with the publicKey as Bearer token.
|
|
38
|
+
* Cache-busting headers prevent okhttp (Android) from sending If-None-Match on repeat calls,
|
|
39
|
+
* which would cause the server to return a 304 with an empty body and break order type detection.
|
|
40
|
+
*/
|
|
41
|
+
const response = await axios.get(apiUrl, {
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `Bearer ${options.publicKey}`,
|
|
44
|
+
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
45
|
+
Pragma: "no-cache",
|
|
46
|
+
},
|
|
47
|
+
timeout: options.timeoutMs ?? 30000,
|
|
48
|
+
});
|
|
49
|
+
const data = response.data;
|
|
50
|
+
|
|
51
|
+
// Validating that the returned order type is one of the expected values
|
|
52
|
+
if (data.orderType === "lrs" || data.orderType === "standard") {
|
|
53
|
+
if (options.devMode) {
|
|
54
|
+
console.log(
|
|
55
|
+
`[Glomo-RN-SDK] Order type for orderId: ${options.orderId} successfully determined to be ${data.orderType}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return { success: true, orderType: data.orderType };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (options.devMode) {
|
|
62
|
+
console.log(`[Glomo-RN-SDK] Unexpected orderType ${data.orderType} provided for ${options.orderId}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { success: false, error: `Unexpected order type from ${apiUrl}: ${data.orderType}` };
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Extracting the error message for logging and returning
|
|
68
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
69
|
+
const config = resolveServerConfig(options.server);
|
|
70
|
+
const apiUrl = `${config.baseUrl.api}/api/public/v1/order/${options.orderId}`;
|
|
71
|
+
if (options.devMode) {
|
|
72
|
+
// Logging additional response details for Axios errors (status code, response body)
|
|
73
|
+
if (isAxiosError(error) && error.response) {
|
|
74
|
+
console.log(
|
|
75
|
+
`[Glomo-RN-SDK] orderType determination failed for ${options.orderId} from ${apiUrl}: ${message} (${error.response.status}) and data:`,
|
|
76
|
+
JSON.stringify(error.response.data)
|
|
77
|
+
);
|
|
78
|
+
} else {
|
|
79
|
+
console.log(
|
|
80
|
+
`[Glomo-RN-SDK] orderType determination failed for ${options.orderId} from ${apiUrl}: ${message}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { success: false, error: `Failed to determine order type for ${apiUrl}: ${message}` };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Unified v3 type definitions for GlomoCheckout */
|
|
2
|
+
|
|
3
|
+
import { type GlomoServer } from "../config/base";
|
|
4
|
+
import { type SdkError } from "../utils/analytics";
|
|
5
|
+
|
|
6
|
+
/** The payload for a successful or failed payment (unified across LRS and standard) */
|
|
7
|
+
export interface GlomoCheckoutPayload {
|
|
8
|
+
orderId: string;
|
|
9
|
+
paymentId: string;
|
|
10
|
+
signature: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The payload for a bank transfer submission */
|
|
14
|
+
export interface GlomoBankTransferPayload {
|
|
15
|
+
orderId: string;
|
|
16
|
+
senderAccountNumber: string;
|
|
17
|
+
transactionReference: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The payload for a pay via bank - bank connection successful event */
|
|
21
|
+
export interface GlomoPayViaBankConnectionPayload {
|
|
22
|
+
bankIdentifier: string;
|
|
23
|
+
cooldownPeriodInMinutes: number;
|
|
24
|
+
bankName: string;
|
|
25
|
+
bankImageSrc: string;
|
|
26
|
+
bankImageAlt: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Unified checkout statuses - superset of LRS + standard statuses */
|
|
30
|
+
export type CheckoutStatus =
|
|
31
|
+
| "ready"
|
|
32
|
+
| "detecting_order_type"
|
|
33
|
+
| "payment_in_progress"
|
|
34
|
+
| "payment_successful"
|
|
35
|
+
| "payment_failed"
|
|
36
|
+
| "payment_cancelled"
|
|
37
|
+
| "bank_transfer_submitted"
|
|
38
|
+
| "pay_via_bank_completed";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Ref handle for the unified checkout component.
|
|
42
|
+
* start() is async (returns Promise<boolean>) because the unified flow first detects order type
|
|
43
|
+
* via an API call before delegating to either the LRS or Standard inner component.
|
|
44
|
+
*/
|
|
45
|
+
export interface GlomoCheckoutRef {
|
|
46
|
+
start: () => Promise<boolean>;
|
|
47
|
+
getStatus: () => CheckoutStatus;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Shared callback and configuration props for the unified checkout component */
|
|
51
|
+
interface GlomoCheckoutBaseProps {
|
|
52
|
+
server?: GlomoServer;
|
|
53
|
+
publicKey: string;
|
|
54
|
+
onPaymentSuccess: (payload: GlomoCheckoutPayload) => void;
|
|
55
|
+
onPaymentFailure: (payload: GlomoCheckoutPayload) => void;
|
|
56
|
+
onConnectionError?: (error: unknown) => void;
|
|
57
|
+
onPaymentTerminate?: () => void;
|
|
58
|
+
onSdkError?: (error: Array<SdkError>) => void;
|
|
59
|
+
onBankTransferSubmitted?: (payload: GlomoBankTransferPayload | null | undefined) => void;
|
|
60
|
+
onPayViaBankCompleted?: (payload: { status: string }) => void;
|
|
61
|
+
onPayViaBankBankConnectionSuccessful?: (payload: GlomoPayViaBankConnectionPayload | null | undefined) => void;
|
|
62
|
+
onUserRefusedCameraPermissions?: () => void;
|
|
63
|
+
devMode?: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Props for the unified checkout component.
|
|
68
|
+
* Exactly one of orderId or subscriptionId must be provided.
|
|
69
|
+
* TypeScript enforces this at compile time; a runtime guard in useGlomoCheckout catches JS consumers.
|
|
70
|
+
*/
|
|
71
|
+
export type GlomoCheckoutProps = GlomoCheckoutBaseProps &
|
|
72
|
+
({ orderId: string; subscriptionId?: never } | { subscriptionId: string; orderId?: never });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Type definitions for the Standard Checkout flow */
|
|
2
|
+
|
|
3
|
+
import { type GlomoServer } from "../config/base";
|
|
4
|
+
import { type SdkError } from "../utils/analytics";
|
|
5
|
+
import { type GlomoBankTransferPayload, type GlomoPayViaBankConnectionPayload } from "./checkout";
|
|
6
|
+
|
|
7
|
+
/** Standard checkout statuses */
|
|
8
|
+
export type StandardCheckoutStatus =
|
|
9
|
+
| "ready"
|
|
10
|
+
| "payment_in_progress"
|
|
11
|
+
| "payment_successful"
|
|
12
|
+
| "payment_failed"
|
|
13
|
+
| "payment_cancelled"
|
|
14
|
+
| "bank_transfer_submitted"
|
|
15
|
+
| "pay_via_bank_completed";
|
|
16
|
+
|
|
17
|
+
/** The payload for a successful or failed standard payment */
|
|
18
|
+
export interface GlomoStandardCheckoutPayload {
|
|
19
|
+
orderId: string;
|
|
20
|
+
paymentId: string;
|
|
21
|
+
signature: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Ref handle for the standard checkout component.
|
|
26
|
+
* start() is synchronous (returns boolean) because the standard flow does not need to detect
|
|
27
|
+
* order type - unlike the unified GlomoCheckoutRef whose start() is async (returns Promise<boolean>).
|
|
28
|
+
*/
|
|
29
|
+
export interface GlomoStandardCheckoutRef {
|
|
30
|
+
start: () => boolean;
|
|
31
|
+
getStatus: () => StandardCheckoutStatus;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Props for the standard checkout component */
|
|
35
|
+
export interface GlomoStandardCheckoutProps {
|
|
36
|
+
server?: GlomoServer;
|
|
37
|
+
publicKey: string;
|
|
38
|
+
orderId: string;
|
|
39
|
+
onPaymentSuccess: (payload: GlomoStandardCheckoutPayload) => void;
|
|
40
|
+
onPaymentFailure: (payload: GlomoStandardCheckoutPayload) => void;
|
|
41
|
+
onConnectionError?: (error: unknown) => void;
|
|
42
|
+
onPaymentTerminate?: () => void;
|
|
43
|
+
onSdkError?: (error: Array<SdkError>) => void;
|
|
44
|
+
onBankTransferSubmitted?: (payload: GlomoBankTransferPayload | null | undefined) => void;
|
|
45
|
+
onPayViaBankCompleted?: (payload: { status: string }) => void;
|
|
46
|
+
onPayViaBankBankConnectionSuccessful?: (payload: GlomoPayViaBankConnectionPayload | null | undefined) => void;
|
|
47
|
+
onUserRefusedCameraPermissions?: () => void;
|
|
48
|
+
devMode?: boolean;
|
|
49
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Type definitions for the Subscriptions Checkout flow */
|
|
2
|
+
|
|
3
|
+
import { type GlomoServer } from "../config/base";
|
|
4
|
+
import { type SdkError } from "../utils/analytics";
|
|
5
|
+
import { type GlomoCheckoutPayload, type GlomoPayViaBankConnectionPayload } from "./checkout";
|
|
6
|
+
import { type StandardCheckoutStatus } from "./standard-checkout";
|
|
7
|
+
|
|
8
|
+
/** Props for the subscriptions checkout component */
|
|
9
|
+
export interface GlomoSubscriptionsCheckoutProps {
|
|
10
|
+
server?: GlomoServer;
|
|
11
|
+
publicKey: string;
|
|
12
|
+
subscriptionId: string;
|
|
13
|
+
onPaymentSuccess: (payload: GlomoCheckoutPayload) => void;
|
|
14
|
+
onPaymentFailure: (payload: GlomoCheckoutPayload) => void;
|
|
15
|
+
onConnectionError?: (error: unknown) => void;
|
|
16
|
+
onPaymentTerminate?: () => void;
|
|
17
|
+
onSdkError?: (error: Array<SdkError>) => void;
|
|
18
|
+
onPayViaBankBankConnectionSuccessful?: (payload: GlomoPayViaBankConnectionPayload | null | undefined) => void;
|
|
19
|
+
onUserRefusedCameraPermissions?: () => void;
|
|
20
|
+
devMode?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Ref handle for the subscriptions checkout component.
|
|
25
|
+
* Same type as GlomoStandardCheckoutRef - start() is async at the unified level
|
|
26
|
+
* but delegates to the synchronous standard checkout start() internally.
|
|
27
|
+
*/
|
|
28
|
+
export interface GlomoSubscriptionsCheckoutRef {
|
|
29
|
+
start: () => boolean;
|
|
30
|
+
getStatus: () => StandardCheckoutStatus;
|
|
31
|
+
}
|