22import json
33
44# Default API endpoint
5- DECISION_ENGINE_API = "https://sandbox .juspay.io"
5+ DECISION_ENGINE_API = "https://integ .juspay.io"
66
77class DecisionEngineAPI :
88 """A class to interact with the Decision Engine API endpoints"""
9-
9+
1010 def __init__ (self , base_url = DECISION_ENGINE_API ):
1111 self .base_url = base_url
1212 self .headers = {
1313 "Content-Type" : "application/json"
1414 }
15-
15+
1616 def create_rule_success_rate (self , merchant_id = "test_merchant_123" ):
1717 """Create a success rate rule"""
1818 url = f"{ self .base_url } /rule/create"
@@ -36,7 +36,7 @@ def create_rule_success_rate(self, merchant_id="test_merchant_123"):
3636 }
3737 }
3838 }
39-
39+
4040 try :
4141 response = requests .post (url , headers = self .headers , json = payload )
4242 response .raise_for_status ()
@@ -47,7 +47,7 @@ def create_rule_success_rate(self, merchant_id="test_merchant_123"):
4747 if hasattr (e , 'response' ) and e .response is not None :
4848 print (f"Response: { e .response .text } " )
4949 return None
50-
50+
5151 def create_rule_elimination (self , merchant_id = "test_merchant_123" ):
5252 """Create an elimination rule"""
5353 url = f"{ self .base_url } /rule/create"
@@ -60,7 +60,7 @@ def create_rule_elimination(self, merchant_id="test_merchant_123"):
6060 }
6161 }
6262 }
63-
63+
6464 try :
6565 response = requests .post (url , headers = self .headers , json = payload )
6666 response .raise_for_status ()
@@ -71,7 +71,7 @@ def create_rule_elimination(self, merchant_id="test_merchant_123"):
7171 if hasattr (e , 'response' ) and e .response is not None :
7272 print (f"Response: { e .response .text } " )
7373 return None
74-
74+
7575 def create_rule_debit_routing (self , merchant_id = "test_merchant_123" ):
7676 """Create a debit routing rule"""
7777 url = f"{ self .base_url } /rule/create"
@@ -85,7 +85,7 @@ def create_rule_debit_routing(self, merchant_id="test_merchant_123"):
8585 }
8686 }
8787 }
88-
88+
8989 try :
9090 response = requests .post (url , headers = self .headers , json = payload )
9191 response .raise_for_status ()
@@ -96,15 +96,15 @@ def create_rule_debit_routing(self, merchant_id="test_merchant_123"):
9696 if hasattr (e , 'response' ) and e .response is not None :
9797 print (f"Response: { e .response .text } " )
9898 return None
99-
99+
100100 def get_rule (self , merchant_id = "test_merchant_123" , algorithm = "successRate" ):
101101 """Fetch a rule by merchant ID and algorithm"""
102102 url = f"{ self .base_url } /rule/get"
103103 payload = {
104104 "merchant_id" : merchant_id ,
105105 "algorithm" : algorithm
106106 }
107-
107+
108108 try :
109109 response = requests .post (url , headers = self .headers , json = payload )
110110 response .raise_for_status ()
@@ -115,7 +115,7 @@ def get_rule(self, merchant_id="test_merchant_123", algorithm="successRate"):
115115 if hasattr (e , 'response' ) and e .response is not None :
116116 print (f"Response: { e .response .text } " )
117117 return None
118-
118+
119119 def update_rule_debit_routing (self , merchant_id = "test_merchant_123" ):
120120 """Update a debit routing rule"""
121121 url = f"{ self .base_url } /rule/update"
@@ -129,7 +129,7 @@ def update_rule_debit_routing(self, merchant_id="test_merchant_123"):
129129 }
130130 }
131131 }
132-
132+
133133 try :
134134 response = requests .post (url , headers = self .headers , json = payload )
135135 response .raise_for_status ()
@@ -140,15 +140,15 @@ def update_rule_debit_routing(self, merchant_id="test_merchant_123"):
140140 if hasattr (e , 'response' ) and e .response is not None :
141141 print (f"Response: { e .response .text } " )
142142 return None
143-
143+
144144 def delete_rule (self , merchant_id = "test_merchant_123" , algorithm = "successRate" ):
145145 """Delete a rule by merchant ID and algorithm"""
146146 url = f"{ self .base_url } /rule/delete"
147147 payload = {
148148 "merchant_id" : merchant_id ,
149149 "algorithm" : algorithm
150150 }
151-
151+
152152 try :
153153 response = requests .post (url , headers = self .headers , json = payload )
154154 response .raise_for_status ()
@@ -159,14 +159,14 @@ def delete_rule(self, merchant_id="test_merchant_123", algorithm="successRate"):
159159 if hasattr (e , 'response' ) and e .response is not None :
160160 print (f"Response: { e .response .text } " )
161161 return None
162-
162+
163163 def create_merchant_account (self , merchant_id = "test_merchant_123" ):
164164 """Create a merchant account"""
165165 url = f"{ self .base_url } /merchant-account/create"
166166 payload = {
167167 "merchant_id" : merchant_id
168168 }
169-
169+
170170 try :
171171 response = requests .post (url , headers = self .headers , json = payload )
172172 response .raise_for_status ()
@@ -177,11 +177,11 @@ def create_merchant_account(self, merchant_id="test_merchant_123"):
177177 if hasattr (e , 'response' ) and e .response is not None :
178178 print (f"Response: { e .response .text } " )
179179 return None
180-
180+
181181 def get_merchant_account (self , merchant_id = "test_merchant_123" ):
182182 """Fetch a merchant account by ID"""
183183 url = f"{ self .base_url } /merchant-account/{ merchant_id } "
184-
184+
185185 try :
186186 response = requests .get (url , headers = self .headers )
187187 response .raise_for_status ()
@@ -192,11 +192,11 @@ def get_merchant_account(self, merchant_id="test_merchant_123"):
192192 if hasattr (e , 'response' ) and e .response is not None :
193193 print (f"Response: { e .response .text } " )
194194 return None
195-
195+
196196 def delete_merchant_account (self , merchant_id = "test_merchant_123" ):
197197 """Delete a merchant account by ID"""
198198 url = f"{ self .base_url } /merchant-account/{ merchant_id } "
199-
199+
200200 try :
201201 response = requests .delete (url , headers = self .headers )
202202 response .raise_for_status ()
@@ -213,71 +213,71 @@ def test_decision_engine_endpoints():
213213 """Test all the Decision Engine API endpoints"""
214214 print ("\n 🔍 Testing Decision Engine API Endpoints" )
215215 print ("---------------------------------------" )
216-
216+
217217 # Initialize API client
218218 de_api = DecisionEngineAPI ()
219219 merchant_id = "test_merchant_123"
220-
220+
221221 # Test merchant account operations
222222 print ("\n 📋 Testing Merchant Account Operations..." )
223-
223+
224224 # Create merchant account
225225 print ("\n ▶️ Creating merchant account..." )
226226 create_result = de_api .create_merchant_account (merchant_id )
227227 if create_result :
228228 print (f"Create merchant result: { json .dumps (create_result , indent = 2 )} " )
229-
229+
230230 # Get merchant account
231231 print ("\n ▶️ Fetching merchant account..." )
232232 account_result = de_api .get_merchant_account (merchant_id )
233233 if account_result :
234234 print (f"Merchant account: { json .dumps (account_result , indent = 2 )} " )
235-
235+
236236 # Test rule operations
237237 print ("\n 📋 Testing Rule Operations..." )
238-
238+
239239 # Create success rate rule
240240 print ("\n ▶️ Creating success rate rule..." )
241241 sr_result = de_api .create_rule_success_rate (merchant_id )
242242 if sr_result :
243243 print (f"Success rate rule created: { json .dumps (sr_result , indent = 2 )} " )
244-
244+
245245 # Create elimination rule
246246 print ("\n ▶️ Creating elimination rule..." )
247247 elim_result = de_api .create_rule_elimination (merchant_id )
248248 if elim_result :
249249 print (f"Elimination rule created: { json .dumps (elim_result , indent = 2 )} " )
250-
250+
251251 # Create debit routing rule
252252 print ("\n ▶️ Creating debit routing rule..." )
253253 dr_result = de_api .create_rule_debit_routing (merchant_id )
254254 if dr_result :
255255 print (f"Debit routing rule created: { json .dumps (dr_result , indent = 2 )} " )
256-
256+
257257 # Get rules
258258 print ("\n ▶️ Fetching success rate rule..." )
259259 get_sr_result = de_api .get_rule (merchant_id , "successRate" )
260260 if get_sr_result :
261261 print (f"Success rate rule: { json .dumps (get_sr_result , indent = 2 )} " )
262-
262+
263263 # Update debit routing rule
264264 print ("\n ▶️ Updating debit routing rule..." )
265265 update_dr_result = de_api .update_rule_debit_routing (merchant_id )
266266 if update_dr_result :
267267 print (f"Updated debit routing rule: { json .dumps (update_dr_result , indent = 2 )} " )
268-
268+
269269 # Delete success rate rule
270270 print ("\n ▶️ Deleting success rate rule..." )
271271 delete_sr_result = de_api .delete_rule (merchant_id , "successRate" )
272272 if delete_sr_result :
273273 print (f"Success rate rule deletion result: { json .dumps (delete_sr_result , indent = 2 )} " )
274-
274+
275275 # Delete merchant account
276276 print ("\n ▶️ Deleting merchant account..." )
277277 delete_result = de_api .delete_merchant_account (merchant_id )
278278 if delete_result :
279279 print (f"Delete merchant result: { json .dumps (delete_result , indent = 2 )} " )
280-
280+
281281 print ("\n ✅ Decision Engine API Testing completed!" )
282282
283283
0 commit comments