@@ -13,68 +13,104 @@ class Prod:
1313
1414
1515class Deeplink :
16+
1617 def __init__ (self , schemeId , secret , productInstance , production = False ):
1718 self .schemeId = schemeId
1819 self .secret = secret
1920 self .productInstance = productInstance
2021 self .url = URLS .Sandbox .url if not production else URLS .Prod .url
2122
22- def generate_link (self , amount , expiresInDays , payeeName , refId , exactness = "EXACT" ):
23- expiryDate = datetime .datetime .now () + datetime .timedelta (days = expiresInDays )
23+ def createPaymentLink (
24+ self ,
25+ amountValue ,
26+ billerBillID ,
27+ amountExactness ,
28+ dueDate ,
29+ expiryDate ,
30+ payeeName ,
31+ settlement ,
32+ validationRules
33+ ):
34+
2435 path = "/payment-links"
2536 payload = {
26- "amount" : {"currencyCode" : "INR" , "value" : amount },
27- "amountExactness" : exactness ,
28- "billerBillID" : refId ,
29- "dueDate" : "{}Z" .format (expiryDate .isoformat ("T" )),
30- "expiryDate" : "{}Z" .format (expiryDate .isoformat ("T" )),
37+ "amount" : {
38+ "currencyCode" : "INR" ,
39+ "value" : amountValue
40+ },
41+ "amountExactness" : amountExactness ,
42+ "billerBillID" : billerBillID ,
3143 "name" : payeeName ,
44+ "dueDate" : dueDate ,
45+ "expiryDate" : expiryDate
3246 }
3347
34- if exactness == "EXACT_UP" :
48+ if settlement :
49+ payload .update ({"settlement" : settlement })
50+
51+ if validationRules :
52+ payload .update ({"validationRules" : validationRules })
53+
54+ if amountExactness == "EXACT_UP" :
3555 payload ["validationRules" ] = {
36- "amount" : {"maximum" : 0 , "minimum" : amount }}
37- elif exactness == "EXACT_DOWN" :
56+ "amount" : {
57+ "maximum" : 0 ,
58+ "minimum" : amountValue
59+ }
60+ }
61+ elif amountExactness == "EXACT_DOWN" :
3862 payload ["validationRules" ] = {
39- "amount" : {"maximum" : amount , "minimum" : 0 }}
63+ "amount" : {
64+ "maximum" : amountValue ,
65+ "minimum" : 0
66+ }
67+ }
4068
4169 headers = generate_setu_headers (
4270 self .schemeId , self .secret , self .productInstance
4371 )
4472 response = requests .post (
45- self .url + path , json = payload , headers = headers )
73+ self .url + path , json = payload , headers = headers
74+ )
4675 handle_setu_errors (response )
4776 data = response .json ()
4877 self .platformBillID = data ["data" ]["platformBillID" ]
4978 return data ["data" ]
5079
51- def check_status (self , platformBillID = None ):
80+ def checkPaymentStatus (self , platformBillID = None ):
5281 bill_id = self .platformBillID
5382 if platformBillID :
5483 bill_id = platformBillID
5584 path = "/payment-links/{}" .format (bill_id )
5685 headers = generate_setu_headers (
5786 self .schemeId , self .secret , self .productInstance
5887 )
59- response = requests .get (self .url + path , headers = headers )
88+ response = requests .get (
89+ self .url + path , headers = headers
90+ )
6091 data = response .json ()
6192 print (data )
6293 return data ["data" ]
6394
64- def mock_payment (self , amount , upiId ):
95+ def mock_payment (self , amountValue , upiId ):
6596 path = "/triggers/funds/addCredit"
6697 payload = {
67- "amount" : amount ,
68- "destinationAccount" : {"accountID" : upiId },
69- "sourceAccount" : {"accountID" : "customer@vpa" },
98+ "amount" : amountValue ,
99+ "destinationAccount" : {
100+ "accountID" : upiId
101+ },
102+ "sourceAccount" : {
103+ "accountID" : "customer@vpa"
104+ },
70105 "type" : "UPI" ,
71106 }
72107
73108 headers = generate_setu_headers (
74109 self .schemeId , self .secret , self .productInstance
75110 )
76111 response = requests .post (
77- self .url + path , json = payload , headers = headers )
112+ self .url + path , json = payload , headers = headers
113+ )
78114 if response .status_code != 200 :
79115 raise Exception ("Failed to mock payment" , )
80116 return "Mock success"
0 commit comments