-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdonate.html
More file actions
327 lines (291 loc) · 11.7 KB
/
Copy pathdonate.html
File metadata and controls
327 lines (291 loc) · 11.7 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!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" />
<title>Support Jachu | Donate</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/file/styles.css" />
<style>
/* PRESERVING YOUR EXACT CSS */
.donation-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
margin-bottom: 15px;
}
.amount-chip {
background: rgba(30, 41, 59, 0.45);
border: 1px solid var(--border-color);
color: var(--text-main);
border-radius: 10px;
padding: 12px;
cursor: pointer;
font-weight: 600;
transition: var(--transition-speed);
}
.amount-chip.active,
.amount-chip:hover {
border-color: var(--primary-accent);
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
background: rgba(79, 70, 229, 0.2);
}
.row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.char-counter {
margin-top: -6px;
margin-bottom: 14px;
text-align: right;
color: var(--text-muted);
font-size: 0.8rem;
}
.note {
margin-top: 18px;
font-size: 0.9rem;
color: var(--text-muted);
line-height: 1.5;
text-align: center;
}
#successCard {
display: none;
margin-top: 16px;
padding: 18px;
border: 1px solid rgba(34, 197, 94, 0.35);
background: rgba(34, 197, 94, 0.1);
border-radius: 14px;
text-align: left;
animation: popIn 0.35s ease;
}
#successCard h3 { margin-top: 0; margin-bottom: 8px; color: #4ade80; }
#successCard p { margin: 4px 0; color: #dcfce7; font-size: 0.92rem; }
@keyframes popIn {
from { transform: translateY(8px) scale(0.98); opacity: 0; }
to { transform: translateY(0) scale(1); opacity: 1; }
}
@media (max-width: 600px) {
.row { grid-template-columns: 1fr; }
.donation-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
</style>
</head>
<body>
<div id="authButtons">
<a href="/index.html" class="button" style="background: transparent; border: none; box-shadow: none; color: #a5b4fc; width: auto; padding: 8px 12px;">🏠 Home</a>
</div>
<div class="main-container">
<h1 class="title">Support Jachu 💜</h1>
<div class="shortener-box">
<p style="margin-top: 0; color: var(--text-muted);">Your contribution helps keep this URL shortener fast, free, and improving every week.</p>
<div class="input-group">
<label for="donationAmount" style="display: block; margin-bottom: 8px; color: var(--text-muted);">Choose amount (INR)</label>
<div class="donation-grid" id="presetAmounts">
<button type="button" class="amount-chip" data-amount="9900">₹99</button>
<button type="button" class="amount-chip" data-amount="19900">₹199</button>
<button type="button" class="amount-chip" data-amount="49900">₹499</button>
<button type="button" class="amount-chip" data-amount="99900">₹999</button>
<button type="button" class="amount-chip" data-amount="149900">₹1499</button>
<button type="button" class="amount-chip" data-amount="249900">₹2499</button>
</div>
<input type="number" id="donationAmount" class="input" min="1" step="1" placeholder="Or enter custom amount in INR" />
</div>
<div class="row">
<div class="input-group">
<input type="text" id="donorName" class="input" placeholder="Your name" autocomplete="name" />
</div>
<div class="input-group">
<input type="email" id="donorEmail" class="input" placeholder="Your email" autocomplete="email" />
</div>
</div>
<div class="row">
<div class="input-group">
<input type="tel" id="donorPhone" class="input" placeholder="Phone (optional)" autocomplete="tel" />
</div>
<div class="input-group">
<select id="donationPurpose" class="input">
<option value="General support">General support</option>
<option value="Server costs">Server costs</option>
<option value="Feature development">Feature development</option>
<option value="Open source contribution">Open source contribution</option>
</select>
</div>
</div>
<div class="input-group" style="margin-top: -2px; margin-bottom: 12px;">
<label style="display:flex; align-items:center; gap:8px; color: var(--text-muted); cursor:pointer;">
<input id="anonymousMode" type="checkbox" /> Donate anonymously
</label>
</div>
<div class="input-group">
<textarea id="donationNote" class="input" rows="4" maxlength="240" placeholder="Add a note (optional)"></textarea>
<div class="char-counter"><span id="noteCount">0</span>/240</div>
</div>
<button id="payBtn" class="button" onclick="startDonation()">Donate with Razorpay</button>
<p class="note" id="modeNotice">Loading payment system...</p>
<div id="successCard">
<h3>🎉 Donation Received</h3>
<p id="successLine1"></p>
<p id="successLine2"></p>
<p style="opacity:0.9;">Thank you for supporting Jachu. Your donation was also saved to admin panel records.</p>
</div>
</div>
</div>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.22.2/firebase-app-compat.js"></script>
<script>
let RAZORPAY_KEY_ID = null;
// 1. Initialize & Fetch Config
async function initDonationSystem() {
try {
const response = await fetch('/api/get_config');
const config = await response.json();
RAZORPAY_KEY_ID = config.razorpayKeyId;
const notice = document.getElementById('modeNotice');
if (RAZORPAY_KEY_ID && RAZORPAY_KEY_ID.startsWith('rzp_test')) {
notice.innerText = "Test mode enabled. No real money will be deducted.";
} else if (RAZORPAY_KEY_ID) {
notice.innerText = "Secure Payment by Razorpay.";
} else {
notice.innerText = "Error: Payment system unavailable.";
document.getElementById('payBtn').disabled = true;
}
} catch (error) {
console.error('Config load failed', error);
}
}
initDonationSystem();
// 2. UI Event Listeners
const presetButtons = document.querySelectorAll('.amount-chip');
const amountInput = document.getElementById('donationAmount');
const noteInput = document.getElementById('donationNote');
const noteCount = document.getElementById('noteCount');
// Char counter
noteInput.addEventListener('input', () => {
noteCount.innerText = noteInput.value.length;
});
// Preset Amount Chips
presetButtons.forEach((button) => {
button.addEventListener('click', () => {
presetButtons.forEach((b) => b.classList.remove('active'));
button.classList.add('active');
// Data-amount is in paise, convert to INR for input
amountInput.value = Math.floor(Number(button.dataset.amount) / 100);
});
});
// 3. Helper Functions
function readFormData() {
const anonymousMode = document.getElementById('anonymousMode').checked;
return {
amountInInr: Number(amountInput.value),
donorName: document.getElementById('donorName').value.trim(),
donorEmail: document.getElementById('donorEmail').value.trim(),
donorPhone: document.getElementById('donorPhone').value.trim(),
donationPurpose: document.getElementById('donationPurpose').value,
donationNote: document.getElementById('donationNote').value.trim(),
anonymousMode
};
}
function showSuccessCard(form, paymentId) {
const card = document.getElementById('successCard');
document.getElementById('successLine1').innerText = `Payment ID: ${paymentId}`;
document.getElementById('successLine2').innerText = `Amount: ₹${form.amountInInr} • Purpose: ${form.donationPurpose}`;
card.style.display = 'block';
card.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
async function saveDonationToAdmin(form, response) {
// Send to secure API instead of direct Firebase Write
const payload = {
amount: form.amountInInr,
donorName: form.anonymousMode ? 'Anonymous' : form.donorName,
donorEmail: form.anonymousMode ? '' : form.donorEmail,
donorPhone: form.anonymousMode ? '' : form.donorPhone,
anonymous: form.anonymousMode,
purpose: form.donationPurpose,
donorNote: form.donationNote,
paymentId: response.razorpay_payment_id,
orderId: response.razorpay_order_id,
signature: response.razorpay_signature,
source: 'donate_page'
};
await fetch('/api/donations', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
}
// 4. Main Donation Logic
async function startDonation() {
if (!RAZORPAY_KEY_ID) {
await initDonationSystem();
if(!RAZORPAY_KEY_ID) {
alert("System Error: Could not load payment key. Please refresh.");
return;
}
}
const payBtn = document.getElementById('payBtn');
const form = readFormData();
// Validation
if (!form.amountInInr || form.amountInInr < 1) {
alert('Please enter a valid donation amount (minimum ₹1).');
return;
}
if (!form.anonymousMode && !form.donorName) {
alert('Please enter your name or choose anonymous mode.');
return;
}
// UI Feedback
payBtn.disabled = true;
payBtn.innerText = 'Opening Checkout...';
const amountInPaise = Math.round(form.amountInInr * 100);
const options = {
key: RAZORPAY_KEY_ID, // Uses variable from Env
amount: amountInPaise,
currency: 'INR',
name: 'Jachu Services',
description: `Donation - ${form.donationPurpose}`,
image: '/assets/logo.png', // Fallback to local or generic
prefill: {
name: form.anonymousMode ? '' : form.donorName,
email: form.anonymousMode ? '' : form.donorEmail,
contact: form.anonymousMode ? '' : form.donorPhone
},
notes: {
purpose: form.donationPurpose,
donor_note: form.donationNote || 'No note provided',
anonymous: String(form.anonymousMode)
},
theme: {
color: '#6366f1'
},
handler: async function (response) {
try {
payBtn.innerText = 'Processing...';
await saveDonationToAdmin(form, response);
} catch (error) {
console.error('Could not save donation', error);
}
showSuccessCard(form, response.razorpay_payment_id);
payBtn.disabled = false;
payBtn.innerText = 'Donate Again';
},
modal: {
ondismiss: function () {
payBtn.disabled = false;
payBtn.innerText = 'Donate with Razorpay';
}
}
};
const checkout = new Razorpay(options);
checkout.on('payment.failed', function (response) {
payBtn.disabled = false;
payBtn.innerText = 'Try Donation Again';
alert('Payment failed: ' + response.error.description);
});
checkout.open();
}
</script>
</body>
</html>