omnipay-reactnative-sdk 1.1.6 → 1.1.7
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/lib/commonjs/components/OmnipayProvider.js +2 -2
- package/lib/commonjs/components/OmnipayProvider.js.map +1 -1
- package/lib/commonjs/components/OmnipayView.js +4 -0
- package/lib/commonjs/components/OmnipayView.js.map +1 -1
- package/lib/commonjs/components/views/BvnVerification.js +133 -0
- package/lib/commonjs/components/views/BvnVerification.js.map +1 -0
- package/lib/commonjs/components/views/PaylaterAgreement.js +132 -0
- package/lib/commonjs/components/views/PaylaterAgreement.js.map +1 -0
- package/lib/module/components/OmnipayProvider.js +2 -2
- package/lib/module/components/OmnipayProvider.js.map +1 -1
- package/lib/module/components/OmnipayView.js +4 -0
- package/lib/module/components/OmnipayView.js.map +1 -1
- package/lib/module/components/views/BvnVerification.js +124 -0
- package/lib/module/components/views/BvnVerification.js.map +1 -0
- package/lib/module/components/views/PaylaterAgreement.js +123 -0
- package/lib/module/components/views/PaylaterAgreement.js.map +1 -0
- package/lib/typescript/components/OmnipayView.d.ts +24 -0
- package/lib/typescript/components/OmnipayView.d.ts.map +1 -1
- package/lib/typescript/components/views/BvnVerification.d.ts +12 -0
- package/lib/typescript/components/views/BvnVerification.d.ts.map +1 -0
- package/lib/typescript/components/views/PaylaterAgreement.d.ts +19 -0
- package/lib/typescript/components/views/PaylaterAgreement.d.ts.map +1 -0
- package/package.json +5 -4
- package/src/components/OmnipayProvider.tsx +1 -1
- package/src/components/OmnipayView.tsx +4 -0
- package/src/components/views/BvnVerification.tsx +153 -0
- package/src/components/views/PaylaterAgreement.tsx +167 -0
|
@@ -0,0 +1,167 @@
|
|
|
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, WebViewMessageEvent } from 'react-native-webview';
|
|
10
|
+
import { serverSdkBaseUrl } from '../../lib/config';
|
|
11
|
+
|
|
12
|
+
type AgreementSubmittedType = {
|
|
13
|
+
agreementId: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type OmnipayProps = {
|
|
17
|
+
color: string;
|
|
18
|
+
env: 'dev' | 'prod';
|
|
19
|
+
publicKey: string;
|
|
20
|
+
phoneNumber?: string;
|
|
21
|
+
customerRef?: string;
|
|
22
|
+
amount: number;
|
|
23
|
+
lenderId?: string;
|
|
24
|
+
feesId?: string;
|
|
25
|
+
sublimitId?: string;
|
|
26
|
+
onAgreementAccepted: ({ agreementId }: AgreementSubmittedType) => void;
|
|
27
|
+
onClose?: () => void;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type Status = 'error' | 'loading' | 'success';
|
|
31
|
+
|
|
32
|
+
export const PaylaterAgreement = ({
|
|
33
|
+
color,
|
|
34
|
+
env,
|
|
35
|
+
publicKey,
|
|
36
|
+
phoneNumber,
|
|
37
|
+
onAgreementAccepted,
|
|
38
|
+
customerRef,
|
|
39
|
+
amount,
|
|
40
|
+
lenderId,
|
|
41
|
+
feesId,
|
|
42
|
+
sublimitId,
|
|
43
|
+
onClose,
|
|
44
|
+
}: OmnipayProps): JSX.Element => {
|
|
45
|
+
const webviewRef = useRef<WebView>(null);
|
|
46
|
+
const [webviewStatus, setWebviewStatus] = useState<Status>('loading');
|
|
47
|
+
const webHost = getWebHost();
|
|
48
|
+
const webUrl = getWebUrl();
|
|
49
|
+
|
|
50
|
+
const onWebviewMount = `
|
|
51
|
+
window.nativeOs = ${Platform.OS};
|
|
52
|
+
true;
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
function getWebHost() {
|
|
56
|
+
return serverSdkBaseUrl[env];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getWebUrl() {
|
|
60
|
+
const themeColor = color.includes('#') ? color.split('#')[1] : color;
|
|
61
|
+
return `${webHost}paylater/agreement?theme=${themeColor}&publicKey=${publicKey}&phoneNumber=${
|
|
62
|
+
phoneNumber || ''
|
|
63
|
+
}&customerRef=${customerRef || ''}&amount=${amount}&lenderId=${
|
|
64
|
+
lenderId || ''
|
|
65
|
+
}&feesId=${feesId || ''}&sublimitId=${sublimitId || ''}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function onWebviewMessage(e: WebViewMessageEvent) {
|
|
69
|
+
try {
|
|
70
|
+
if (e.nativeEvent && e.nativeEvent.data) {
|
|
71
|
+
const eventData = JSON.parse(e.nativeEvent.data);
|
|
72
|
+
const { dataKey, dataValue } = eventData;
|
|
73
|
+
|
|
74
|
+
if (dataKey === 'agreement.accepted') {
|
|
75
|
+
onAgreementAccepted({
|
|
76
|
+
agreementId: dataValue.agreementId,
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (dataKey === 'close.agreement') {
|
|
82
|
+
if (onClose) {
|
|
83
|
+
onClose();
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!publicKey.includes('OMNIPUBKEY_')) {
|
|
94
|
+
return <Text>Invalid public key</Text>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (color.length < 3) {
|
|
98
|
+
return <Text>Invalid color</Text>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!['dev', 'prod'].includes(env)) {
|
|
102
|
+
return <Text>Invalid environment</Text>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!customerRef) {
|
|
106
|
+
if (!phoneNumber) {
|
|
107
|
+
return <Text>Phone number is required</Text>;
|
|
108
|
+
}
|
|
109
|
+
if (phoneNumber?.length < 10) {
|
|
110
|
+
return <Text>Invalid phone number</Text>;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
|
|
115
|
+
return <Text>Amount is required and should be greater than 0</Text>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<Fragment>
|
|
120
|
+
<View style={styles.full}>
|
|
121
|
+
<WebView
|
|
122
|
+
source={{
|
|
123
|
+
uri: webUrl,
|
|
124
|
+
}}
|
|
125
|
+
style={styles.webview}
|
|
126
|
+
injectedJavaScriptBeforeContentLoaded={onWebviewMount}
|
|
127
|
+
onMessage={onWebviewMessage}
|
|
128
|
+
ref={webviewRef}
|
|
129
|
+
onLoadEnd={() => setWebviewStatus('success')}
|
|
130
|
+
/>
|
|
131
|
+
{webviewStatus === 'loading' && (
|
|
132
|
+
<View style={styles.webviewLoader}>
|
|
133
|
+
<ActivityIndicator size="small" color={color} />
|
|
134
|
+
</View>
|
|
135
|
+
)}
|
|
136
|
+
</View>
|
|
137
|
+
</Fragment>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const styles = StyleSheet.create({
|
|
142
|
+
hide: {
|
|
143
|
+
display: 'none',
|
|
144
|
+
},
|
|
145
|
+
full: {
|
|
146
|
+
flex: 1,
|
|
147
|
+
width: '100%',
|
|
148
|
+
height: '100%',
|
|
149
|
+
},
|
|
150
|
+
webview: {
|
|
151
|
+
flex: 1,
|
|
152
|
+
width: '100%',
|
|
153
|
+
height: '100%',
|
|
154
|
+
},
|
|
155
|
+
webviewLoader: {
|
|
156
|
+
zIndex: 3,
|
|
157
|
+
backgroundColor: 'white',
|
|
158
|
+
alignItems: 'center',
|
|
159
|
+
justifyContent: 'center',
|
|
160
|
+
flex: 1,
|
|
161
|
+
width: '100%',
|
|
162
|
+
height: '100%',
|
|
163
|
+
position: 'absolute',
|
|
164
|
+
top: 0,
|
|
165
|
+
left: 0,
|
|
166
|
+
},
|
|
167
|
+
});
|