nimbbl-mobile-react-native-sdk 1.2.0 → 1.3.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/README.md +128 -167
- package/android/build.gradle +4 -4
- package/android/src/main/AndroidManifest.xml +0 -4
- package/android/src/main/java/com/nimbbl/reactnative/NimbblCheckoutActivity.kt +49 -54
- package/android/src/main/java/com/nimbbl/reactnative/NimbblReactNativeSDKModule.kt +257 -55
- package/ios/NimbblReactNativeSDK.swift +11 -33
- package/lib/NimbblSDK.d.ts +3 -31
- package/lib/NimbblSDK.js +23 -101
- package/lib/constants.d.ts +3 -13
- package/lib/constants.js +4 -16
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -3
- package/lib/types.d.ts +26 -10
- package/lib/types.js +1 -1
- package/nimbbl-mobile-react-native-sdk.podspec +1 -1
- package/package.json +7 -2
package/lib/NimbblSDK.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* @fileoverview Main Nimbbl SDK for React Native
|
|
4
|
-
* @version 1.
|
|
4
|
+
* @version 1.3.0
|
|
5
5
|
* @author Nimbbl Tech
|
|
6
6
|
*
|
|
7
7
|
* This is a wrapper around the native Android and iOS SDKs
|
|
@@ -18,13 +18,11 @@ const { NimbblReactNativeSDK } = react_native_1.NativeModules;
|
|
|
18
18
|
*/
|
|
19
19
|
class NimbblSDK {
|
|
20
20
|
constructor() {
|
|
21
|
-
this.eventListeners = new Map();
|
|
22
21
|
if (!NimbblReactNativeSDK) {
|
|
23
22
|
throw new Error('NimbblReactNativeSDK native module is not available. Make sure you have properly linked the library.');
|
|
24
23
|
}
|
|
25
24
|
this.config = null;
|
|
26
25
|
this.isInitialized = false;
|
|
27
|
-
this.eventEmitter = new react_native_1.NativeEventEmitter(NimbblReactNativeSDK);
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
28
|
* Get shared instance (matching iOS pattern)
|
|
@@ -41,35 +39,19 @@ class NimbblSDK {
|
|
|
41
39
|
* @returns Promise resolving to initialization result
|
|
42
40
|
*/
|
|
43
41
|
async initialize(config) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
enable_logging: constants_1.DEFAULT_CONFIG.enable_logging,
|
|
58
|
-
enable_analytics: constants_1.DEFAULT_CONFIG.enable_analytics,
|
|
59
|
-
api_base_url: constants_1.DEFAULT_CONFIG.api_base_url,
|
|
60
|
-
...(finalConfig && 'options' in finalConfig ? finalConfig.options : {}),
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
// Initialize native module
|
|
64
|
-
const result = await NimbblReactNativeSDK.initialize(this.config);
|
|
65
|
-
if (result.success) {
|
|
66
|
-
this.isInitialized = true;
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
42
|
+
// Use default configuration if no config provided
|
|
43
|
+
const finalConfig = config || constants_1.DEFAULT_CONFIG;
|
|
44
|
+
// Merge with default configuration
|
|
45
|
+
this.config = {
|
|
46
|
+
...constants_1.DEFAULT_CONFIG,
|
|
47
|
+
...finalConfig,
|
|
48
|
+
};
|
|
49
|
+
// Initialize native module
|
|
50
|
+
const result = await NimbblReactNativeSDK.initialize(this.config);
|
|
51
|
+
if (result.success) {
|
|
52
|
+
this.isInitialized = true;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
73
55
|
}
|
|
74
56
|
/**
|
|
75
57
|
* Create shop order (matching iOS SDK pattern)
|
|
@@ -123,40 +105,23 @@ class NimbblSDK {
|
|
|
123
105
|
wallet_code: options.walletCode || '',
|
|
124
106
|
payment_flow: options.paymentFlow || '',
|
|
125
107
|
};
|
|
126
|
-
// Use
|
|
108
|
+
// Use callback-based approach - SDK will always return a response
|
|
127
109
|
return new Promise((resolve) => {
|
|
128
|
-
// Set up a timeout to handle cases where the callback never comes
|
|
129
|
-
const timeout = setTimeout(() => {
|
|
130
|
-
resolve({
|
|
131
|
-
success: false,
|
|
132
|
-
message: 'Payment timeout - no response received',
|
|
133
|
-
});
|
|
134
|
-
}, 300000); // 5 minutes timeout
|
|
135
110
|
// Store the resolve function for the native module to call
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (status === 'success' || status === 'completed') {
|
|
141
|
-
resolve({ success: true, message: 'Payment completed successfully', data: result });
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
resolve({
|
|
145
|
-
success: false,
|
|
146
|
-
message: (result === null || result === void 0 ? void 0 : result.message) || 'Payment failed',
|
|
147
|
-
data: result,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
111
|
+
const nativeModule = NimbblReactNativeSDK;
|
|
112
|
+
nativeModule.setCheckoutCallback((result) => {
|
|
113
|
+
// Return the raw JSON response from native SDK directly
|
|
114
|
+
resolve(result);
|
|
150
115
|
});
|
|
151
116
|
// Start the checkout process
|
|
152
|
-
|
|
117
|
+
nativeModule
|
|
118
|
+
.checkout(checkoutPayload)
|
|
153
119
|
.then(() => {
|
|
154
120
|
// Native checkout initiated successfully
|
|
155
121
|
})
|
|
156
122
|
.catch((error) => {
|
|
157
|
-
clearTimeout(timeout);
|
|
158
123
|
resolve({
|
|
159
|
-
|
|
124
|
+
status: 'error',
|
|
160
125
|
message: error.message || 'Failed to initiate native checkout',
|
|
161
126
|
});
|
|
162
127
|
});
|
|
@@ -164,54 +129,11 @@ class NimbblSDK {
|
|
|
164
129
|
}
|
|
165
130
|
catch (error) {
|
|
166
131
|
return {
|
|
167
|
-
|
|
132
|
+
status: 'error',
|
|
168
133
|
message: error instanceof Error ? error.message : 'Checkout failed',
|
|
169
134
|
};
|
|
170
135
|
}
|
|
171
136
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Add unified checkout response listener (recommended approach)
|
|
174
|
-
* This method handles both success and failure cases in a single callback
|
|
175
|
-
* @param listener - Callback function that receives checkout response data
|
|
176
|
-
*/
|
|
177
|
-
addCheckoutResponseListener(listener) {
|
|
178
|
-
if (!this.eventListeners.has('checkout_response')) {
|
|
179
|
-
this.eventListeners.set('checkout_response', []);
|
|
180
|
-
}
|
|
181
|
-
this.eventListeners.get('checkout_response').push(listener);
|
|
182
|
-
if (this.eventEmitter) {
|
|
183
|
-
this.eventEmitter.addListener('checkout_response', listener);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Remove unified checkout response listener
|
|
188
|
-
* @param listener - Callback function to remove
|
|
189
|
-
*/
|
|
190
|
-
removeCheckoutResponseListener(listener) {
|
|
191
|
-
const listeners = this.eventListeners.get('checkout_response');
|
|
192
|
-
if (listeners) {
|
|
193
|
-
const index = listeners.indexOf(listener);
|
|
194
|
-
if (index > -1) {
|
|
195
|
-
listeners.splice(index, 1);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (this.eventEmitter) {
|
|
199
|
-
this.eventEmitter.removeAllListeners('checkout_response');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Validate SDK configuration
|
|
204
|
-
* @param config - Configuration to validate
|
|
205
|
-
*/
|
|
206
|
-
validateConfig(config) {
|
|
207
|
-
if (!config) {
|
|
208
|
-
throw new Error(constants_1.ERROR_MESSAGES[constants_1.ERROR_CODES.INVALID_CONFIG]);
|
|
209
|
-
}
|
|
210
|
-
if (!config.environment ||
|
|
211
|
-
!Object.values(constants_1.ENVIRONMENTS).includes(config.environment)) {
|
|
212
|
-
throw new Error('Invalid environment specified');
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
137
|
}
|
|
216
138
|
NimbblSDK.shared = null;
|
|
217
139
|
exports.default = NimbblSDK;
|
package/lib/constants.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Constants for Nimbbl React Native SDK
|
|
3
|
-
* @version 1.
|
|
3
|
+
* @version 1.3.0
|
|
4
4
|
* @author Nimbbl Tech
|
|
5
5
|
*/
|
|
6
|
-
export declare const ENVIRONMENTS: {
|
|
7
|
-
readonly SANDBOX: "sandbox";
|
|
8
|
-
readonly PRODUCTION: "production";
|
|
9
|
-
};
|
|
10
6
|
export declare const ERROR_CODES: {
|
|
11
7
|
readonly SDK_NOT_INITIALIZED: "SDK_NOT_INITIALIZED";
|
|
12
8
|
readonly INVALID_CONFIG: "INVALID_CONFIG";
|
|
@@ -15,14 +11,8 @@ export declare const ERROR_MESSAGES: {
|
|
|
15
11
|
readonly SDK_NOT_INITIALIZED: "SDK is not initialized. Call initialize() first.";
|
|
16
12
|
readonly INVALID_CONFIG: "Invalid SDK configuration provided.";
|
|
17
13
|
};
|
|
18
|
-
export declare const EVENTS: {
|
|
19
|
-
readonly CHECKOUT_RESPONSE: "checkout_response";
|
|
20
|
-
};
|
|
21
14
|
export declare const DEFAULT_CONFIG: {
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
24
|
-
readonly enable_logging: false;
|
|
25
|
-
readonly enable_analytics: true;
|
|
26
|
-
readonly api_base_url: "https://api.nimbbl.tech";
|
|
15
|
+
readonly api_base_url: "https://api.nimbbl.tech/";
|
|
16
|
+
readonly app_code: "reactnative_webview_sdk";
|
|
27
17
|
};
|
|
28
18
|
//# sourceMappingURL=constants.d.ts.map
|
package/lib/constants.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* @fileoverview Constants for Nimbbl React Native SDK
|
|
4
|
-
* @version 1.
|
|
4
|
+
* @version 1.3.0
|
|
5
5
|
* @author Nimbbl Tech
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.DEFAULT_CONFIG = exports.
|
|
9
|
-
// MARK: - SDK Environments
|
|
10
|
-
exports.ENVIRONMENTS = {
|
|
11
|
-
SANDBOX: 'sandbox',
|
|
12
|
-
PRODUCTION: 'production',
|
|
13
|
-
};
|
|
8
|
+
exports.DEFAULT_CONFIG = exports.ERROR_MESSAGES = exports.ERROR_CODES = void 0;
|
|
14
9
|
// MARK: - Error Codes
|
|
15
10
|
exports.ERROR_CODES = {
|
|
16
11
|
SDK_NOT_INITIALIZED: 'SDK_NOT_INITIALIZED',
|
|
@@ -21,16 +16,9 @@ exports.ERROR_MESSAGES = {
|
|
|
21
16
|
[exports.ERROR_CODES.SDK_NOT_INITIALIZED]: 'SDK is not initialized. Call initialize() first.',
|
|
22
17
|
[exports.ERROR_CODES.INVALID_CONFIG]: 'Invalid SDK configuration provided.',
|
|
23
18
|
};
|
|
24
|
-
// MARK: - Events
|
|
25
|
-
exports.EVENTS = {
|
|
26
|
-
CHECKOUT_RESPONSE: 'checkout_response',
|
|
27
|
-
};
|
|
28
19
|
// MARK: - Default Configuration
|
|
29
20
|
exports.DEFAULT_CONFIG = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
enable_logging: false,
|
|
33
|
-
enable_analytics: true,
|
|
34
|
-
api_base_url: 'https://api.nimbbl.tech',
|
|
21
|
+
api_base_url: 'https://api.nimbbl.tech/',
|
|
22
|
+
app_code: 'reactnative_webview_sdk',
|
|
35
23
|
};
|
|
36
24
|
//# sourceMappingURL=constants.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export { default as NimbblSDK } from './NimbblSDK';
|
|
10
10
|
export { nimbblSDK } from './NimbblSDK';
|
|
11
|
-
export type { SDKConfig, } from './types';
|
|
12
|
-
export {
|
|
11
|
+
export type { SDKConfig, CheckoutOptions, NimbblReactNativeSDKInterface, } from './types';
|
|
12
|
+
export { ERROR_CODES, ERROR_MESSAGES, DEFAULT_CONFIG } from './constants';
|
|
13
13
|
export { default } from './NimbblSDK';
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.default = exports.
|
|
14
|
+
exports.default = exports.DEFAULT_CONFIG = exports.ERROR_MESSAGES = exports.ERROR_CODES = exports.nimbblSDK = exports.NimbblSDK = void 0;
|
|
15
15
|
// Main SDK class
|
|
16
16
|
var NimbblSDK_1 = require("./NimbblSDK");
|
|
17
17
|
Object.defineProperty(exports, "NimbblSDK", { enumerable: true, get: function () { return __importDefault(NimbblSDK_1).default; } });
|
|
@@ -20,11 +20,9 @@ var NimbblSDK_2 = require("./NimbblSDK");
|
|
|
20
20
|
Object.defineProperty(exports, "nimbblSDK", { enumerable: true, get: function () { return NimbblSDK_2.nimbblSDK; } });
|
|
21
21
|
// Constants
|
|
22
22
|
var constants_1 = require("./constants");
|
|
23
|
-
Object.defineProperty(exports, "ENVIRONMENTS", { enumerable: true, get: function () { return constants_1.ENVIRONMENTS; } });
|
|
24
23
|
Object.defineProperty(exports, "ERROR_CODES", { enumerable: true, get: function () { return constants_1.ERROR_CODES; } });
|
|
25
24
|
Object.defineProperty(exports, "ERROR_MESSAGES", { enumerable: true, get: function () { return constants_1.ERROR_MESSAGES; } });
|
|
26
25
|
Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_CONFIG; } });
|
|
27
|
-
Object.defineProperty(exports, "EVENTS", { enumerable: true, get: function () { return constants_1.EVENTS; } });
|
|
28
26
|
// Default export
|
|
29
27
|
var NimbblSDK_3 = require("./NimbblSDK");
|
|
30
28
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(NimbblSDK_3).default; } });
|
package/lib/types.d.ts
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Type definitions for Nimbbl React Native SDK
|
|
3
|
-
* @version 1.
|
|
3
|
+
* @version 1.3.0
|
|
4
4
|
* @author Nimbbl Tech
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* SDK Configuration object
|
|
8
8
|
*/
|
|
9
9
|
export interface SDKConfig {
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
/** API base URL for the SDK */
|
|
11
|
+
api_base_url?: string;
|
|
12
|
+
/** Application code for the SDK */
|
|
13
|
+
app_code?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Native module interface
|
|
17
|
+
*/
|
|
18
|
+
export interface NimbblReactNativeSDKInterface {
|
|
19
|
+
initialize(config: any): Promise<any>;
|
|
20
|
+
createShopOrder(options: any): Promise<any>;
|
|
21
|
+
checkout(options: any): Promise<any>;
|
|
22
|
+
setCheckoutCallback(callback: (result: any) => void): void;
|
|
23
|
+
addListener(eventName: string): void;
|
|
24
|
+
removeListeners(count: number): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checkout options
|
|
28
|
+
*/
|
|
29
|
+
export interface CheckoutOptions {
|
|
30
|
+
orderToken: string;
|
|
31
|
+
paymentModeCode?: string;
|
|
32
|
+
bankCode?: string;
|
|
33
|
+
walletCode?: string;
|
|
34
|
+
paymentFlow?: string;
|
|
19
35
|
}
|
|
20
36
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nimbbl-mobile-react-native-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Nimbbl React Native SDK for payment integration",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -71,7 +71,12 @@
|
|
|
71
71
|
"react": "18.2.0",
|
|
72
72
|
"react-native": "0.76.0",
|
|
73
73
|
"ts-jest": "^29.1.0",
|
|
74
|
-
"typescript": "^5.0.0"
|
|
74
|
+
"typescript": "^5.0.0",
|
|
75
|
+
"@react-navigation/native": "^7.1.18",
|
|
76
|
+
"@react-navigation/stack": "^7.4.9",
|
|
77
|
+
"react-native-gesture-handler": "^2.28.0",
|
|
78
|
+
"react-native-safe-area-context": "^5.6.1",
|
|
79
|
+
"react-native-screens": "^4.16.0"
|
|
75
80
|
},
|
|
76
81
|
"dependencies": {},
|
|
77
82
|
"files": [
|