krsyer-server-monitor-pro 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -269,7 +269,11 @@
269
269
  mode: "production"
270
270
  });
271
271
 
272
+ let isSubmitting = false;
273
+
272
274
  document.getElementById('buyBtn').addEventListener('click', async () => {
275
+ if (isSubmitting) return;
276
+
273
277
  const email = document.getElementById('email').value;
274
278
  const phone = document.getElementById('phone').value;
275
279
  const btn = document.getElementById('buyBtn');
@@ -279,46 +283,39 @@
279
283
  return;
280
284
  }
281
285
 
286
+ isSubmitting = true;
282
287
  btn.innerHTML = '<span class="loader-spinner"></span> Processing...';
283
288
  btn.disabled = true;
284
289
 
290
+ const emailVal = document.getElementById('email').value;
291
+ const phoneVal = document.getElementById('phone').value;
292
+
285
293
  try {
286
294
  // Create Order
287
295
  const res = await fetch('/api/buy', {
288
296
  method: 'POST',
289
297
  headers: { 'Content-Type': 'application/json' },
290
- body: JSON.stringify({ email, phone })
298
+ body: JSON.stringify({ email: emailVal, phone: phoneVal })
291
299
  });
300
+
301
+ if (!res.ok) {
302
+ const errData = await res.json().catch(() => ({}));
303
+ throw new Error(errData.message || errData.error || `Server Error ${res.status}`);
304
+ }
305
+
292
306
  const data = await res.json();
293
307
 
294
308
  if (data.payment_session_id) {
295
- // Redirect to Payment
296
- const email = document.getElementById('email').value;
297
- const phone = document.getElementById('phone').value;
298
-
299
- cashfree.checkout({
300
- paymentSessionId: data.payment_session_id
301
- }).then(() => {
302
- console.log("Checkout initiated");
303
- });
304
-
305
- cashfree.on("payment.success", (data) => {
306
- // Pass email/phone to verify route
307
- window.location.href = `/verify?order_id=${data.orderId}&email=${encodeURIComponent(email)}&phone=${encodeURIComponent(phone)}`;
308
- });
309
-
310
- cashfree.on("payment.failed", (data) => {
311
- alert("Payment Failed: " + data.message);
312
- });
309
+ const cf = new Cashfree(data.payment_session_id);
310
+ cf.redirect();
313
311
  } else {
314
- alert('Error creating order');
315
- btn.innerText = 'Buy License Now';
316
- btn.disabled = false;
312
+ throw new Error(data.message || 'No payment session ID returned');
317
313
  }
318
314
  } catch (e) {
319
315
  console.error(e);
320
- alert('Connection Error');
321
- btn.innerText = 'Buy License Now';
316
+ alert('Connection Error: ' + e.message + '. Ensure server is running on port 3011 and you are accessing via http://localhost:3011');
317
+ isSubmitting = false;
318
+ btn.innerHTML = 'Buy License Now';
322
319
  btn.disabled = false;
323
320
  }
324
321
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "krsyer-server-monitor-pro",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "API to get server details like IP address, health, applications running, etc.",
5
5
  "main": "lib/server.js",
6
6
  "bin": {