omnipay-reactnative-sdk 1.0.4 → 1.0.5

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 (41) hide show
  1. package/lib/commonjs/components/OmnipayProvider.js +2 -2
  2. package/lib/commonjs/components/OmnipayProvider.js.map +1 -1
  3. package/lib/commonjs/components/OmnipayView.js +27 -6
  4. package/lib/commonjs/components/OmnipayView.js.map +1 -1
  5. package/lib/commonjs/components/views/Registration.js +135 -0
  6. package/lib/commonjs/components/views/Registration.js.map +1 -0
  7. package/lib/commonjs/index.js +5 -7
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/lib/colors.js +35 -0
  10. package/lib/commonjs/lib/colors.js.map +1 -0
  11. package/lib/commonjs/lib/config.js +17 -0
  12. package/lib/commonjs/lib/config.js.map +1 -0
  13. package/lib/module/components/OmnipayProvider.js +2 -2
  14. package/lib/module/components/OmnipayProvider.js.map +1 -1
  15. package/lib/module/components/OmnipayView.js +27 -6
  16. package/lib/module/components/OmnipayView.js.map +1 -1
  17. package/lib/module/components/views/Registration.js +126 -0
  18. package/lib/module/components/views/Registration.js.map +1 -0
  19. package/lib/module/index.js +2 -1
  20. package/lib/module/index.js.map +1 -1
  21. package/lib/module/lib/colors.js +28 -0
  22. package/lib/module/lib/colors.js.map +1 -0
  23. package/lib/module/lib/config.js +9 -0
  24. package/lib/module/lib/config.js.map +1 -0
  25. package/lib/typescript/components/OmnipayView.d.ts +16 -3
  26. package/lib/typescript/components/OmnipayView.d.ts.map +1 -1
  27. package/lib/typescript/components/views/Registration.d.ts +15 -0
  28. package/lib/typescript/components/views/Registration.d.ts.map +1 -0
  29. package/lib/typescript/index.d.ts +2 -1
  30. package/lib/typescript/index.d.ts.map +1 -1
  31. package/lib/typescript/lib/colors.d.ts +28 -0
  32. package/lib/typescript/lib/colors.d.ts.map +1 -0
  33. package/lib/typescript/lib/config.d.ts +9 -0
  34. package/lib/typescript/lib/config.d.ts.map +1 -0
  35. package/package.json +1 -1
  36. package/src/components/OmnipayProvider.tsx +2 -2
  37. package/src/components/OmnipayView.tsx +31 -7
  38. package/src/components/views/Registration.tsx +163 -0
  39. package/src/index.tsx +3 -1
  40. package/src/lib/colors.ts +27 -0
  41. package/src/lib/config.ts +9 -0
@@ -0,0 +1,126 @@
1
+ import React, { Fragment, useRef, useState } from 'react';
2
+ import { ActivityIndicator, Platform, StyleSheet, Text, View } from 'react-native';
3
+ import { WebView } from 'react-native-webview';
4
+ import { serverSdkBaseUrl } from 'src/lib/config';
5
+ export const Registration = _ref => {
6
+ let {
7
+ color,
8
+ env,
9
+ publicKey,
10
+ phoneNumber,
11
+ onRegistrationSuccessful,
12
+ onClose
13
+ } = _ref;
14
+ const webviewRef = useRef(null);
15
+ const [webviewStatus, setWebviewStatus] = useState('loading');
16
+ const webHost = getWebHost();
17
+ const webUrl = getWebUrl();
18
+ const onWebviewMount = `
19
+ window.nativeOs = ${Platform.OS};
20
+ true;
21
+ `;
22
+ function getWebHost() {
23
+ return serverSdkBaseUrl[env];
24
+ }
25
+ function getWebUrl() {
26
+ const themeColor = color.includes('#') ? color.split('#')[1] : color;
27
+ return `${webHost}auth/register?theme=${themeColor}&publicKey=${publicKey}&phoneNumber=${phoneNumber}`;
28
+ }
29
+
30
+ // function postMessage(data: PostMessage) {
31
+ // if (!webviewRef.current) {
32
+ // return;
33
+ // }
34
+ // try {
35
+ // webviewRef.current.postMessage(JSON.stringify(data));
36
+ // } catch (error) {}
37
+ // }
38
+
39
+ async function onWebviewMessage(e) {
40
+ try {
41
+ if (e.nativeEvent && e.nativeEvent.data) {
42
+ const eventData = JSON.parse(e.nativeEvent.data);
43
+ const {
44
+ dataKey,
45
+ dataValue
46
+ } = eventData;
47
+ const {
48
+ action,
49
+ details
50
+ } = JSON.parse(dataValue);
51
+ if (dataKey === 'customer.registered') {
52
+ if (onRegistrationSuccessful) {
53
+ onRegistrationSuccessful({
54
+ customerRef: details.customerRef,
55
+ walletId: details.walletId
56
+ });
57
+ }
58
+ return;
59
+ }
60
+ if (action === 'close.registration') {
61
+ if (onClose) {
62
+ onClose();
63
+ }
64
+ return;
65
+ }
66
+ }
67
+ } catch (error) {}
68
+ }
69
+ if (!publicKey.includes('OMNIPUBKEY_')) {
70
+ return /*#__PURE__*/React.createElement(Text, null, "Invalid public key");
71
+ }
72
+ if (phoneNumber.length < 10) {
73
+ return /*#__PURE__*/React.createElement(Text, null, "Invalid phone number");
74
+ }
75
+ if (color.length < 3) {
76
+ return /*#__PURE__*/React.createElement(Text, null, "Invalid color");
77
+ }
78
+ if (!['dev', 'prod'].includes(env)) {
79
+ return /*#__PURE__*/React.createElement(Text, null, "Invalid environment");
80
+ }
81
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(View, {
82
+ style: styles.full
83
+ }, /*#__PURE__*/React.createElement(WebView, {
84
+ source: {
85
+ uri: webUrl
86
+ },
87
+ style: styles.webview,
88
+ injectedJavaScriptBeforeContentLoaded: onWebviewMount,
89
+ onMessage: onWebviewMessage,
90
+ ref: webviewRef,
91
+ onLoadEnd: () => setWebviewStatus('success')
92
+ }), webviewStatus === 'loading' && /*#__PURE__*/React.createElement(View, {
93
+ style: styles.webviewLoader
94
+ }, /*#__PURE__*/React.createElement(ActivityIndicator, {
95
+ size: "small",
96
+ color: color
97
+ }))));
98
+ };
99
+ const styles = StyleSheet.create({
100
+ hide: {
101
+ display: 'none'
102
+ },
103
+ full: {
104
+ flex: 1,
105
+ width: '100%',
106
+ height: '100%'
107
+ },
108
+ webview: {
109
+ flex: 1,
110
+ width: '100%',
111
+ height: '100%'
112
+ },
113
+ webviewLoader: {
114
+ zIndex: 3,
115
+ backgroundColor: 'white',
116
+ alignItems: 'center',
117
+ justifyContent: 'center',
118
+ flex: 1,
119
+ width: '100%',
120
+ height: '100%',
121
+ position: 'absolute',
122
+ top: 0,
123
+ left: 0
124
+ }
125
+ });
126
+ //# sourceMappingURL=Registration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","Fragment","useRef","useState","ActivityIndicator","Platform","StyleSheet","Text","View","WebView","serverSdkBaseUrl","Registration","color","env","publicKey","phoneNumber","onRegistrationSuccessful","onClose","webviewRef","webviewStatus","setWebviewStatus","webHost","getWebHost","webUrl","getWebUrl","onWebviewMount","OS","themeColor","includes","split","onWebviewMessage","e","nativeEvent","data","eventData","JSON","parse","dataKey","dataValue","action","details","customerRef","walletId","error","length","styles","full","uri","webview","webviewLoader","create","hide","display","flex","width","height","zIndex","backgroundColor","alignItems","justifyContent","position","top","left"],"sourceRoot":"../../src","sources":["Registration.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACzD,SACEC,iBAAiB,EACjBC,QAAQ,EACRC,UAAU,EACVC,IAAI,EACJC,IAAI,QACC,cAAc;AACrB,SAASC,OAAO,QAA6B,sBAAsB;AACnE,SAASC,gBAAgB,QAAQ,gBAAgB;AAyBjD,OAAO,MAAMC,YAAY,GAAG,QAOK;EAAA,IAPJ;IAC3BC,KAAK;IACLC,GAAG;IACHC,SAAS;IACTC,WAAW;IACXC,wBAAwB;IACxBC;EACY,CAAC;EACb,MAAMC,UAAU,GAAGhB,MAAM,CAAU,IAAI,CAAC;EACxC,MAAM,CAACiB,aAAa,EAAEC,gBAAgB,CAAC,GAAGjB,QAAQ,CAAS,SAAS,CAAC;EACrE,MAAMkB,OAAO,GAAGC,UAAU,EAAE;EAC5B,MAAMC,MAAM,GAAGC,SAAS,EAAE;EAE1B,MAAMC,cAAc,GAAI;AAC1B,4BAA4BpB,QAAQ,CAACqB,EAAG;AACxC;AACA,OAAO;EAEL,SAASJ,UAAU,GAAG;IACpB,OAAOZ,gBAAgB,CAACG,GAAG,CAAC;EAC9B;EAEA,SAASW,SAAS,GAAG;IACnB,MAAMG,UAAU,GAAGf,KAAK,CAACgB,QAAQ,CAAC,GAAG,CAAC,GAAGhB,KAAK,CAACiB,KA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Provider } from './components/OmnipayProvider';
2
3
  export { useOmnipay } from './hooks/useOmnipay';
3
- export { Omnipay } from './components/OmnipayView';
4
+ export default Omnipay;
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["OmnipayProvider","useOmnipay","Omnipay"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,eAAe,QAAQ,8BAA8B;AAC9D,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,OAAO,QAAQ,0BAA0B"}
1
+ {"version":3,"names":["Omnipay","OmnipayProvider","useOmnipay"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,OAAOA,OAAO,MAAM,0BAA0B;AAE9C,SAASC,eAAe,QAAQ,8BAA8B;AAC9D,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,eAAeF,OAAO"}
@@ -0,0 +1,28 @@
1
+ export const colors = {
2
+ 10: 'rgba(166, 130, 255, 0.1)',
3
+ 20: 'rgba(166, 130, 255, 0.2)',
4
+ 30: 'rgba(166, 130, 255, 0.3)',
5
+ 40: 'rgba(166, 130, 255, 0.4)',
6
+ 50: 'rgba(166, 130, 255, 0.10)',
7
+ 100: '#F0E6FF',
8
+ 200: '#DFCDFF',
9
+ 300: '#CEB3FF',
10
+ 400: '#BFA1FF',
11
+ 500: '#A682FF',
12
+ 600: '#a27dff',
13
+ 700: '#5C41B7',
14
+ 800: '#3E2993',
15
+ 900: '#29187A',
16
+ 1500: '#FF9900',
17
+ black: '#1E3565',
18
+ secondary: '#E06900',
19
+ light: 'rgb(83, 100, 113)',
20
+ iconColor: 'rgba(35, 47, 73, 0.6)',
21
+ bgColor: '#D7EEEB',
22
+ grey: '#61728F',
23
+ danger: '#E32828',
24
+ black500: '#1A1D1F',
25
+ black600: '#3E4554',
26
+ darkGrey: '#6F767E'
27
+ };
28
+ //# sourceMappingURL=colors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["colors","black","secondary","light","iconColor","bgColor","grey","danger","black500","black600","darkGrey"],"sourceRoot":"../../src","sources":["colors.ts"],"mappings":"AAAA,OAAO,MAAMA,MAAM,GAAG;EACpB,EAAE,EAAE,0BAA0B;EAC9B,EAAE,EAAE,0BAA0B;EAC9B,EAAE,EAAE,0BAA0B;EAC9B,EAAE,EAAE,0BAA0B;EAC9B,EAAE,EAAE,2BAA2B;EAC/B,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,IAAI,EAAE,SAAS;EACfC,KAAK,EAAE,SAAS;EAChBC,SAAS,EAAE,SAAS;EACpBC,KAAK,EAAE,mBAAmB;EAC1BC,SAAS,EAAE,uBAAuB;EAClCC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE,SAAS;EACfC,MAAM,EAAE,SAAS;EACjBC,QAAQ,EAAE,SAAS;EACnBC,QAAQ,EAAE,SAAS;EACnBC,QAAQ,EAAE;AACZ,CAAC"}
@@ -0,0 +1,9 @@
1
+ export const serverSdkBaseUrl = {
2
+ dev: 'https://dev.omnipay-sdk.pages.dev/',
3
+ prod: 'https://omnipay-sdk.pages.dev/'
4
+ };
5
+ export const clientSdkBaseUrl = {
6
+ dev: 'https://omnipay-websdk.vercel.app/',
7
+ prod: 'https://sdk.omnipay.ng/'
8
+ };
9
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["serverSdkBaseUrl","dev","prod","clientSdkBaseUrl"],"sourceRoot":"../../src","sources":["config.ts"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,GAAG;EAC9BC,GAAG,EAAE,oCAAoC;EACzCC,IAAI,EAAE;AACR,CAAC;AAED,OAAO,MAAMC,gBAAgB,GAAG;EAC9BF,GAAG,EAAE,oCAAoC;EACzCC,IAAI,EAAE;AACR,CAAC"}
@@ -3,10 +3,23 @@ declare type OmnipayProps = {
3
3
  env: 'dev' | 'prod';
4
4
  publicKey: string;
5
5
  phoneNumber: string;
6
- view: 'bills';
6
+ view: 'bills' | 'registration';
7
7
  onEnterFullScreen?: () => void;
8
8
  onExitFullScreen?: () => void;
9
9
  };
10
- export declare const Omnipay: ({ color, env, publicKey, phoneNumber, view, onEnterFullScreen, onExitFullScreen, }: OmnipayProps) => JSX.Element;
11
- export {};
10
+ declare const Omnipay: {
11
+ ({ color, env, publicKey, phoneNumber, view, onEnterFullScreen, onExitFullScreen, }: OmnipayProps): JSX.Element;
12
+ Registration: ({ color, env, publicKey, phoneNumber, onRegistrationSuccessful, onClose, }: {
13
+ color: string;
14
+ env: "prod" | "dev";
15
+ publicKey: string;
16
+ phoneNumber: string;
17
+ onRegistrationSuccessful?: (({ customerRef, walletId, }: {
18
+ customerRef: string;
19
+ walletId: string;
20
+ }) => void) | undefined;
21
+ onClose?: (() => void) | undefined;
22
+ }) => JSX.Element;
23
+ };
24
+ export default Omnipay;
12
25
  //# sourceMappingURL=OmnipayView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OmnipayView.d.ts","sourceRoot":"","sources":["../../../src/components/OmnipayView.tsx"],"names":[],"mappings":"AAYA,aAAK,YAAY,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,KAAK,GAAG,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAQF,eAAO,MAAM,OAAO,uFAQjB,YAAY,KAAG,WA0FjB,CAAC"}
1
+ {"version":3,"file":"OmnipayView.d.ts","sourceRoot":"","sources":["../../../src/components/OmnipayView.tsx"],"names":[],"mappings":"AAcA,aAAK,YAAY,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,KAAK,GAAG,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,GAAG,cAAc,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAQF,QAAA,MAAM,OAAO;yFAQV,YAAY,GAAG,WAAW;;;;;;;;;;;;CA6G5B,CAAC;AA+BF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,15 @@
1
+ declare type RegisterSuccessType = {
2
+ customerRef: string;
3
+ walletId: string;
4
+ };
5
+ declare type OmnipayProps = {
6
+ color: string;
7
+ env: 'dev' | 'prod';
8
+ publicKey: string;
9
+ phoneNumber: string;
10
+ onRegistrationSuccessful?: ({ customerRef, walletId, }: RegisterSuccessType) => void;
11
+ onClose?: () => void;
12
+ };
13
+ export declare const Registration: ({ color, env, publicKey, phoneNumber, onRegistrationSuccessful, onClose, }: OmnipayProps) => JSX.Element;
14
+ export {};
15
+ //# sourceMappingURL=Registration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Registration.d.ts","sourceRoot":"","sources":["../../../../src/components/views/Registration.tsx"],"names":[],"mappings":"AAWA,aAAK,mBAAmB,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,aAAK,YAAY,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,KAAK,GAAG,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,wBAAwB,CAAC,EAAE,CAAC,EAC1B,WAAW,EACX,QAAQ,GACT,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAQF,eAAO,MAAM,YAAY,+EAOtB,YAAY,KAAG,WA6FjB,CAAC"}
@@ -1,4 +1,5 @@
1
+ import Omnipay from './components/OmnipayView';
1
2
  export { OmnipayProvider } from './components/OmnipayProvider';
2
3
  export { useOmnipay } from './hooks/useOmnipay';
3
- export { Omnipay } from './components/OmnipayView';
4
+ export default Omnipay;
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,eAAe,OAAO,CAAC"}
@@ -0,0 +1,28 @@
1
+ export declare const colors: {
2
+ 10: string;
3
+ 20: string;
4
+ 30: string;
5
+ 40: string;
6
+ 50: string;
7
+ 100: string;
8
+ 200: string;
9
+ 300: string;
10
+ 400: string;
11
+ 500: string;
12
+ 600: string;
13
+ 700: string;
14
+ 800: string;
15
+ 900: string;
16
+ 1500: string;
17
+ black: string;
18
+ secondary: string;
19
+ light: string;
20
+ iconColor: string;
21
+ bgColor: string;
22
+ grey: string;
23
+ danger: string;
24
+ black500: string;
25
+ black600: string;
26
+ darkGrey: string;
27
+ };
28
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../../src/lib/colors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BlB,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const serverSdkBaseUrl: {
2
+ dev: string;
3
+ prod: string;
4
+ };
5
+ export declare const clientSdkBaseUrl: {
6
+ dev: string;
7
+ prod: string;
8
+ };
9
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/lib/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;CAG5B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;CAG5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnipay-reactnative-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Omnipay react native sdk",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -288,7 +288,7 @@ export const OmnipayProvider = ({
288
288
  }
289
289
 
290
290
  const _initiateBills = ({ phoneNumber, onClose }: InitiateBillsType) => {
291
- if (typeof phoneNumber === 'string' && phoneNumber.length === 11) {
291
+ if (typeof phoneNumber === 'string' && phoneNumber.length >= 10) {
292
292
  const webUrl = `${webHost}?theme=${color}&view=bills&publicKey=${publicKey}&phoneNumber=${phoneNumber}`;
293
293
  setWebviewUrl(webUrl);
294
294
  setIsVisible(true);
@@ -320,7 +320,7 @@ export const OmnipayProvider = ({
320
320
  if (visibilityRef.current) {
321
321
  return;
322
322
  }
323
- const isPhoneNumberValid = !!phoneNumber && phoneNumber.length === 11;
323
+ const isPhoneNumberValid = !!phoneNumber && phoneNumber.length >= 10;
324
324
  const isValidCustomerRef = !!customerRef && !!customerRef.trim();
325
325
  const isValidUserRef = !!userRef && !!userRef.trim();
326
326
  const usesNativeShare = true;
@@ -8,14 +8,16 @@ import {
8
8
  Linking,
9
9
  } from 'react-native';
10
10
  import { WebView, WebViewMessageEvent } from 'react-native-webview';
11
- import { getContact, getWebHost } from '../functions';
11
+ import { clientSdkBaseUrl, serverSdkBaseUrl } from 'src/lib/config';
12
+ import { getContact } from '../functions';
13
+ import { Registration } from './views/Registration';
12
14
 
13
15
  type OmnipayProps = {
14
16
  color: string;
15
17
  env: 'dev' | 'prod';
16
18
  publicKey: string;
17
19
  phoneNumber: string;
18
- view: 'bills';
20
+ view: 'bills' | 'registration';
19
21
  onEnterFullScreen?: () => void;
20
22
  onExitFullScreen?: () => void;
21
23
  };
@@ -26,7 +28,7 @@ type PostMessage = {
26
28
 
27
29
  type Status = 'error' | 'loading' | 'success';
28
30
 
29
- export const Omnipay = ({
31
+ const Omnipay = ({
30
32
  color,
31
33
  env,
32
34
  publicKey,
@@ -37,14 +39,33 @@ export const Omnipay = ({
37
39
  }: OmnipayProps): JSX.Element => {
38
40
  const webviewRef = useRef<WebView>(null);
39
41
  const [webviewStatus, setWebviewStatus] = useState<Status>('loading');
40
- const webHost = getWebHost(env);
41
- const webUrl = `${webHost}?theme=${color}&view=${view}&publicKey=${publicKey}&phoneNumber=${phoneNumber}`;
42
+ const webHost = getWebHost();
43
+ const webUrl = getWebUrl();
42
44
 
43
45
  const onWebviewMount = `
44
46
  window.nativeOs = ${Platform.OS};
45
47
  true;
46
48
  `;
47
49
 
50
+ function getWebHost() {
51
+ /**
52
+ * use client rendered app url for bills sdk,
53
+ * else use server rendered app url
54
+ */
55
+ if (view === 'bills') {
56
+ return clientSdkBaseUrl[env];
57
+ }
58
+ return serverSdkBaseUrl[env];
59
+ }
60
+
61
+ function getWebUrl() {
62
+ const themeColor = color.includes('#') ? color.split('#')[1] : color;
63
+ if (view === 'bills') {
64
+ return `${webHost}?theme=${themeColor}&view=${view}&publicKey=${publicKey}&phoneNumber=${phoneNumber}`;
65
+ }
66
+ return `${webHost}auth/register?theme=${themeColor}&publicKey=${publicKey}&phoneNumber=${phoneNumber}`;
67
+ }
68
+
48
69
  function postMessage(data: PostMessage) {
49
70
  if (!webviewRef.current) {
50
71
  return;
@@ -83,7 +104,7 @@ export const Omnipay = ({
83
104
  } catch (error) {}
84
105
  }
85
106
 
86
- if (view !== 'bills') {
107
+ if (view !== 'bills' && view !== 'registration') {
87
108
  return <Text>Invalid view</Text>;
88
109
  }
89
110
 
@@ -91,7 +112,7 @@ export const Omnipay = ({
91
112
  return <Text>Invalid public key</Text>;
92
113
  }
93
114
 
94
- if (phoneNumber.length !== 11) {
115
+ if (phoneNumber.length < 10) {
95
116
  return <Text>Invalid phone number</Text>;
96
117
  }
97
118
 
@@ -153,3 +174,6 @@ const styles = StyleSheet.create({
153
174
  left: 0,
154
175
  },
155
176
  });
177
+
178
+ Omnipay.Registration = Registration;
179
+ export default Omnipay;
@@ -0,0 +1,163 @@
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 'src/lib/config';
11
+
12
+ type RegisterSuccessType = {
13
+ customerRef: string;
14
+ walletId: string;
15
+ };
16
+
17
+ type OmnipayProps = {
18
+ color: string;
19
+ env: 'dev' | 'prod';
20
+ publicKey: string;
21
+ phoneNumber: string;
22
+ onRegistrationSuccessful?: ({
23
+ customerRef,
24
+ walletId,
25
+ }: RegisterSuccessType) => void;
26
+ onClose?: () => void;
27
+ };
28
+
29
+ // type PostMessage = {
30
+ // [key: string]: unknown;
31
+ // };
32
+
33
+ type Status = 'error' | 'loading' | 'success';
34
+
35
+ export const Registration = ({
36
+ color,
37
+ env,
38
+ publicKey,
39
+ phoneNumber,
40
+ onRegistrationSuccessful,
41
+ onClose,
42
+ }: OmnipayProps): JSX.Element => {
43
+ const webviewRef = useRef<WebView>(null);
44
+ const [webviewStatus, setWebviewStatus] = useState<Status>('loading');
45
+ const webHost = getWebHost();
46
+ const webUrl = getWebUrl();
47
+
48
+ const onWebviewMount = `
49
+ window.nativeOs = ${Platform.OS};
50
+ true;
51
+ `;
52
+
53
+ function getWebHost() {
54
+ return serverSdkBaseUrl[env];
55
+ }
56
+
57
+ function getWebUrl() {
58
+ const themeColor = color.includes('#') ? color.split('#')[1] : color;
59
+ return `${webHost}auth/register?theme=${themeColor}&publicKey=${publicKey}&phoneNumber=${phoneNumber}`;
60
+ }
61
+
62
+ // function postMessage(data: PostMessage) {
63
+ // if (!webviewRef.current) {
64
+ // return;
65
+ // }
66
+ // try {
67
+ // webviewRef.current.postMessage(JSON.stringify(data));
68
+ // } catch (error) {}
69
+ // }
70
+
71
+ async function onWebviewMessage(e: WebViewMessageEvent) {
72
+ try {
73
+ if (e.nativeEvent && e.nativeEvent.data) {
74
+ const eventData = JSON.parse(e.nativeEvent.data);
75
+ const { dataKey, dataValue } = eventData;
76
+
77
+ const { action, details } = JSON.parse(dataValue);
78
+
79
+ if (dataKey === 'customer.registered') {
80
+ if (onRegistrationSuccessful) {
81
+ onRegistrationSuccessful({
82
+ customerRef: details.customerRef,
83
+ walletId: details.walletId,
84
+ });
85
+ }
86
+ return;
87
+ }
88
+ if (action === 'close.registration') {
89
+ if (onClose) {
90
+ onClose();
91
+ }
92
+ return;
93
+ }
94
+ }
95
+ } catch (error) {}
96
+ }
97
+
98
+ if (!publicKey.includes('OMNIPUBKEY_')) {
99
+ return <Text>Invalid public key</Text>;
100
+ }
101
+
102
+ if (phoneNumber.length < 10) {
103
+ return <Text>Invalid phone number</Text>;
104
+ }
105
+
106
+ if (color.length < 3) {
107
+ return <Text>Invalid color</Text>;
108
+ }
109
+
110
+ if (!['dev', 'prod'].includes(env)) {
111
+ return <Text>Invalid environment</Text>;
112
+ }
113
+
114
+ return (
115
+ <Fragment>
116
+ <View style={styles.full}>
117
+ <WebView
118
+ source={{
119
+ uri: webUrl,
120
+ }}
121
+ style={styles.webview}
122
+ injectedJavaScriptBeforeContentLoaded={onWebviewMount}
123
+ onMessage={onWebviewMessage}
124
+ ref={webviewRef}
125
+ onLoadEnd={() => setWebviewStatus('success')}
126
+ />
127
+ {webviewStatus === 'loading' && (
128
+ <View style={styles.webviewLoader}>
129
+ <ActivityIndicator size="small" color={color} />
130
+ </View>
131
+ )}
132
+ </View>
133
+ </Fragment>
134
+ );
135
+ };
136
+
137
+ const styles = StyleSheet.create({
138
+ hide: {
139
+ display: 'none',
140
+ },
141
+ full: {
142
+ flex: 1,
143
+ width: '100%',
144
+ height: '100%',
145
+ },
146
+ webview: {
147
+ flex: 1,
148
+ width: '100%',
149
+ height: '100%',
150
+ },
151
+ webviewLoader: {
152
+ zIndex: 3,
153
+ backgroundColor: 'white',
154
+ alignItems: 'center',
155
+ justifyContent: 'center',
156
+ flex: 1,
157
+ width: '100%',
158
+ height: '100%',
159
+ position: 'absolute',
160
+ top: 0,
161
+ left: 0,
162
+ },
163
+ });
package/src/index.tsx CHANGED
@@ -1,3 +1,5 @@
1
+ import Omnipay from './components/OmnipayView';
2
+
1
3
  export { OmnipayProvider } from './components/OmnipayProvider';
2
4
  export { useOmnipay } from './hooks/useOmnipay';
3
- export { Omnipay } from './components/OmnipayView';
5
+ export default Omnipay;
@@ -0,0 +1,27 @@
1
+ export const colors = {
2
+ 10: 'rgba(166, 130, 255, 0.1)',
3
+ 20: 'rgba(166, 130, 255, 0.2)',
4
+ 30: 'rgba(166, 130, 255, 0.3)',
5
+ 40: 'rgba(166, 130, 255, 0.4)',
6
+ 50: 'rgba(166, 130, 255, 0.10)',
7
+ 100: '#F0E6FF',
8
+ 200: '#DFCDFF',
9
+ 300: '#CEB3FF',
10
+ 400: '#BFA1FF',
11
+ 500: '#A682FF',
12
+ 600: '#a27dff',
13
+ 700: '#5C41B7',
14
+ 800: '#3E2993',
15
+ 900: '#29187A',
16
+ 1500: '#FF9900',
17
+ black: '#1E3565',
18
+ secondary: '#E06900',
19
+ light: 'rgb(83, 100, 113)',
20
+ iconColor: 'rgba(35, 47, 73, 0.6)',
21
+ bgColor: '#D7EEEB',
22
+ grey: '#61728F',
23
+ danger: '#E32828',
24
+ black500: '#1A1D1F',
25
+ black600: '#3E4554',
26
+ darkGrey: '#6F767E',
27
+ };
@@ -0,0 +1,9 @@
1
+ export const serverSdkBaseUrl = {
2
+ dev: 'https://dev.omnipay-sdk.pages.dev/',
3
+ prod: 'https://omnipay-sdk.pages.dev/',
4
+ };
5
+
6
+ export const clientSdkBaseUrl = {
7
+ dev: 'https://omnipay-websdk.vercel.app/',
8
+ prod: 'https://sdk.omnipay.ng/',
9
+ };