Skip to content

Commit 9fbbded

Browse files
committed
Update donation page
1 parent 424f6a6 commit 9fbbded

3 files changed

Lines changed: 51 additions & 25 deletions

File tree

public/css/base.css

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,10 +1143,10 @@ pre span {
11431143
right: 15px;
11441144
z-index: -1;
11451145
}
1146-
.donate .dropdown {
1146+
.donate .donateInput {
11471147
background: transparent;
1148-
width: 150px;
1149-
height: 50px;
1148+
width: 75px;
1149+
height: 27px;
11501150
padding: 10px;
11511151
font-size: 16px;
11521152
line-height: 1;
@@ -1157,6 +1157,17 @@ pre span {
11571157
outline: none;
11581158
cursor: pointer;
11591159
}
1160+
.donate .comment {
1161+
background: transparent;
1162+
padding: 10px;
1163+
font-size: 16px;
1164+
line-height: 1;
1165+
border: 1px solid #ccc;
1166+
border-radius: 3px;
1167+
-webkit-appearance: none;
1168+
-moz-appearance: none;
1169+
outline: none;
1170+
}
11601171
.donate .button {
11611172
width: 150px;
11621173
height: 50px;
@@ -1201,7 +1212,7 @@ pre span {
12011212
transform: scale(0.75);
12021213
}
12031214
.dropdown_frame,
1204-
.dropdown,
1215+
.donateInput,
12051216
.button {
12061217
width: 100% !important;
12071218
}

routes/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ router.post('/donate', function(req, res, next) {
4444
let data = JSON.parse(req.body.data);
4545

4646
stripe.charges.create({
47-
amount: data.price,
47+
amount: data.token.price,
4848
currency: "usd",
49-
source: data.id, // obtained with Stripe.js
50-
description: "Donation from " + data.email
49+
source: data.token.id, // obtained with Stripe.js
50+
description: `Donation from ${data.token.email}
51+
${data.comment}`
5152
}, function(err, charge) {
5253
if (err) return res.sendStatus(400);
5354
else res.sendStatus(200);

views/pages/donate.ejs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,27 @@
1717

1818
<section id="donate">
1919
<h2>How can I donate?</h2>
20-
<p>You can donate using our secure stripe donation button below. Please select your desired donation and click "Donate Now". But you're pretty smart and probably figured that out on your own didn't you?</p>
20+
<p>You can donate using our secure Stripe donation button below. Please enter your desired donation and click "Donate Now". But you're pretty smart and probably figured that out on your own didn't you?</p>
2121

2222
<script src="https://checkout.stripe.com/checkout.js"></script>
2323

2424
<div class="donate_form">
25-
<div class="dropdown_frame">
26-
<select id="donation_amount" class="dropdown">
27-
<option value="100">$1.00</option>
28-
<option value="500">$5.00</option>
29-
<option value="1000">$10.00</option>
30-
<option value="1500">$15.00</option>
31-
<option value="2000">$20.00</option>
32-
<option value="5000">$50.00</option>
33-
<option value="10000">$100.00</option>
34-
</select>
35-
</div>
36-
<button id="donate_button" class="button">Donate Now</button>
25+
$ <input class="donateInput" id="donation_amount" type="number" min="1.00" step="1.00" value="5.00" />
26+
<button id="donate_button" class="button">Donate Now</button><br><br>
27+
<textarea class="comment" rows="3" cols="60" id="comment" placeholder="Leave a comment"></textarea>
3728
</div>
3829

3930
<script>
4031
var handler = StripeCheckout.configure({
4132
key: '<%=stripePublishKey%>',
4233
image: 'img/donate_small.png',
4334
token: function(token, args) {
44-
token.price = Number(document.getElementById('donation_amount').value);
35+
token.price = Number(donationAmt());
4536
4637
$.ajax({
4738
type: 'POST',
4839
url: '/donate',
49-
data: { data: JSON.stringify(token) },
40+
data: { data: JSON.stringify({token, comment: document.getElementById('comment').value}) },
5041
success: function(data) {
5142
window.alert("Thanks for your donation!");
5243
},
@@ -61,10 +52,26 @@
6152
handler.open({
6253
name: 'Random User API',
6354
description: 'Thanks for donating!',
64-
amount: Number(document.getElementById('donation_amount').value)
55+
amount: Number(donationAmt())
6556
});
6657
e.preventDefault();
6758
});
59+
60+
function donationAmt() {
61+
let input = document.getElementById('donation_amount');
62+
let amt = input.value;
63+
64+
if (Number(amt) < 1) {
65+
input.value = "1.00";
66+
return 100;
67+
} else if (amt.indexOf('.') === -1) {
68+
input.value = amt + ".00";
69+
return Number(amt)*100;
70+
} else {
71+
input.value = Number(amt).toFixed(2);
72+
return Number((input.value*100).toFixed(0));
73+
}
74+
}
6875
</script>
6976

7077
<%//<p style="text-align: center;">Don't have your card details handy? <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QBRGZ79MNX9W6" target="_blank">Click here to donate via PayPal</a></p>%>
@@ -74,17 +81,24 @@
7481
7582
<section id="why">
7683
<h2>Why should I donate?</h2>
77-
<p>The Random User Generator API is a 100% free service and is paid for out of our own pockets. <strong>We generate up to a million random users a day</strong>, and the bandwidth involved to deliver that information is costly. Random User Generator will never require a paid subscription to use our service, and we strive to continue providing this service free to you for life. Donating isn't required, but it will help us continue to improve and enhance our service.</p>
84+
<p>The Random User Generator API is a 100% free service and is paid for out of our own pockets. <strong>We generate up to <span id='gen'>1,000,000</span> random users everyday</strong>, and the servers involved to deliver that information is costly. Random User Generator will never require a paid subscription to use our service, and we strive to continue providing this service free to you for life. Donating isn't required, but it will help us continue to improve and enhance our service.</p>
7885
</section>
7986
8087
<section class="advertisement">
8188
<h2>Advertising</h2>
82-
<p>Alternatively, we also earn money from you clicking on the verious advertisements you see on the site. If you aren't seeing ads, it's most likely because you are running an adblock service. We don't blame you, we hate ads too! However it would help us out a lot of you disabled your adblock service for our website.</p>
89+
<p>Alternatively, we also earn money from you clicking on the various advertisements you see on the site. If you aren't seeing ads, it's most likely because you are running an adblock service. We don't blame you, we hate ads too! However it would help us out a lot of you disabled your adblock service for our website.</p>
8390
<p>If not, that's cool too. We love you either way.</p>
8491
</section>
8592
<% include ../snippets/ads %>
8693
</div>
8794
<% include ../snippets/footer %>
8895
<% include ../snippets/analytics %>
96+
<script>
97+
setInterval(() => {
98+
$.get("getStats", data => {
99+
document.getElementById('gen').innerHTML = data['30'].total;
100+
});
101+
}, 1000);
102+
</script>
89103
</body>
90104
</html>

0 commit comments

Comments
 (0)