11<!doctype html>
22< html lang ="en ">
3- < head >
4- < meta charset ="UTF-8 " />
5- < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6- < title > Document</ title >
7- </ head >
8- < script src ="https://cdn.tailwindcss.com "> </ script >
93
10- < body >
11- < div class ="m-12 ">
12- < button
13- id ="createOrder "
14- class ="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded "
15- >
16- Create Order
17- </ button >
18- < button
19- id ="rzp-button1 "
20- class ="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded hidden "
21- >
22- Pay with Razorpay
23- </ button >
24- </ div >
4+ < head >
5+ < meta charset ="UTF-8 " />
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7+ < title > Document</ title >
8+ </ head >
9+ < script src ="https://cdn.tailwindcss.com "> </ script >
2510
26- < script src ="https://checkout.razorpay.com/v1/checkout.js "> </ script >
27- < script >
28- let data = null ;
29- document
30- . getElementById ( 'createOrder' )
31- . addEventListener ( 'click' , async function postData ( e ) {
32- const baseUrl = 'http://localhost:3000/orders/create' ;
11+ < body >
12+ < div class ="m-12 ">
13+ < button id ="createOrder " class ="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded ">
14+ Create Order
15+ </ button >
16+ < button id ="rzp-button1 " class ="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded hidden ">
17+ Pay with Razorpay
18+ </ button >
19+ </ div >
3320
34- try {
35- const response = await fetch ( baseUrl , {
36- method : 'POST' ,
37- headers : {
38- accept : 'application/json' ,
39- 'Content-Type' : 'application/json' ,
40- } ,
41- credentials : 'include' ,
42- body : JSON . stringify ( {
43- amount : 200 ,
44- currency : 'INR' ,
45- receipt : 'receipt-hello' ,
46- } ) ,
47- } ) ;
21+ < script src ="https://checkout.razorpay.com/v1/checkout.js "> </ script >
22+ < script >
23+ let data = null ;
24+ document
25+ . getElementById ( 'createOrder' )
26+ . addEventListener ( 'click' , async function postData ( e ) {
27+ const baseUrl = 'https://api.flux.codegasms.com/orders/create' ;
28+
29+ try {
30+ const response = await fetch ( baseUrl , {
31+ method : 'POST' ,
32+ headers : {
33+ accept : 'application/json' ,
34+ 'Content-Type' : 'application/json' ,
35+ } ,
36+ credentials : 'include' ,
37+ body : JSON . stringify ( {
38+ amount : 200 ,
39+ currency : 'INR' ,
40+ receipt : 'receipt-hello' ,
41+ } ) ,
42+ } ) ;
43+ console . log ( response . status ) ;
44+ if ( ! response . ok ) {
4845 console . log ( response . status ) ;
49- if ( ! response . ok ) {
50- console . log ( response . status ) ;
51- console . log ( response . statusText ) ;
52- alert ( 'Could not create order! Make sure setup is correct' ) ;
53- } else {
54- data = await response . json ( ) ;
55- console . log ( data ) ;
56- console . log ( 'end of flow' ) ;
57- }
58- // console.log(response.body);
59- } catch ( err ) {
60- console . log ( 'error happened' ) ;
61- console . log ( err ) ;
62- if ( err ?. response ) {
63- console . log ( await err . response . json ( ) ) ;
64- }
46+ console . log ( response . statusText ) ;
47+ alert ( 'Could not create order! Make sure setup is correct' ) ;
48+ } else {
49+ data = await response . json ( ) ;
50+ console . log ( data ) ;
51+ console . log ( 'end of flow' ) ;
6552 }
66- alert (
67- `Order created: id: ${ data . order . id } . Click on Pay with Razorpay`
68- ) ;
69- if ( data != null ) {
70- document . getElementById ( 'rzp-button1' ) . classList . remove ( 'hidden' ) ;
71- document . getElementById ( 'createOrder' ) . classList . add ( 'hidden' ) ;
53+ // console.log(response.body);
54+ } catch ( err ) {
55+ console . log ( 'error happened' ) ;
56+ console . log ( err ) ;
57+ if ( err ?. response ) {
58+ console . log ( await err . response . json ( ) ) ;
7259 }
73- var options = {
74- key : data . key ,
75- amount : data . order . amount ,
76- // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
77- currency : data . order . currency ,
78- name : 'Flux@Codegasms' ,
79- description : 'Get your orgasms here!' ,
80- image : 'https://i.ibb.co/ZJG2pG2/download-7.jpg' ,
81- order_id : data . order . id ,
82- callback_url : `http://localhost:3000/${ data . verifyUrl } ?frontendBase=http://localhost:5501&successRedirect=/success&failureRedirect=/failure` ,
60+ }
61+ alert (
62+ `Order created: id: ${ data . order . id } . Click on Pay with Razorpay`
63+ ) ;
64+ if ( data != null ) {
65+ document . getElementById ( 'rzp-button1' ) . classList . remove ( 'hidden' ) ;
66+ document . getElementById ( 'createOrder' ) . classList . add ( 'hidden' ) ;
67+ }
68+ var options = {
69+ key : data . key ,
70+ amount : data . order . amount ,
71+ // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
72+ currency : data . order . currency ,
73+ name : 'Flux@Codegasms' ,
74+ description : 'Get your orgasms here!' ,
75+ image : 'https://i.ibb.co/ZJG2pG2/download-7.jpg' ,
76+ order_id : data . order . id ,
77+ callback_url : `https://api.flux.codegasms.com/${ data . verifyUrl } ?frontendBase=http://localhost:5501&successRedirect=/success&failureRedirect=/failure` ,
8378
84- notes : {
85- 'custom-data' : 'data' ,
86- } ,
87- theme : {
88- color : '#3399cc' ,
89- } ,
90- } ;
91- if ( data . prefill ) {
92- options [ 'prefill' ] = data . prefill ;
93- }
79+ notes : {
80+ 'custom-data' : 'data' ,
81+ } ,
82+ theme : {
83+ color : '#3399cc' ,
84+ } ,
85+ } ;
86+ if ( data . prefill ) {
87+ options [ 'prefill' ] = data . prefill ;
88+ }
89+
90+ var rzp1 = new Razorpay ( options ) ;
91+ document . getElementById ( 'rzp-button1' ) . onclick = function ( e ) {
92+ rzp1 . open ( ) ;
93+ e . preventDefault ( ) ;
94+ } ;
95+ } ) ;
96+ console . log ( data ) ;
97+ </ script >
98+ </ body >
9499
95- var rzp1 = new Razorpay ( options ) ;
96- document . getElementById ( 'rzp-button1' ) . onclick = function ( e ) {
97- rzp1 . open ( ) ;
98- e . preventDefault ( ) ;
99- } ;
100- } ) ;
101- console . log ( data ) ;
102- </ script >
103- </ body >
104- </ html >
100+ </ html >
0 commit comments