1
- document . getElementById ( "button_text" ) . onclick = function ( e ) {
2
- var url = "https://api.linux-diary.wcewlug.org/api/payment/order"
3
- var params = {
4
- amount : 100 ,
5
- currency : "INR" ,
6
- receipt : "linuxDiary3.0" ,
7
- payment_capture : '1'
8
- } ;
9
-
10
- var xmlHttp = new XMLHttpRequest ( ) ;
11
-
12
- xmlHttp . onreadystatechange = function ( res ) {
13
- if ( xmlHttp . readyState === 4 ) {
14
- res = JSON . parse ( xmlHttp . responseText ) ;
15
- document . getElementById ( "rzp-text" ) . value = res . sub . id ;
16
- alert ( res . sub . id ) ;
17
- rzpClick ( e ) ;
1
+ var referral = "" ;
2
+ document . getElementById ( "button_text" ) . onclick = function ( e ) {
3
+
4
+ var name = document . getElementById ( 'firstName' ) . value ;
5
+ referral = document . getElementById ( 'referral' ) . value ;
6
+ var email = document . getElementById ( 'email' ) . value ;
7
+ var college = document . getElementById ( 'collegeName' ) . value ;
8
+ var transaction = document . getElementById ( 'transactionId' ) . value ;
9
+
10
+ if ( name == undefined || name == "" ) {
11
+ alert ( "Please Enter Your Name !!!" ) ;
12
+ return ;
13
+ }
14
+
15
+ if ( email == undefined || email == "" ) {
16
+ alert ( "Please Enter Your Email !!!" ) ;
17
+ return ;
18
+ }
19
+
20
+ var filter = / ^ ( [ a - z A - Z 0 - 9 _ \. \- ] ) + \@ ( ( [ a - z A - Z 0 - 9 \- ] ) + \. ) + ( [ a - z A - Z 0 - 9 ] { 2 , 4 } ) + $ / ;
21
+
22
+ if ( ! filter . test ( email ) )
23
+ {
24
+ alert ( "You have entered an invalid email address !!!" )
25
+ return ;
26
+ }
27
+
28
+ if ( college == undefined || college == "" ) {
29
+ alert ( "Please Enter Your College Name !!!" ) ;
30
+ return ;
31
+ }
32
+
33
+ if ( transaction == undefined || transaction == "" ) {
34
+ alert ( "Please Enter Your Transaction ID !!!" ) ;
35
+ return ;
36
+ }
37
+
38
+ var url2 = "http://localhost:3000/api/payment/findUser"
39
+ var params2 = {
40
+ email : email
41
+ } ;
42
+ var xmlHttp2 = new XMLHttpRequest ( ) ;
43
+ var flag = true ;
44
+ xmlHttp2 . onreadystatechange = function ( res ) {
45
+ if ( xmlHttp2 . readyState === 4 ) {
46
+ res = JSON . parse ( xmlHttp2 . responseText ) ;
47
+ if ( res . status === "failed" ) {
48
+ alert ( "Email Already Registered !!!" ) ;
49
+ flag = false ;
50
+ return ;
51
+ }
52
+ }
53
+ }
54
+ xmlHttp2 . open ( "POST" , url2 , true ) ;
55
+ xmlHttp2 . setRequestHeader ( "Content-type" , "application/json" ) ;
56
+ xmlHttp2 . send ( JSON . stringify ( params2 ) ) ;
57
+
58
+ var url3 = "http://localhost:3000/api/payment/findUser2"
59
+ var params3 = {
60
+ transaction : transaction
61
+ } ;
62
+ var xmlHttp3 = new XMLHttpRequest ( ) ;
63
+ var flag = true ;
64
+ xmlHttp3 . onreadystatechange = function ( res ) {
65
+ if ( xmlHttp2 . readyState === 4 ) {
66
+
67
+ if ( flag === false ) return ;
68
+
69
+ res = JSON . parse ( xmlHttp3 . responseText ) ;
70
+ if ( res . status === "failed" ) {
71
+ alert ( "Transaction ID Already Registered !!!" ) ;
72
+ flag = false ;
73
+ return ;
74
+ }
75
+ register ( e ) ;
76
+ }
18
77
}
78
+ xmlHttp3 . open ( "POST" , url3 , true ) ;
79
+ xmlHttp3 . setRequestHeader ( "Content-type" , "application/json" ) ;
80
+ xmlHttp3 . send ( JSON . stringify ( params3 ) ) ;
81
+
19
82
}
20
- xmlHttp . open ( "POST" , url , true ) ;
21
- xmlHttp . setRequestHeader ( "Content-type" , "application/json" ) ;
22
- xmlHttp . send ( JSON . stringify ( params ) ) ;
23
- }
24
-
25
- function rzpClick ( e ) {
26
- var options = {
27
- "key" : "rzp_live_7Qavb1VhFIUu1u" ,
28
- "currency" : "INR" ,
29
- "name" : "LinuxDiary 3.0" ,
30
- "description" : "WLUG Linux Diary 3.0 Registration" ,
31
- "order_id" : document . getElementById ( "rzp-text" ) . value ,
32
- "handler" : function ( response ) {
33
- document . getElementById ( 'order-pay-id' ) . value = response . razorpay_payment_id ;
34
- document . getElementById ( 'order-id' ) . value = response . razorpay_order_id ;
35
- document . getElementById ( 'order-sig' ) . value = response . razorpay_signature ;
36
- verifyClick ( ) ;
37
- } ,
38
- "theme" : {
39
- "color" : "#0EB9F2"
83
+
84
+
85
+ var count = 0 ;
86
+ function incrementReferral ( e ) {
87
+
88
+ if ( referral != undefined && referral != "" ) {
89
+ var url2 = "http://localhost:3000/api/payment/incrementReferral"
90
+ var params2 = {
91
+ referralCode : referral
92
+ } ;
93
+ var xmlHttp2 = new XMLHttpRequest ( ) ;
94
+ var flag = true ;
95
+ xmlHttp2 . onreadystatechange = function ( res ) {
96
+ if ( xmlHttp2 . readyState === 4 ) {
97
+ res = JSON . parse ( xmlHttp2 . responseText ) ;
98
+ }
40
99
}
41
- } ;
42
- var rzp1 = new Razorpay ( options ) ;
43
- rzp1 . open ( ) ;
44
- e . preventDefault ( ) ;
45
- }
100
+ xmlHttp2 . open ( "POST" , url2 , true ) ;
101
+ xmlHttp2 . setRequestHeader ( "Content-type" , "application/json" ) ;
102
+ xmlHttp2 . send ( JSON . stringify ( params2 ) ) ;
103
+ }
104
+ }
46
105
47
- function register ( e ) {
106
+ function register ( e ) {
48
107
49
- const name = document . getElementById ( "firstName" ) . value ;
108
+ if ( count >= 1 ) return ;
109
+ count ++ ;
50
110
51
- const username = document . getElementById ( "userName " ) . value ;
111
+ const name = document . getElementById ( "firstName " ) . value ;
52
112
53
- const referralCode = document . getElementById ( "referralCode " ) . value ;
113
+ const email = document . getElementById ( "email " ) . value ;
54
114
55
- const email = document . getElementById ( "email " ) . value ;
115
+ const college = document . getElementById ( "collegeName " ) . value ;
56
116
57
- const college = document . getElementById ( "collegeName " ) . value ;
117
+ const transaction = document . getElementById ( "transactionId " ) . value ;
58
118
59
- var url = 'https ://api.linux-diary.wcewlug.org /api/payment/register' ;
119
+ var url = 'http ://localhost:3000 /api/payment/register' ;
60
120
61
- var params = {
62
- name : name ,
63
- username : username ,
64
- referralCode : referralCode ,
65
- email : email ,
66
- college : college
67
- }
121
+ var params = {
122
+ name : name ,
123
+ email : email ,
124
+ college : college ,
125
+ transaction : transaction
126
+ }
68
127
69
- try {
70
- var xmlHttp = new XMLHttpRequest ( ) ;
71
- xmlHttp . onreadystatechange = function ( res ) {
128
+ try {
129
+ var xmlHttp = new XMLHttpRequest ( ) ;
130
+ xmlHttp . onreadystatechange = function ( res ) {
72
131
if ( xmlHttp . readyState === 4 ) {
73
- alert ( "Registration Successful !!! Kindly Check Your Mail For Payment Confirmation !!!" ) ;
132
+ res = JSON . parse ( xmlHttp . responseText ) ;
133
+ if ( res . error === "true" || res . emailSent === "false" ) {
134
+ if ( res . error === "true" ) alert ( "User Registration Failed !!!" ) ;
135
+ else alert ( "Invalid Email ID !!!" ) ;
136
+ return ;
137
+ }
138
+ incrementReferral ( e ) ;
139
+ alert ( "Registration Successful !!! Kindly Check Your Mail For Payment Confirmation !!!" ) ;
140
+ var obj = document . getElementById ( 'successBox' ) ;
141
+ var newContent = "<div style='display: flex; justify-content: center;'><p style='color: white;'>Registration Successfull !!!</p></div></br></br></br></br><p style='color: white;'> Your Referral Code : <strong>" + res . referralCode + "</strong></p>" + "<br/></br></br><p style='color: white;'>Confirmation Mail has been sent to you, Thanks For Registration !!!</p></br></br><p style='color: white;'>In case if you have any queries or doubts, feel free to contact us.</p></br></br></br></br><p style='color: white;'>Regards,</br>Walchand Linux User's Group</p>" ;
142
+ obj . innerHTML = newContent ;
74
143
}
75
144
}
76
145
xmlHttp . open ( "POST" , url , true ) ; // false for synchronous request
77
146
xmlHttp . setRequestHeader ( "Content-type" , "application/json" ) ;
78
147
xmlHttp . send ( JSON . stringify ( params ) ) ;
79
- } catch ( e ) {
80
- alert ( e . message ) ;
81
- console . log ( e . message ) ;
82
- }
83
-
148
+ } catch ( e ) {
149
+ alert ( e . message ) ;
150
+ console . log ( e . message ) ;
151
+ }
84
152
85
- }
86
153
87
- function verifyClick ( e ) {
88
- var url = 'https://api.linux-diary.wcewlug.org/api/payment/verify' ;
89
- var params = {
90
- razorpay_order_id : document . getElementById ( 'order-id' ) . value ,
91
- razorpay_payment_id : document . getElementById ( 'order-pay-id' ) . value ,
92
- razorpay_signature : document . getElementById ( 'order-sig' ) . value
93
- } ;
94
- var xmlHttp = new XMLHttpRequest ( ) ;
95
- xmlHttp . onreadystatechange = function ( res ) {
96
- if ( xmlHttp . readyState === 4 ) {
97
- register ( e ) ;
98
- }
99
- }
100
- xmlHttp . open ( "POST" , url , true ) ; // false for synchronous request
101
- xmlHttp . setRequestHeader ( "Content-type" , "application/json" ) ;
102
- xmlHttp . send ( JSON . stringify ( params ) ) ;
103
- }
154
+ }
0 commit comments