File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 3
3
4
4
from flask import Flask , render_template , request
5
5
6
- app = Flask (__name__ ,static_folder = "static" , static_url_path = '' )
6
+ app = Flask (__name__ , static_folder = "static" , static_url_path = '' )
7
7
razorpay_client = razorpay .Client (auth = ("<APP_ID>" , "<APP_SECRET>" ))
8
8
9
9
10
10
@app .route ('/' )
11
11
def app_create ():
12
- return render_template ('app.html' )
12
+ data = {
13
+ 'amount' : 5100 ,
14
+ 'currency' : 'INR' ,
15
+ 'receipt' : 'test receipt' ,
16
+ 'payment_capture' : 1 ,
17
+ 'notes' : {
18
+ 'key' : 'value'
19
+ }
20
+ }
21
+
22
+ order = razorpay_client .order .create (data )
23
+
24
+ order_id = order ['id' ]
25
+
26
+ return render_template ('app.html' , order_id = order_id , amount = data ['amount' ])
13
27
14
28
15
29
@app .route ('/charge' , methods = ['POST' ])
16
30
def app_charge ():
17
- amount = 5100
31
+ params_dict = dict (request .form .iteritems ())
32
+
33
+ try :
34
+ razorpay_client .utility .verify_payment_signature (params_dict )
35
+ except ValueError :
36
+ return json .dumps ('Signature Validatioon failed' )
37
+
18
38
payment_id = request .form ['razorpay_payment_id' ]
19
- razorpay_client . payment . capture ( payment_id , amount )
39
+
20
40
return json .dumps (razorpay_client .payment .fetch (payment_id ))
21
41
22
42
if __name__ == '__main__' :
Original file line number Diff line number Diff line change 6
6
< form action ="charge " method ="POST ">
7
7
< script
8
8
src ="https://checkout.razorpay.com/v1/checkout.js "
9
- data-key ="rzp_test_WyK93y9mvps7SN "
10
- data-amount ="5100 "
9
+ data-key ="rzp_test_1DP5mmOlF5G5ag "
10
+ data-amount ="{{amount}} "
11
11
data-name ="Daft Punk "
12
12
data-description ="Purchase Description "
13
13
data-image ="vk.jpg "
14
14
data-netbanking ="true "
15
15
data-description ="Tron Legacy "
16
16
data-prefill.name ="Harshil Mathur "
17
17
data-prefill.email ="
[email protected] "
18
- data-prefill.contact =" 9999999999 "
18
+ data-order_id =" {{order_id}} "
19
19
data-notes.shopping_order_id ="21 ">
20
20
</ script >
21
21
< input type ="hidden " name ="shopping_order_id " value ="21 ">
You can’t perform that action at this time.
0 commit comments