-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
141 lines (135 loc) · 4.93 KB
/
index.js
File metadata and controls
141 lines (135 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Rave Web View for React Native
* Author: Martins Joseph (creativeJoe007)
* Website: https://creativejoe007.com
*/
import React, {useState, createRef} from 'react';
import {Modal, Text, View, TouchableOpacity, ActivityIndicator} from 'react-native';
import { WebView } from 'react-native-webview';
let showModal;
let setShowModal;
let isLoading;
let setIsLoading;
export const RaveWebView = props => {
[showModal, setShowModal] = useState(props.active || false);
[isLoading, setIsLoading] = useState(false);
let webView = createRef();
let Rave = {
html: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body onload="payWithRave()" style="background-color:#fff;height:100vh ">
<form>
<script src="https://api.ravepay.co/flwv3-pug/getpaidx/api/flwpbf-inline.js"></script>
</form>
<script>
const API_publicKey = "${props.raveKey}";
window.onload = payWithRave;
function payWithRave() {
var x = getpaidSetup({
PBFPubKey: API_publicKey,
amount: ${props.amount},
customer_phone: "${props.customerPhone || ''}",
customer_email: "${props.customerEmail || ''}",
custom_description: "${props.contentDescription}",
currency: "${props.currency || 'NGN'}",
txref: "${props.txref}",
meta: [{
metaname: "${props.billingName || props.customerEmail || ''}",
metavalue: "${props.billingMobile || props.customerPhone || ''}"
}],
onclose: function() {
var resp = {event:'cancelled'};
window.ReactNativeWebView.postMessage(JSON.stringify(resp))
},
callback: function(response) {
var txref = response.tx.txRef;
if (
response.tx.chargeResponseCode == "00" ||
response.tx.chargeResponseCode == "0"
) {
var resp = {event:'successful', transactionRef:txref};
window.ReactNativeWebView.postMessage(JSON.stringify(resp))
} else {
var resp = {event:'error'};
window.ReactNativeWebView.postMessage(JSON.stringify(resp))
}
x.close();
}
});
}
</script>
</body>
</html>
`
}
return (
<View>
<Modal
visible={showModal}
style={{backgroundColor: 'red'}}
animationType="slide"
transparent={false}>
<WebView
javaScriptEnabled={true}
javaScriptEnabledAndroid={true}
originWhitelist={['*']}
ref={webView}
source={Rave}
onMessage={(e)=> messageRecived(props, e.nativeEvent.data)}
onLoadStart={() => setIsLoading(true)}
onLoadEnd={() => setIsLoading(false)}
/>
{/*Start of Loading modal*/}
{
isLoading === true && (
<View style={{position: 'absolute', height: '100%', width: '100%', justifyContent: 'center', alignItems: 'center', top: 0}}>
<ActivityIndicator size="large" color={props.ActivityIndicatorColor || '#f5a623'} />
<TouchableOpacity
style={{
position: 'absolute',
top: 20,
right: 20,
backgroundColor: '#f5a623',
borderRadius: 4,
padding: 10,
paddingTop: 7,
paddingBottom: 7
}}
onPress={() => {
setIsLoading(false)
props.onCancel();
}}>
<Text style={{color: 'white', fontSize: 12, fontWeight: 'bold'}}>Cancel</Text>
</TouchableOpacity>
</View>
)
}
</Modal>
{
typeof props.active == "undefined" && (
<TouchableOpacity style={props.btnStyles} onPress={() => setShowModal(true)}>
<Text style={props.textStyles}>{props.buttonText}</Text>
</TouchableOpacity>
)
}
</View>
);
}
const messageRecived = async (props, data) => {
var webResponse = JSON.parse(data);
switch(webResponse.event){
case 'cancelled':
props.onCancel();
break;
case 'successful':
props.onSuccess(webResponse);
break;
default:
props.onError();
break;
}
}