Skip to content

Commit 8203801

Browse files
Update README
1 parent 09e13e6 commit 8203801

2 files changed

Lines changed: 91 additions & 54 deletions

File tree

README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Currently the following APIs are supported.
77
- UPI DeepLinks
88

99
We're constantly adding new API support. Feel free to reach out to us if you
10-
can't see any API.
10+
can't see an API.
1111

1212
## Installation
1313

@@ -24,7 +24,7 @@ The following actions are currently supported
2424
- Generate payment link
2525
- Check status of payment link
2626

27-
#### Generate Link
27+
#### Configuration
2828

2929
```python
3030
from setu import deeplink
@@ -33,18 +33,43 @@ dl = deeplink.Deeplink(
3333
"YOUR SCHEME ID",
3434
"YOUR JWT SECRET",
3535
"YOUR PRODUCT INSTANCE ID",
36+
mode="PRODUCTION | SANDBOX" # default SANDBOX
3637
)
37-
link = dl.generate_link(2300, 4, "gb", "1231243")
38-
print(link["paymentLink"], link["platformBillID"])
3938
```
4039

41-
#### Generate Link
40+
#### Generate UPI payment link
4241

4342
```python
44-
from setu import deeplink
43+
link = dl.create_payment_link(
44+
amountValue=Number,
45+
billerBillID=String,
46+
amountExactness=String,
47+
dueDate=String, # Optional
48+
payeeName=String, # Optional
49+
expiryDate=String, # Optional
50+
settlement=Object, # Optional
51+
validationRules=Object # Optional
52+
)
53+
print(link)
54+
```
55+
56+
#### Check status of UPI payment link
57+
58+
```python
59+
status = dl.check_payment_status(
60+
platformBillID=String
61+
)
62+
print(status)
63+
```
4564

46-
status = dl.checkPaymentStatus(link['platformBillID'])
47-
print(status["status"])
65+
#### Trigger mock payment for UPI payment link - ONLY IN SANDBOX ⚠️
66+
67+
```python
68+
status = dl.trigger_mock_payment(
69+
amountValue=Number, # Decimal Value
70+
upiID=UPI_ID # UPI ID generated by create_payment_link method
71+
)
72+
print(status)
4873
```
4974

5075
## License

setu/deeplink.py

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
class URLS:
8+
89
class Sandbox:
910
url = "https://sandbox.setu.co/api"
1011

@@ -14,22 +15,24 @@ class Prod:
1415

1516
class Deeplink:
1617

17-
def __init__(self, schemeId, secret, productInstance, production=False):
18+
def __init__(self, schemeId, secret, productInstance, mode="SANDBOX"):
1819
self.schemeId = schemeId
1920
self.secret = secret
2021
self.productInstance = productInstance
21-
self.url = URLS.Sandbox.url if not production else URLS.Prod.url
22+
self.url = URLS.Sandbox.url if mode != "PRODUCTION" else URLS.Prod.url
23+
self.mode = mode
2224

23-
def createPaymentLink(
25+
# Generate UPI payment link method
26+
def create_payment_link(
2427
self,
2528
amountValue,
2629
billerBillID,
2730
amountExactness,
28-
dueDate,
29-
expiryDate,
30-
payeeName,
31-
settlement,
32-
validationRules
31+
dueDate=None,
32+
expiryDate=None,
33+
payeeName=None,
34+
settlement=None,
35+
validationRules=None
3336
):
3437

3538
path = "/payment-links"
@@ -39,78 +42,87 @@ def createPaymentLink(
3942
"value": amountValue
4043
},
4144
"amountExactness": amountExactness,
42-
"billerBillID": billerBillID,
43-
"name": payeeName,
44-
"dueDate": dueDate,
45-
"expiryDate": expiryDate
45+
"billerBillID": billerBillID
4646
}
4747

48-
if settlement:
48+
if payeeName is not None:
49+
payload.update({"name": payeeName})
50+
51+
if dueDate is not None:
52+
payload.update({"dueDate": dueDate})
53+
54+
if expiryDate is not None:
55+
payload.update({"expiryDate": expiryDate})
56+
57+
if settlement is not None:
4958
payload.update({"settlement": settlement})
5059

51-
if validationRules:
60+
if validationRules is not None:
5261
payload.update({"validationRules": validationRules})
5362

54-
if amountExactness == "EXACT_UP":
55-
payload["validationRules"] = {
56-
"amount": {
57-
"maximum": 0,
58-
"minimum": amountValue
59-
}
60-
}
61-
elif amountExactness == "EXACT_DOWN":
62-
payload["validationRules"] = {
63-
"amount": {
64-
"maximum": amountValue,
65-
"minimum": 0
66-
}
67-
}
68-
63+
# Generate required headers
6964
headers = generate_setu_headers(
7065
self.schemeId, self.secret, self.productInstance
7166
)
67+
68+
# Call API with required parameters
7269
response = requests.post(
7370
self.url + path, json=payload, headers=headers
7471
)
72+
73+
# Handle errors
7574
handle_setu_errors(response)
76-
data = response.json()
77-
self.platformBillID = data["data"]["platformBillID"]
78-
return data["data"]
79-
80-
def checkPaymentStatus(self, platformBillID=None):
81-
bill_id = self.platformBillID
82-
if platformBillID:
83-
bill_id = platformBillID
84-
path = "/payment-links/{}".format(bill_id)
75+
76+
return response.json()
77+
78+
# Check status of UPI payment link method
79+
def check_payment_status(
80+
self,
81+
platformBillID
82+
):
83+
path = "/payment-links/{}".format(platformBillID)
84+
85+
# Generate required headers
8586
headers = generate_setu_headers(
8687
self.schemeId, self.secret, self.productInstance
8788
)
89+
90+
# Call API with required parameters
8891
response = requests.get(
8992
self.url + path, headers=headers
9093
)
91-
data = response.json()
92-
print(data)
93-
return data["data"]
9494

95-
def mock_payment(self, amountValue, upiId):
95+
return response.json()
96+
97+
# AVAILABLE ONLY FOR SANDBOX
98+
# Trigger mock payment for UPI payment link
99+
def trigger_mock_payment(self, amountValue, upiID):
100+
101+
if self.mode == "PRODUCTION":
102+
raise Exception(
103+
"trigger_mock_payment METHOD IS IS NOT AVAILABLE IN PRODUCTION"
104+
)
105+
96106
path = "/triggers/funds/addCredit"
97107
payload = {
98108
"amount": amountValue,
99109
"destinationAccount": {
100-
"accountID": upiId
110+
"accountID": upiID
101111
},
102112
"sourceAccount": {
103113
"accountID": "customer@vpa"
104114
},
105115
"type": "UPI",
106116
}
107117

118+
# Generate required headers
108119
headers = generate_setu_headers(
109120
self.schemeId, self.secret, self.productInstance
110121
)
122+
123+
# Call API with required parameters
111124
response = requests.post(
112125
self.url + path, json=payload, headers=headers
113126
)
114-
if response.status_code != 200:
115-
raise Exception("Failed to mock payment", )
116-
return "Mock success"
127+
128+
return response

0 commit comments

Comments
 (0)