-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
164 lines (148 loc) · 4.41 KB
/
index.html
File metadata and controls
164 lines (148 loc) · 4.41 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="oe_formstack_addresslookup.AUG.js"></script>
<title>Google Pay Button</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
<style>
body {
font-family: gordita, Arial, sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.button-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#gpay-button {
width: 140pt;
height: 30pt;
background-color: #000;
border: 1px solid #5f6368;
border-radius: 900px;
font-family: Arial, sans-serif;
font-size: 14px;
text-align: center;
text-decoration: none;
color: white;
line-height: 40px; /* Vertically center the text */
cursor: pointer;
margin-bottom: 14px;
display: none;
}
.apple-pay-button {
-webkit-appearance: -apple-pay-button;
-apple-pay-button-type: pay;
-apple-pay-button-style: black;
border-radius: 950px;
width: 140pt;
height: 30pt;
margin: 10px;
cursor: pointer;
display: none;
}
.pay-icon {
width: 45px;
height: 45px;
vertical-align: middle;
}
#nonce {
display: flex;
justify-content: center;
font-family: Arial, sans-serif;
font-size: 11px;
margin: 20px;
}
input[type="text"] {
width: 140pt;
margin-bottom: 20px;
padding: 12px;
border: 1px solid #ccc;
border-radius: 3px;
}
label {
margin-bottom: 10px;
display: block;
}
</style>
</head>
<body>
<h3>This is WebView</h3>
<label for="address">Address:</label>
<input type="text" id="address" name="address">
<div>
<label for="custId">Customer ID</label>
<input type="text" id="custId" />
</div>
<div class="button-container">
<div id="gpay-button">
Pay with <img class="pay-icon" src="GPay.svg" alt="Gpay" />
</div>
<div id="applepay-button" class="apple-pay-button"></div>
<div id="nonce"></div>
</div>
<script>
function isIOSWebView() {
return /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(
navigator.userAgent
);
}
function isAndroidWebView() {
return /Android.*(?:Version\/(\d+)\.\d+)?\s+Chrome\/[.0-9]*\s+Mobile/i.test(
navigator.userAgent
);
}
// Function to show/hide buttons based on WebView type
function togglePayButtons() {
const gpayButton = document.getElementById("gpay-button");
const applepayButton = document.getElementById("applepay-button");
if (isIOSWebView()) {
gpayButton.style.display = "none";
applepayButton.style.display = "inline-block";
applepayButton.addEventListener("click", () => {
window.ReactNativeWebView.postMessage(
JSON.stringify({
customerId: document.getElementById("custId").value,
paymentMethod: "ApplePay",
})
);
});
} else if (isAndroidWebView()) {
gpayButton.style.display = "inline-block";
applepayButton.style.display = "none";
gpayButton.addEventListener("click", () => {
window.ReactNativeWebView.postMessage(
JSON.stringify({
customerId: document.getElementById("custId").value,
paymentMethod: "GPay",
})
);
});
} else {
gpayButton.style.display = "inline-block";
applepayButton.style.display = "inline-block";
gpayButton.addEventListener("click", () => {
console.log(
JSON.stringify({
customerId: document.getElementById("custId").value,
paymentMethod: "GPay",
})
);
});
}
}
window.onload = togglePayButtons;
</script>
</body>
</html>