@@ -15,12 +15,22 @@ class Prod:
1515
1616class Deeplink :
1717
18- def __init__ (self , schemeId , secret , productInstance , mode = "SANDBOX" ):
18+ def __init__ (self , schemeId , secret , productInstance , authType = "JWT" , mode = "SANDBOX" ):
1919 self .schemeId = schemeId
2020 self .secret = secret
2121 self .productInstance = productInstance
2222 self .url = URLS .Sandbox .url if mode != "PRODUCTION" else URLS .Prod .url
2323 self .mode = mode
24+ self .authType = authType
25+
26+
27+ if self .authType != 'JWT' :
28+ # Generate required headers
29+ self .headers = generate_setu_headers (
30+ self .schemeId , self .secret , self .productInstance , self .url , self .authType
31+ )
32+ # Set the url to v2
33+ self .url = self .url + '/v2'
2434
2535 # Generate UPI payment link method
2636 def create_payment_link (
@@ -60,14 +70,15 @@ def create_payment_link(
6070 if validationRules is not None :
6171 payload .update ({"validationRules" : validationRules })
6272
63- # Generate required headers
64- headers = generate_setu_headers (
65- self .schemeId , self .secret , self .productInstance
66- )
73+ # In case of JWT the token expires often enough to warrant creation of new tokens
74+ if self .authType == 'JWT' :
75+ self .headers = generate_setu_headers (
76+ self .schemeId , self .secret , self .productInstance , self .url , self .authType
77+ )
6778
6879 # Call API with required parameters
6980 response = requests .post (
70- self .url + path , json = payload , headers = headers
81+ self .url + path , json = payload , headers = self . headers
7182 )
7283
7384 # Handle errors
@@ -81,15 +92,16 @@ def check_payment_status(
8192 platformBillID
8293 ):
8394 path = "/payment-links/{}" .format (platformBillID )
84-
85- # Generate required headers
86- headers = generate_setu_headers (
87- self .schemeId , self .secret , self .productInstance
88- )
95+
96+ # In case of JWT the token expires often enough to warrant creation of new tokens
97+ if self .authType == 'JWT' :
98+ self .headers = generate_setu_headers (
99+ self .schemeId , self .secret , self .productInstance , self .url , self .authType
100+ )
89101
90102 # Call API with required parameters
91103 response = requests .get (
92- self .url + path , headers = headers
104+ self .url + path , headers = self . headers
93105 )
94106
95107 return response .json ()
@@ -115,14 +127,15 @@ def trigger_mock_payment(self, amountValue, upiID):
115127 "type" : "UPI" ,
116128 }
117129
118- # Generate required headers
119- headers = generate_setu_headers (
120- self .schemeId , self .secret , self .productInstance
121- )
130+ # In case of JWT the token expires often enough to warrant creation of new tokens
131+ if self .authType == 'JWT' :
132+ self .headers = generate_setu_headers (
133+ self .schemeId , self .secret , self .productInstance , self .url , self .authType
134+ )
122135
123136 # Call API with required parameters
124137 response = requests .post (
125- self .url + path , json = payload , headers = headers
138+ self .url + path , json = payload , headers = self . headers
126139 )
127140
128141 return response
0 commit comments