@primer-io/react-native 0.12.4 → 0.15.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.
Files changed (55) hide show
  1. package/android/build.gradle +2 -2
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/java/com/primerioreactnative/PrimerRN.kt +191 -152
  4. package/android/src/main/java/com/primerioreactnative/PrimerRNEventListener.kt +131 -86
  5. package/android/src/main/java/com/primerioreactnative/datamodels/PrimerErrorRN.kt +3 -2
  6. package/android/src/main/java/com/primerioreactnative/datamodels/PrimerEventsRN.kt +11 -0
  7. package/android/src/main/java/com/primerioreactnative/utils/ErrorHelper.kt +11 -0
  8. package/android/src/main/java/com/primerioreactnative/utils/PrimerImplementedRNCallbacks.kt +14 -0
  9. package/ios/DataModels/PrimerErrorRN.swift +32 -2
  10. package/ios/RNTPrimer.m +43 -0
  11. package/ios/RNTPrimer.swift +394 -0
  12. package/ios/ReactNative-Bridging-Header.h +1 -9
  13. package/ios/ReactNative.xcodeproj/project.pbxproj +44 -0
  14. package/lib/commonjs/Primer.js +221 -209
  15. package/lib/commonjs/Primer.js.map +1 -1
  16. package/lib/commonjs/RNPrimer.js +145 -0
  17. package/lib/commonjs/RNPrimer.js.map +1 -0
  18. package/lib/commonjs/index.js +1 -0
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/models/primer-intent.js.map +1 -1
  21. package/lib/commonjs/models/utils/redirectScheme.js +4 -0
  22. package/lib/commonjs/models/utils/redirectScheme.js.map +1 -0
  23. package/lib/module/Primer.js +203 -209
  24. package/lib/module/Primer.js.map +1 -1
  25. package/lib/module/RNPrimer.js +136 -0
  26. package/lib/module/RNPrimer.js.map +1 -0
  27. package/lib/module/index.js +2 -1
  28. package/lib/module/index.js.map +1 -1
  29. package/lib/module/models/primer-intent.js.map +1 -1
  30. package/lib/module/models/utils/redirectScheme.js +2 -0
  31. package/lib/module/models/utils/redirectScheme.js.map +1 -0
  32. package/lib/typescript/Primer.d.ts +13 -0
  33. package/lib/typescript/RNPrimer.d.ts +24 -0
  34. package/lib/typescript/models/primer-callbacks.d.ts +7 -9
  35. package/lib/typescript/models/primer-config.d.ts +16 -13
  36. package/lib/typescript/models/primer-intent.d.ts +1 -1
  37. package/lib/typescript/models/primer-request.d.ts +2 -12
  38. package/lib/typescript/models/primer-settings.d.ts +3 -5
  39. package/lib/typescript/models/primer.d.ts +4 -4
  40. package/lib/typescript/models/utils/redirectScheme.d.ts +3 -0
  41. package/package.json +4 -1
  42. package/primer-io-react-native.podspec +2 -3
  43. package/src/Primer.ts +227 -176
  44. package/src/RNPrimer.ts +170 -0
  45. package/src/index.tsx +1 -0
  46. package/src/models/primer-callbacks.ts +9 -27
  47. package/src/models/primer-config.ts +23 -20
  48. package/src/models/primer-intent.ts +1 -1
  49. package/src/models/primer-request.ts +2 -16
  50. package/src/models/primer-settings.ts +3 -5
  51. package/src/models/primer.ts +5 -5
  52. package/src/models/utils/redirectScheme.ts +5 -0
  53. package/ios/PrimerRN+PrimerDelegate.swift +0 -147
  54. package/ios/PrimerRN.swift +0 -166
  55. package/ios/ReactNative.m +0 -34
package/src/Primer.ts CHANGED
@@ -1,201 +1,252 @@
1
- import { NativeModules } from 'react-native';
2
- import type { ClientSessionActionsRequest } from './models/client-session-actions-request';
3
1
  import type { PaymentInstrumentToken } from './models/payment-instrument-token';
4
2
  import type { IPrimer } from './models/primer';
5
- import type {
6
- OnClientSessionActionsCallback,
7
- OnDismissCallback,
8
- OnPrimerErrorCallback,
9
- OnTokenAddedToVaultCallback,
10
- OnTokenizeSuccessCallback,
11
- } from './models/primer-callbacks';
12
- import type { PrimerConfig } from './models/primer-config';
13
- import type { PrimerError } from './models/primer-error';
14
- import type {
15
- PrimerIntent,
16
- PrimerPaymentMethodIntent,
17
- } from './models/primer-intent';
18
- import type { PrimerSettings } from './models/primer-settings';
19
- import type { PrimerTheme } from './models/primer-theme';
20
- import { parseCallback } from './utils';
21
-
22
- const { PrimerRN: NativeModule } = NativeModules;
3
+ import type { IPrimerConfig } from './models/primer-config';
4
+ import type { PrimerPaymentMethodIntent } from './models/primer-intent';
5
+ import type { PrimerResumeHandler } from './models/primer-request';
6
+ import RNPrimer, { IPrimerError } from './RNPrimer';
23
7
 
24
- export const PrimerNativeMapping: IPrimer = {
25
- showUniversalCheckout(token: String, config: PrimerConfig): void {
26
- configureIntent({ vault: false, paymentMethod: 'Any' });
27
- configure(config);
28
- NativeModule.initialize(token);
29
- },
30
-
31
- showVaultManager(token: String, config: PrimerConfig): void {
32
- configureIntent({ vault: true, paymentMethod: 'Any' });
33
- configure(config);
34
- NativeModule.initialize(token);
35
- },
36
-
37
- showPaymentMethod(
38
- token: String,
39
- intent: PrimerPaymentMethodIntent,
40
- config: PrimerConfig
41
- ): void {
42
- configureIntent(intent);
43
- configure(config);
44
- NativeModule.initialize(token);
8
+ const resumeHandler: PrimerResumeHandler = {
9
+ handleNewClientToken: async (clientToken) => {
10
+ try {
11
+ await RNPrimer.handleNewClientToken(clientToken);
12
+ } catch (err) {
13
+ let primerError: IPrimerError;
14
+ if (err instanceof Error) {
15
+ primerError = {
16
+ errorId: "react-native-bridge",
17
+ errorDescription: err.message
18
+ }
19
+ } else {
20
+ primerError = {
21
+ errorId: "react-native-bridge",
22
+ errorDescription: "unknown error"
23
+ }
24
+ }
25
+ await RNPrimer.handleError(primerError);
26
+ }
45
27
  },
46
-
47
- // todo: refactor
48
- // fetchSavedPaymentInstruments(token: String, config: PrimerConfig): void {
49
- // configure(config);
50
- // NativeModule.fetchSavedPaymentInstruments(token);
51
- // },
52
-
53
- dispose(): void {
54
- NativeModule.dispose();
28
+ handleError: async (err) => {
29
+ try {
30
+ const primerError: IPrimerError = {
31
+ errorId: "react-native",
32
+ errorDescription: err.message
33
+ }
34
+ await RNPrimer.handleError(primerError);
35
+ } catch (err) {
36
+ let primerError: IPrimerError;
37
+ if (err instanceof Error) {
38
+ primerError = {
39
+ errorId: "react-native-bridge",
40
+ errorDescription: err.message
41
+ }
42
+ } else {
43
+ primerError = {
44
+ errorId: "react-native-bridge",
45
+ errorDescription: "unknown error"
46
+ }
47
+ }
48
+ await RNPrimer.handleError(primerError);
49
+ }
55
50
  },
56
- };
57
-
58
- function configure(config: PrimerConfig): void {
59
- configureTheme(config.theme);
60
- configureSettings(config.settings);
61
- configureOnVaultSuccess(config.onTokenAddedToVault);
62
- configureOnDismiss(config.onDismiss);
63
- configureOnError(config.onError);
64
- configureOnTokenizeSuccess(config.onTokenizeSuccess);
65
- configureOnClientSessionActions(config.onClientSessionActions);
66
- configureOnResumeSuccess(config.onResumeSuccess);
51
+ handleSuccess: async () => {
52
+ try {
53
+ await RNPrimer.handleSuccess();
54
+ } catch (err) {
55
+ let primerError: IPrimerError;
56
+ if (err instanceof Error) {
57
+ primerError = {
58
+ errorId: "react-native-bridge",
59
+ errorDescription: err.message
60
+ }
61
+ } else {
62
+ primerError = {
63
+ errorId: "react-native-bridge",
64
+ errorDescription: "unknown error"
65
+ }
66
+ }
67
+ await RNPrimer.handleError(primerError);
68
+ }
69
+ }
67
70
  }
68
71
 
69
- function configureSettings(settings: PrimerSettings = {}): void {
70
- const data = JSON.stringify(settings);
71
- NativeModule.configureSettings(data);
72
+ export interface IClientSessionAction {
73
+ type:
74
+ | 'SELECT_PAYMENT_METHOD'
75
+ | 'UNSELECT_PAYMENT_METHOD'
76
+ | 'SET_BILLING_ADDRESS';
77
+ params?: IActionParams;
72
78
  }
73
79
 
74
- function configureTheme(theme: PrimerTheme = {}): void {
75
- const data = JSON.stringify(theme);
76
- NativeModule.configureTheme(data);
80
+ interface IActionParams {
81
+ billingAddress: Record<string, string | null>;
82
+ paymentMethodType?: string;
83
+ binData?: IBinData;
77
84
  }
78
85
 
79
- function configureIntent(
80
- intent: PrimerIntent = { vault: false, paymentMethod: 'Any' }
81
- ): void {
82
- const data = JSON.stringify(intent);
83
- NativeModule.configureIntent(data);
86
+ interface IBinData {
87
+ network: string;
84
88
  }
85
89
 
86
- function resume(request: ResumeRequest) {
87
- const data = JSON.stringify(request);
88
- NativeModule.resume(data);
89
- }
90
+ export const PrimerNativeMapping: IPrimer = {
90
91
 
91
- function configureOnTokenizeSuccess(
92
- callback: OnTokenizeSuccessCallback = (_, __) => {}
93
- ) {
94
- NativeModule.configureOnTokenizeSuccess((data: any) => {
95
- try {
96
- const parsedData = JSON.parse(data) as PaymentInstrumentToken;
97
- callback(parsedData, {
98
- handleError: (error) => resume({ error, token: null }),
99
- handleSuccess: () => resume({ error: null, token: null }),
100
- handleNewClientToken: (token) => resume({ error: null, token }),
101
- // deprecated
102
- resumeWithError: (error) => resume({ error, token: null }),
103
- resumeWithSuccess: (token) => resume({ error: null, token }),
104
- });
105
- } catch (e) {
106
- console.log('failed to parse json', e);
92
+ showUniversalCheckout(clientToken: string, config: IPrimerConfig): void {
93
+ RNPrimer.removeAllListeners();
94
+
95
+ if (config.settings || config.theme) {
96
+ RNPrimer.configure(config.settings || null, config.theme || null);
97
+
98
+ let implementedRNCallbacks: any = {
99
+ // isClientTokenCallbackImplemented: (config.onClientTokenCallback !== undefined),
100
+ isTokenAddedToVaultImplemented: (config.onTokenAddedToVault !== undefined),
101
+ isOnResumeSuccessImplemented: (config.onResumeSuccess !== undefined),
102
+ isOnResumeErrorImplemented: (config.onError !== undefined),
103
+ isOnCheckoutDismissedImplemented: (config.onDismiss !== undefined),
104
+ isCheckoutFailedImplemented: (config.onError !== undefined),
105
+ isClientSessionActionsImplemented: (config.onClientSessionActions !== undefined)
106
+ };
107
+
108
+ RNPrimer.setImplementedRNCallbacks(implementedRNCallbacks)
109
+ .then(() => {
110
+ RNPrimer.addListener('onClientSessionActions', data => {
111
+ const clientSessionActions: IClientSessionAction[] = data;
112
+ if (config.onClientSessionActions) {
113
+ config.onClientSessionActions(clientSessionActions, resumeHandler);
114
+ }
115
+ });
116
+
117
+ RNPrimer.addListener('onTokenizeSuccessCallback', data => {
118
+ const paymentInstrumentToken: PaymentInstrumentToken = data;
119
+ if (config.onTokenizeSuccess) {
120
+ config.onTokenizeSuccess(paymentInstrumentToken, resumeHandler);
121
+ }
122
+ });
123
+
124
+ RNPrimer.addListener('onResumeSuccess', data => {
125
+ const resumeToken: string = data.resumeToken;
126
+ if (config.onResumeSuccess) {
127
+ config.onResumeSuccess(resumeToken, resumeHandler);
128
+ }
129
+ });
130
+
131
+ RNPrimer.addListener('onCheckoutDismissed', _ => {
132
+ if (config.onDismiss) {
133
+ config.onDismiss();
134
+ }
135
+ });
136
+
137
+ RNPrimer.addListener('onError', data => {
138
+ const err: IPrimerError = data.error;
139
+ if (config.onError) {
140
+ config.onError(err, resumeHandler);
141
+ }
142
+ });
143
+
144
+ RNPrimer.showUniversalCheckout(clientToken);
145
+ })
146
+ .catch( err => {
147
+ console.error(err);
148
+ })
149
+ }
150
+
151
+ // RNPrimer.addListener('onClientTokenCallback', _ => {
152
+ // if (config.onClientTokenCallback) {
153
+ // config.onClientTokenCallback(resumeHandler);
154
+ // }
155
+ // });
156
+ },
157
+
158
+ showVaultManager(clientToken: string, config: IPrimerConfig): void {
159
+ RNPrimer.removeAllListeners();
160
+
161
+ if (config.settings || config.theme) {
162
+ RNPrimer.configure(config.settings || null, config.theme || null);
163
+
164
+ let implementedRNCallbacks: any = {
165
+ // isClientTokenCallbackImplemented: (config.onClientTokenCallback !== undefined),
166
+ isTokenAddedToVaultImplemented: (config.onTokenAddedToVault !== undefined),
167
+ isOnResumeSuccessImplemented: (config.onResumeSuccess !== undefined),
168
+ isOnResumeErrorImplemented: (config.onError !== undefined),
169
+ isOnCheckoutDismissedImplemented: (config.onDismiss !== undefined),
170
+ isCheckoutFailedImplemented: (config.onError !== undefined),
171
+ isClientSessionActionsImplemented: (config.onClientSessionActions !== undefined)
172
+ };
173
+
174
+ RNPrimer.setImplementedRNCallbacks(implementedRNCallbacks);
107
175
  }
108
- });
109
- }
110
176
 
111
- function actionResume(request: ResumeRequest) {
112
- const data = JSON.stringify(request);
113
- NativeModule.actionResume(data);
114
- }
177
+ // RNPrimer.addListener('onClientTokenCallback', _ => {
178
+ // if (config.onClientTokenCallback) {
179
+ // config.onClientTokenCallback(resumeHandler);
180
+ // }
181
+ // });
115
182
 
116
- /**
117
- * Call @method configureOnClientSessionActions on the native bridge, passing
118
- * in a callback that the native side will call every time a client session
119
- * action is triggered.
120
- */
121
- function configureOnClientSessionActions(
122
- callback?: OnClientSessionActionsCallback // defined by integrating developer.
123
- ) {
124
- NativeModule.configureOnClientSessionActions((data: any) => {
125
- try {
126
- // parse the client session action JSON string.
127
- const parsedData = JSON.parse(data) as ClientSessionActionsRequest;
128
-
129
- if (!callback) {
130
- /**
131
- * if @param callback is undefined immediately call the native bridge
132
- * and resume with null values. This will resume the SDK flow without
133
- * triggering extra configuration API fetch calls.
134
- */
135
- actionResume({ error: null, token: null });
183
+ RNPrimer.addListener('onClientSessionActions', data => {
184
+ const clientSessionActions: IClientSessionAction[] = data;
185
+ if (config.onClientSessionActions) {
186
+ config.onClientSessionActions(clientSessionActions, resumeHandler);
136
187
  } else {
137
- /**
138
- * send the parsed data back to the developer through the defined callback.
139
- * The developer will determine how to resume the flow using one of the provided
140
- * resume handlers.
141
- */
142
- callback(parsedData, {
143
- handleError: (error) => actionResume({ error, token: null }),
144
- handleSuccess: () => actionResume({ error: null, token: null }),
145
- handleNewClientToken: (token) => actionResume({ error: null, token }),
146
- // deprecated, remove in next major version update.
147
- resumeWithError: (error) => actionResume({ error, token: null }),
148
- resumeWithSuccess: (token) => actionResume({ error: null, token }),
149
- });
188
+ RNPrimer.handleSuccess();
150
189
  }
190
+ });
151
191
 
152
- // reset the client session action callback (native bridge callbacks are disposed once they're invoked).
153
- configureOnClientSessionActions(callback);
154
- } catch (e) {
155
- // log error if the client session action JSON string cannot be parsed (this should never happen!).
156
- console.error('[OnClientSessionActions]', 'failed to parse json', e);
157
- }
158
- });
159
- }
192
+ RNPrimer.addListener('onTokenizeSuccessCallback', data => {
193
+ const paymentInstrumentToken: PaymentInstrumentToken = data;
194
+ if (config.onTokenizeSuccess) {
195
+ config.onTokenizeSuccess(paymentInstrumentToken, resumeHandler);
196
+ }
197
+ });
160
198
 
161
- function configureOnResumeSuccess(
162
- callback: OnTokenizeSuccessCallback = (_, __) => {}
163
- ) {
164
- NativeModule.configureOnResumeSuccess((paymentMethodToken: any) => {
165
- try {
166
- callback(paymentMethodToken, {
167
- handleError: (error) => resume({ error, token: null }),
168
- handleSuccess: () => resume({ error: null, token: null }),
169
- handleNewClientToken: (token) => resume({ error: null, token }),
170
- // deprecated
171
- resumeWithError: (error) => resume({ error, token: null }),
172
- resumeWithSuccess: (token) => resume({ error: null, token }),
173
- });
174
- } catch (e) {
175
- console.log('failed to parse json', e);
176
- }
177
- });
178
- }
199
+ RNPrimer.addListener('onResumeSuccess', data => {
200
+ const resumeToken: string = data.resumeToken;
201
+ if (config.onResumeSuccess) {
202
+ config.onResumeSuccess(resumeToken, resumeHandler);
203
+ }
204
+ });
179
205
 
180
- function configureOnVaultSuccess(
181
- callback: OnTokenAddedToVaultCallback = (_) => {}
182
- ) {
183
- NativeModule.configureOnVaultSuccess((data: any) => {
184
- parseCallback<PaymentInstrumentToken>(data, callback);
185
- });
186
- }
206
+ RNPrimer.addListener('onCheckoutDismissed', () => {
207
+ if (config.onDismiss) {
208
+ config.onDismiss();
209
+ }
210
+ });
187
211
 
188
- function configureOnDismiss(callback: OnDismissCallback = () => {}) {
189
- NativeModule.configureOnDismiss((_: any) => callback());
190
- }
212
+ RNPrimer.addListener('onError', data => {
213
+ const err: IPrimerError = data.error;
214
+ if (config.onError) {
215
+ config.onError(err, resumeHandler);
216
+ }
217
+ });
191
218
 
192
- function configureOnError(callback: OnPrimerErrorCallback = (_) => {}) {
193
- NativeModule.configureOnPrimerError((data: any) => {
194
- parseCallback<PrimerError>(data, callback);
195
- });
196
- }
219
+ RNPrimer.showVaultManager(clientToken);
220
+ },
197
221
 
198
- interface ResumeRequest {
199
- error: string | null;
200
- token: string | null;
201
- }
222
+ showPaymentMethod(
223
+ clientToken: string,
224
+ intent: PrimerPaymentMethodIntent,
225
+ config: IPrimerConfig
226
+ ): void {
227
+ RNPrimer.removeAllListeners();
228
+
229
+ if (config.settings || config.theme) {
230
+ RNPrimer.configure(config.settings || null, config.theme || null);
231
+ }
232
+
233
+ let implementedRNCallbacks: any = {
234
+ // isClientTokenCallbackImplemented: (config.onClientTokenCallback !== undefined),
235
+ isTokenAddedToVaultImplemented: (config.onTokenAddedToVault !== undefined),
236
+ isOnResumeSuccessImplemented: (config.onResumeSuccess !== undefined),
237
+ isOnResumeErrorImplemented: (config.onError !== undefined),
238
+ isOnCheckoutDismissedImplemented: (config.onDismiss !== undefined),
239
+ isCheckoutFailedImplemented: (config.onError !== undefined),
240
+ isClientSessionActionsImplemented: (config.onClientSessionActions !== undefined)
241
+ };
242
+
243
+ RNPrimer.setImplementedRNCallbacks(implementedRNCallbacks);
244
+ RNPrimer.showPaymentMethod(clientToken, intent.paymentMethod, intent.vault === true ? "vault" : "checkout");
245
+ },
246
+
247
+ dispose(): void {
248
+ RNPrimer.removeAllListeners();
249
+ RNPrimer.dispose();
250
+ },
251
+
252
+ };
@@ -0,0 +1,170 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ import type { PrimerSettings } from './models/primer-settings';
3
+ import type { PrimerTheme } from './models/primer-theme';
4
+
5
+ const { NativePrimer } = NativeModules;
6
+ const eventEmitter = new NativeEventEmitter(NativePrimer);
7
+
8
+ type EventType =
9
+ | 'onClientTokenCallback'
10
+ | 'onClientSessionActions'
11
+ | 'onTokenizeSuccessCallback'
12
+ | 'onVaultSuccess'
13
+ | 'onResumeSuccess'
14
+ | 'onCheckoutDismissed'
15
+ | 'onError'
16
+ | 'detectImplementedRNCallbacks';
17
+
18
+ export interface IPrimerError {
19
+ errorId: string
20
+ errorDescription?: string
21
+ recoverySuggestion?: string
22
+ }
23
+
24
+ const RNPrimer = {
25
+ ///////////////////////////////////////////
26
+ // Event Emitter
27
+ ///////////////////////////////////////////
28
+ addListener: (eventType: EventType, listener: (...args: any[]) => any) => {
29
+ eventEmitter.addListener(eventType, listener);
30
+ },
31
+
32
+ removeListener: (eventType: EventType, listener: (...args: any[]) => any) => {
33
+ eventEmitter.removeListener(eventType, listener);
34
+ },
35
+
36
+ removeAllListenersForEvent(eventType: EventType) {
37
+ eventEmitter.removeAllListeners(eventType);
38
+ },
39
+
40
+ removeAllListeners() {
41
+ eventEmitter.removeAllListeners('onClientTokenCallback');
42
+ eventEmitter.removeAllListeners('onClientSessionActions');
43
+ eventEmitter.removeAllListeners('onTokenizeSuccessCallback');
44
+ eventEmitter.removeAllListeners('onResumeSuccess');
45
+ eventEmitter.removeAllListeners('onCheckoutDismissed');
46
+ eventEmitter.removeAllListeners('onError');
47
+ eventEmitter.removeAllListeners('detectImplementedRNCallbacks');
48
+ },
49
+
50
+ ///////////////////////////////////////////
51
+ // Native API
52
+ ///////////////////////////////////////////
53
+ configure: (
54
+ settings: PrimerSettings | null,
55
+ theme: PrimerTheme | null
56
+ ): Promise<void> => {
57
+ return new Promise(async (resolve, reject) => {
58
+ try {
59
+ if (settings === null && theme === null) {
60
+ // Do nothing, SDK will use default settings and theme.
61
+ } else if (settings && theme === null) {
62
+ await NativePrimer.configureWithSettings(JSON.stringify(settings));
63
+ } else if (settings === null && theme) {
64
+ await NativePrimer.configureWithTheme(JSON.stringify(theme));
65
+ } else {
66
+ await NativePrimer.configureWithSettings(JSON.stringify(settings));
67
+ await NativePrimer.configureWithTheme(JSON.stringify(theme));
68
+ }
69
+ resolve();
70
+ } catch (err) {
71
+ reject(err);
72
+ }
73
+ });
74
+ },
75
+
76
+ showUniversalCheckout: (clientToken: string | undefined): Promise<void> => {
77
+ return new Promise(async (resolve, reject) => {
78
+ try {
79
+ if (clientToken) {
80
+ await NativePrimer.showUniversalCheckoutWithClientToken(clientToken);
81
+ } else {
82
+ await NativePrimer.showUniversalCheckout();
83
+ }
84
+ resolve();
85
+ } catch (err) {
86
+ reject(err);
87
+ }
88
+ });
89
+ },
90
+
91
+ showVaultManager: (clientToken: string | undefined): Promise<void> => {
92
+ return new Promise(async (resolve, reject) => {
93
+ try {
94
+ if (clientToken) {
95
+ await NativePrimer.showVaultManager(clientToken);
96
+ } else {
97
+ await NativePrimer.showVaultManager();
98
+ }
99
+ resolve();
100
+ } catch (err) {
101
+ reject(err);
102
+ }
103
+ });
104
+ },
105
+
106
+ showPaymentMethod: (
107
+ clientToken: string,
108
+ paymentMethodType: string,
109
+ intent: "checkout" | "vault"
110
+ ): Promise<void> => {
111
+ return new Promise(async (resolve, reject) => {
112
+ try {
113
+ await NativePrimer.showPaymentMethod(clientToken, paymentMethodType, intent);
114
+ resolve();
115
+ } catch (err) {
116
+ reject(err);
117
+ }
118
+ });
119
+ },
120
+
121
+ handleNewClientToken: (clientToken: string | undefined): Promise<void> => {
122
+ return new Promise(async (resolve, reject) => {
123
+ try {
124
+ await NativePrimer.handleNewClientToken(clientToken);
125
+ resolve();
126
+ } catch (err) {
127
+ reject(err);
128
+ }
129
+ });
130
+ },
131
+
132
+ handleError: (err: IPrimerError): Promise<void> => {
133
+ return new Promise(async (resolve, reject) => {
134
+ try {
135
+ await NativePrimer.handleError(JSON.stringify(err));
136
+ resolve();
137
+ } catch (err) {
138
+ reject(err);
139
+ }
140
+ });
141
+ },
142
+
143
+ handleSuccess: (): Promise<void> => {
144
+ return new Promise(async (resolve, reject) => {
145
+ try {
146
+ await NativePrimer.handleSuccess();
147
+ resolve();
148
+ } catch (err) {
149
+ reject(err);
150
+ }
151
+ });
152
+ },
153
+
154
+ setImplementedRNCallbacks: (implementedRNCallbacks: any): Promise<void> => {
155
+ return new Promise(async (resolve, reject) => {
156
+ try {
157
+ await NativePrimer.setImplementedRNCallbacks(JSON.stringify(implementedRNCallbacks));
158
+ resolve();
159
+ } catch (err) {
160
+ reject(err);
161
+ }
162
+ });
163
+ },
164
+
165
+ dispose: (): void => {
166
+
167
+ }
168
+ };
169
+
170
+ export default RNPrimer;
package/src/index.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { IPrimer } from './models/primer';
2
2
  import { PrimerNativeMapping } from './Primer';
3
+ // import type { IPrimerConfig as PrimerConfig } from './models/primer-config';
3
4
 
4
5
  const Primer: IPrimer = PrimerNativeMapping;
5
6
 
@@ -1,32 +1,14 @@
1
- import type { ActionRequest } from './action-request';
2
- import type { ClientSessionActionsRequest } from './client-session-actions-request';
1
+ import type { IPrimerError } from 'src/RNPrimer';
2
+ import type { IClientSessionAction } from 'src/Primer';
3
3
  import type { PaymentInstrumentToken } from './payment-instrument-token';
4
- import type { PrimerError } from './primer-error';
5
4
  import type { PrimerResumeHandler } from './primer-request';
6
5
 
7
- export type OnTokenizeSuccessCallback = (
8
- req: PaymentInstrumentToken,
9
- completion: PrimerResumeHandler
10
- ) => void;
11
-
12
- export type OnClientSessionActionsCallback = (
13
- req: ClientSessionActionsRequest,
14
- completion: PrimerResumeHandler
15
- ) => void;
16
-
17
- export type OnDataChangeCallback = (
18
- req: ActionRequest,
19
- completion: PrimerResumeHandler
20
- ) => void;
21
-
22
- export type OnTokenAddedToVaultCallback = (
23
- data: PaymentInstrumentToken
24
- ) => void;
6
+ // Not implemented
7
+ // export type OnClientTokenCallback = (resumeHandler: PrimerResumeHandler) => void;
25
8
 
9
+ export type OnClientSessionActionsCallback = (clientSessionActions: IClientSessionAction[], resumeHandler: PrimerResumeHandler | null) => void;
10
+ export type OnTokenizeSuccessCallback = (paymentInstrument: PaymentInstrumentToken, resumeHandler: PrimerResumeHandler) => void;
11
+ export type OnTokenAddedToVaultCallback = (paymentInstrument: PaymentInstrumentToken) => void;
12
+ export type OnResumeCallback = (resumeToken: string, resumeHandler: PrimerResumeHandler | null) => void;
13
+ export type OnPrimerErrorCallback = (err: IPrimerError, resumeHandler: PrimerResumeHandler) => void;
26
14
  export type OnDismissCallback = () => void;
27
-
28
- export type OnPrimerErrorCallback = (data: PrimerError) => void;
29
-
30
- export type OnSavedPaymentInstrumentsFetchedCallback = (
31
- data: PaymentInstrumentToken[]
32
- ) => void;