omnipay-reactnative-sdk 1.2.7 → 1.3.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/README.md +1 -0
- package/lib/commonjs/components/OmnipayProvider.js +41 -5
- package/lib/commonjs/components/OmnipayProvider.js.map +1 -1
- package/lib/commonjs/components/OmnipayView.js +2 -0
- package/lib/commonjs/components/OmnipayView.js.map +1 -1
- package/lib/commonjs/components/views/FaceVerification.js +108 -0
- package/lib/commonjs/components/views/FaceVerification.js.map +1 -0
- package/lib/commonjs/components/views/PaymentLinking.js +3 -2
- package/lib/commonjs/components/views/PaymentLinking.js.map +1 -1
- package/lib/commonjs/lib/config.js +5 -1
- package/lib/commonjs/lib/config.js.map +1 -1
- package/lib/commonjs/utils/buildUrlWithMetadata.js +14 -1
- package/lib/commonjs/utils/buildUrlWithMetadata.js.map +1 -1
- package/lib/commonjs/utils/encryption.js +35 -0
- package/lib/commonjs/utils/encryption.js.map +1 -0
- package/lib/module/components/OmnipayProvider.js +41 -5
- package/lib/module/components/OmnipayProvider.js.map +1 -1
- package/lib/module/components/OmnipayView.js +2 -0
- package/lib/module/components/OmnipayView.js.map +1 -1
- package/lib/module/components/views/FaceVerification.js +100 -0
- package/lib/module/components/views/FaceVerification.js.map +1 -0
- package/lib/module/components/views/PaymentLinking.js +3 -2
- package/lib/module/components/views/PaymentLinking.js.map +1 -1
- package/lib/module/lib/config.js +4 -0
- package/lib/module/lib/config.js.map +1 -1
- package/lib/module/utils/buildUrlWithMetadata.js +13 -1
- package/lib/module/utils/buildUrlWithMetadata.js.map +1 -1
- package/lib/module/utils/encryption.js +28 -0
- package/lib/module/utils/encryption.js.map +1 -0
- package/lib/typescript/components/OmnipayProvider.d.ts.map +1 -1
- package/lib/typescript/components/OmnipayView.d.ts +8 -1
- package/lib/typescript/components/OmnipayView.d.ts.map +1 -1
- package/lib/typescript/components/views/FaceVerification.d.ts +10 -0
- package/lib/typescript/components/views/FaceVerification.d.ts.map +1 -0
- package/lib/typescript/components/views/PaymentLinking.d.ts +2 -1
- package/lib/typescript/components/views/PaymentLinking.d.ts.map +1 -1
- package/lib/typescript/lib/config.d.ts +4 -0
- package/lib/typescript/lib/config.d.ts.map +1 -1
- package/lib/typescript/utils/buildUrlWithMetadata.d.ts +4 -0
- package/lib/typescript/utils/buildUrlWithMetadata.d.ts.map +1 -1
- package/lib/typescript/utils/encryption.d.ts +3 -0
- package/lib/typescript/utils/encryption.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/OmnipayProvider.tsx +41 -7
- package/src/components/OmnipayView.tsx +2 -0
- package/src/components/views/FaceVerification.tsx +130 -0
- package/src/components/views/PaymentLinking.tsx +4 -2
- package/src/lib/config.ts +5 -0
- package/src/utils/buildUrlWithMetadata.ts +16 -4
- package/src/utils/encryption.ts +38 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React, { Fragment, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ActivityIndicator,
|
|
4
|
+
Platform,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Text,
|
|
7
|
+
View,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { WebView, type WebViewMessageEvent } from 'react-native-webview';
|
|
10
|
+
import { faceVerificationSdkBaseUrl } from '../../lib/config';
|
|
11
|
+
|
|
12
|
+
type OmnipayProps = {
|
|
13
|
+
color: string;
|
|
14
|
+
env: 'dev' | 'prod';
|
|
15
|
+
preAuthKey: string;
|
|
16
|
+
onVerificationSuccessful: (facAuthToken: string) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type Status = 'error' | 'loading' | 'success';
|
|
20
|
+
|
|
21
|
+
export const FaceVerification = ({
|
|
22
|
+
color,
|
|
23
|
+
env,
|
|
24
|
+
preAuthKey,
|
|
25
|
+
onVerificationSuccessful,
|
|
26
|
+
}: OmnipayProps): React.JSX.Element => {
|
|
27
|
+
const webviewRef = useRef<WebView>(null);
|
|
28
|
+
const [webviewStatus, setWebviewStatus] = useState<Status>('loading');
|
|
29
|
+
const webHost = getWebHost();
|
|
30
|
+
const webUrl = getWebUrl();
|
|
31
|
+
|
|
32
|
+
const onWebviewMount = `
|
|
33
|
+
window.nativeOs = ${Platform.OS};
|
|
34
|
+
true;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
function getWebHost() {
|
|
38
|
+
return faceVerificationSdkBaseUrl[env];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getWebUrl() {
|
|
42
|
+
const themeColor = color.includes('#') ? color.split('#')[1] : color;
|
|
43
|
+
return `${webHost}auth?theme=${themeColor}&preAuthKey=${preAuthKey}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function handleMessage(e: WebViewMessageEvent) {
|
|
47
|
+
try {
|
|
48
|
+
if (e.nativeEvent && e.nativeEvent.data) {
|
|
49
|
+
const data = JSON.parse(e.nativeEvent.data);
|
|
50
|
+
|
|
51
|
+
if (data.type === 'FACE_AUTH_COMPLETE' && data.faceAuthToken) {
|
|
52
|
+
onVerificationSuccessful(data.faceAuthToken);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
// Handle parsing errors silently
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!preAuthKey) {
|
|
61
|
+
return <Text>Preauth key is required</Text>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (preAuthKey.length !== 64) {
|
|
65
|
+
return <Text>Invalid preauth key</Text>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (color.length < 3) {
|
|
69
|
+
return <Text>Invalid color</Text>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!['dev', 'prod'].includes(env)) {
|
|
73
|
+
return <Text>Invalid environment</Text>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Fragment>
|
|
78
|
+
<View style={styles.full}>
|
|
79
|
+
<WebView
|
|
80
|
+
source={{
|
|
81
|
+
uri: webUrl,
|
|
82
|
+
}}
|
|
83
|
+
style={styles.webview}
|
|
84
|
+
injectedJavaScriptBeforeContentLoaded={onWebviewMount}
|
|
85
|
+
onMessage={handleMessage}
|
|
86
|
+
ref={webviewRef}
|
|
87
|
+
onLoadEnd={() => setWebviewStatus('success')}
|
|
88
|
+
mediaPlaybackRequiresUserAction={false}
|
|
89
|
+
allowsInlineMediaPlayback={true}
|
|
90
|
+
javaScriptEnabled={true}
|
|
91
|
+
domStorageEnabled={true}
|
|
92
|
+
allowsFullscreenVideo={true}
|
|
93
|
+
/>
|
|
94
|
+
{webviewStatus === 'loading' && (
|
|
95
|
+
<View style={styles.webviewLoader}>
|
|
96
|
+
<ActivityIndicator size="small" color={color} />
|
|
97
|
+
</View>
|
|
98
|
+
)}
|
|
99
|
+
</View>
|
|
100
|
+
</Fragment>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const styles = StyleSheet.create({
|
|
105
|
+
hide: {
|
|
106
|
+
display: 'none',
|
|
107
|
+
},
|
|
108
|
+
full: {
|
|
109
|
+
flex: 1,
|
|
110
|
+
width: '100%',
|
|
111
|
+
height: '100%',
|
|
112
|
+
},
|
|
113
|
+
webview: {
|
|
114
|
+
flex: 1,
|
|
115
|
+
width: '100%',
|
|
116
|
+
height: '100%',
|
|
117
|
+
},
|
|
118
|
+
webviewLoader: {
|
|
119
|
+
zIndex: 3,
|
|
120
|
+
backgroundColor: 'white',
|
|
121
|
+
alignItems: 'center',
|
|
122
|
+
justifyContent: 'center',
|
|
123
|
+
flex: 1,
|
|
124
|
+
width: '100%',
|
|
125
|
+
height: '100%',
|
|
126
|
+
position: 'absolute',
|
|
127
|
+
top: 0,
|
|
128
|
+
left: 0,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
@@ -15,6 +15,7 @@ type OmnipayProps = {
|
|
|
15
15
|
publicKey: string;
|
|
16
16
|
phoneNumber?: string;
|
|
17
17
|
customerRef?: string;
|
|
18
|
+
userRef?: string;
|
|
18
19
|
amount: number;
|
|
19
20
|
sessionId: string;
|
|
20
21
|
orderId: string;
|
|
@@ -30,6 +31,7 @@ export const PaymentLinking = ({
|
|
|
30
31
|
publicKey,
|
|
31
32
|
phoneNumber,
|
|
32
33
|
customerRef,
|
|
34
|
+
userRef,
|
|
33
35
|
amount,
|
|
34
36
|
sessionId,
|
|
35
37
|
orderId,
|
|
@@ -56,7 +58,7 @@ export const PaymentLinking = ({
|
|
|
56
58
|
phoneNumber || ''
|
|
57
59
|
}&customerRef=${customerRef || ''}&amountPending=${amount}&sessionId=${
|
|
58
60
|
sessionId || ''
|
|
59
|
-
}&orderId=${orderId || ''}`;
|
|
61
|
+
}&orderId=${orderId || ''}&userRef=${userRef || ''}`;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
async function onWebviewMessage(e: WebViewMessageEvent) {
|
|
@@ -94,7 +96,7 @@ export const PaymentLinking = ({
|
|
|
94
96
|
return <Text>Invalid environment</Text>;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
if (!customerRef) {
|
|
99
|
+
if (!customerRef && !userRef) {
|
|
98
100
|
if (!phoneNumber) {
|
|
99
101
|
return <Text>Phone number is required</Text>;
|
|
100
102
|
}
|
package/src/lib/config.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters out undefined, null, and empty string values from params
|
|
3
|
+
*/
|
|
4
|
+
export function filterParams(
|
|
5
|
+
params: Record<string, string | number | boolean>
|
|
6
|
+
): Record<string, string | number | boolean> {
|
|
7
|
+
return Object.entries(params).reduce((acc, [key, value]) => {
|
|
8
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
9
|
+
acc[key] = value;
|
|
10
|
+
}
|
|
11
|
+
return acc;
|
|
12
|
+
}, {} as Record<string, string | number | boolean>);
|
|
13
|
+
}
|
|
14
|
+
|
|
1
15
|
export default function buildUrlWithMetadata(
|
|
2
16
|
baseUrl: string,
|
|
3
17
|
metadata: Record<string, string | number | boolean>
|
|
4
18
|
): string {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
([_, value]) => value !== undefined && value !== null && value !== ''
|
|
8
|
-
)
|
|
19
|
+
const filtered = filterParams(metadata);
|
|
20
|
+
const query = Object.entries(filtered)
|
|
9
21
|
.map(
|
|
10
22
|
([key, value]) =>
|
|
11
23
|
`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise */
|
|
2
|
+
|
|
3
|
+
import { filterParams } from './buildUrlWithMetadata';
|
|
4
|
+
|
|
5
|
+
const ENCRYPTION_KEY = 'OmN1p@y$3cUr3K3y2024SDK';
|
|
6
|
+
|
|
7
|
+
export function encryptData(text: string): string {
|
|
8
|
+
let hex = '';
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
for (let i = 0; i < text.length; i++) {
|
|
12
|
+
const xorValue =
|
|
13
|
+
text.charCodeAt(i) ^
|
|
14
|
+
ENCRYPTION_KEY.charCodeAt(i % ENCRYPTION_KEY.length);
|
|
15
|
+
|
|
16
|
+
hex += xorValue.toString(16).padStart(2, '0');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return hex;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error('Encryption error:', error);
|
|
22
|
+
throw new Error('Failed to encrypt data');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function encryptUrlParams(
|
|
27
|
+
params: Record<string, string | number | boolean>
|
|
28
|
+
): string {
|
|
29
|
+
try {
|
|
30
|
+
const filteredParams = filterParams(params);
|
|
31
|
+
const jsonString = JSON.stringify(filteredParams);
|
|
32
|
+
|
|
33
|
+
return encryptData(jsonString);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('Encryption error:', error);
|
|
36
|
+
throw new Error('Failed to encrypt data');
|
|
37
|
+
}
|
|
38
|
+
}
|