-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
142 lines (131 loc) · 5.19 KB
/
index.js
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
142
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {WebView, Modal, Text, View, TouchableOpacity, ActivityIndicator} from 'react-native';
export default class Rave extends Component {
constructor(props){
super(props);
this.state = {
showModal:false,
}
}
Rave ={
html: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
<title>SUBSCRIPTION</title>
</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 = "${this.props.raveKey}";
window.onload = payWithRave;
function payWithRave() {
var x = getpaidSetup({
PBFPubKey: API_publicKey,
customer_email: "${this.props.billingEmail}",
amount: ${this.props.amount},
customer_phone: "${this.props.billingMobile}",
currency: "NGN",
txref: "${this.props.txref}",
meta: [{
metaname: "${this.props.billingName}",
metavalue: "${this.props.billingMobile}"
}],
onclose: function() {
var resp = {event:'cancelled'};
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};
postMessage(JSON.stringify(resp))
} else {
var resp = {event:'error'};
postMessage(JSON.stringify(resp))
}
x.close();
}
});
}
</script>
</body>
</html>
`
}
messageRecived=(data)=>{
var webResponse = JSON.parse(data);
switch(webResponse.event){
case 'cancelled':
this.setState({showModal:false},()=>{
this.props.onCancel();
})
break;
case 'successful':
this.setState({showModal:false},()=>{
this.props.onSuccess(webResponse.transactionRef);
})
break;
default:
this.setState({showModal:false},()=>{
this.props.onError();
})
break;
}
}
render() {
return (
<View>
<Modal
visible={this.state.showModal}
animationType="slide"
transparent={false}>
<WebView
javaScriptEnabled={true}
javaScriptEnabledAndroid={true}
originWhitelist={['*']}
ref={( webView ) => this.MyWebView = webView}
source={this.Rave}
onMessage={(e)=>{this.messageRecived(e.nativeEvent.data)}}
onLoadStart={()=>this.setState({isLoading:true})}
onLoadEnd={()=>this.setState({isLoading:false})}
/>
{/*Start of Loading modal*/}
{
this.state.isLoading &&
<View>
<ActivityIndicator size="large" color={this.props.ActivityIndicatorColor} />
</View>
}
</Modal>
<TouchableOpacity style={this.props.btnStyles} onPress={()=> this.setState({showModal:true})}>
<Text style={this.props.textStyles} >{this.props.buttonText}</Text>
</TouchableOpacity>
</View>
);
}
}
Rave.defaultProps = {
buttonText: "Pay Now",
amount:10,
ActivityIndicatorColor:'green'
}