You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.2 KiB

6 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <header>
  3. <script src="https://checkout.razorpay.com/v1/checkout.js"></script>
  4. <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  5. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  6. <script type="text/javascript">
  7. const paymentStart=(id,amount,isBulk)=>{
  8. console.log("payment started" + id);
  9. console.log("payment isBulk started" + isBulk);
  10. amount = Number(amount);
  11. console.log("amount==>" + amount);
  12. if (amount === 0) {
  13. const freeOrderId = "ord-" + Date.now();
  14. const freePaymentId = "pay-" + Date.now();
  15. Swal.fire({
  16. title: "Free Entry",
  17. text: "This category is free of cost. Confirming booking...",
  18. icon: "info",
  19. allowOutsideClick: false,
  20. didOpen: () => Swal.showLoading()
  21. });
  22. updatePaymentInServer(
  23. freePaymentId,
  24. freeOrderId,
  25. id,
  26. amount,
  27. isBulk
  28. );
  29. return;
  30. }
  31. $.ajax({
  32. url:'/victoriapublichall/bookingapi/create_order',
  33. data:JSON.stringify({amount:amount,info:'order_request',id:id,isBulk:isBulk}),
  34. contentType:'application/json',
  35. type:'POST',
  36. dataType:'json',
  37. success:function(response){
  38. let amt = response.amount;
  39. let refid = id;
  40. console.log("refid")
  41. console.log("FIRST:==>");
  42. console.log(response);
  43. if(response.status=="created"){
  44. let options = {
  45. /* "key": "[[${keyId}]]", */
  46. "key": "rzp_test_tDkHFEqWXmuEi8",
  47. // "key":"rzp_live_ySI5Ns54Y7qOcJ",
  48. "amount": response.amount, // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
  49. "currency": response.currency,
  50. "name": "Greater Chennai Corporation",
  51. "description": "Victoria public Hall Booking Transaction",
  52. "image": "https://upload.wikimedia.org/wikipedia/commons/a/a8/Chennai_Corporation_Emblem.png",
  53. "order_id": response.id, //This is a sample Order ID. Pass the `id` obtained in the response of Step 1
  54. "handler": function (response){
  55. console.log("second==>\n");
  56. console.log(response);
  57. console.log(response.razorpay_payment_id);
  58. console.log(response.razorpay_order_id);
  59. console.log(response.razorpay_signature);
  60. console.log("payment success");
  61. //alert("congrates !payment successfull")
  62. updatePaymentInServer(response.razorpay_payment_id,response.razorpay_order_id,refid,amt,isBulk);
  63. },
  64. modal: {
  65. ondismiss: function () {
  66. console.log("Razorpay popup closed by user");
  67. const loader = document.getElementById("pageLoader");
  68. if (loader) {
  69. loader.style.display = "block";
  70. }
  71. // small delay so loader is visible
  72. setTimeout(() => {
  73. // REDIRECT BACK TO BOOKING PAGE
  74. window.location.replace("/victoriapublichall/register");
  75. }, 300);
  76. }
  77. },
  78. "prefill": {
  79. "name": "",
  80. "email": "",
  81. "contact": ""
  82. },
  83. "notes": {
  84. "address": "Greater Chennai Corporation."
  85. },
  86. "theme": {
  87. "color": "#3399cc"
  88. }
  89. };
  90. var rzp1 = new Razorpay(options);
  91. rzp1.on('payment.failed', function (response){
  92. console.log(response.error.code);
  93. console.log(response.error.description);
  94. console.log(response.error.source);
  95. console.log(response.error.step);
  96. console.log(response.error.reason);
  97. console.log(response.error.metadata.order_id);
  98. console.log(response.error.metadata.payment_id);
  99. alert("Payment Failed");
  100. });
  101. rzp1.open();
  102. }
  103. },
  104. error:function(error){
  105. console.log(error);
  106. alert("error");
  107. }
  108. })
  109. };
  110. function updatePaymentInServer(payment_id,order_id,refid,amt,isbulk){
  111. console.log("amt...",amt);
  112. let mobile_no = "";
  113. if (isbulk === 1 || isbulk === true) {
  114. mobile_no = $("#paymentNumber").val()?.trim() ;
  115. } else {
  116. mobile_no = $("#contactDisplay").text()?.trim() ;
  117. }
  118. console.log("mobile_no==>", mobile_no);
  119. $.ajax({
  120. url:'/victoriapublichall/bookingapi/Confirm',
  121. data:JSON.stringify({payment_id:payment_id,order_id:order_id,id:refid,amt:amt,mobile_no: mobile_no,isBulk:isbulk}),
  122. contentType:'application/json',
  123. type:'POST',
  124. dataType:'text',
  125. success:function(response){
  126. console.log("update payment in server");
  127. console.log("order_id...",order_id);
  128. window.location.href = "/victoriapublichall/bookingQRCode?orderid=" +order_id;
  129. },
  130. error:function(error){
  131. swal("Failed`!", "Failed to confirm your booking. If payment was debited, it will be credited back, or you can check with your bank.", "error");
  132. }
  133. });
  134. };
  135. </script>
  136. </header>
  137. </html>