Skip to content

Commit 011adaf

Browse files
Deeplink SDK first commit
0 parents  commit 011adaf

24 files changed

Lines changed: 293 additions & 0 deletions

.pypirc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[distutils]
2+
index-servers =
3+
pypi
4+
[pypi]
5+
repository=https://upload.pypi.org/legacy/
6+

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Setu
2+
This package helps you work with Setu's deeplink APIs.
3+
* To generate a payment link
4+
* To check status of the payment link
5+
6+
## Usage
7+
```
8+
from setu import deeplink
9+
10+
dl = deeplink.Deeplink(
11+
"262c5ab6-60d9-464e-a584-af008a8d0437", // SchemeId
12+
"e056f034-9da3-47e6-ba84-6cd16ccce6a3", // Secret
13+
"378992706761786990", // Product instance ID
14+
)
15+
link = dl.generate_link(2300, 4, "gb", "1231243")
16+
print(link["paymentLink"], link["platformBillID"])
17+
status = dl.check_status(link['platformBillID'])
18+
print(status["status"])
19+
```

Setu.egg-info/PKG-INFO

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Metadata-Version: 1.0
2+
Name: setu
3+
Version: 0.2
4+
Summary: Setu's deeplink pckage
5+
Home-page: https://gitlab.com/setu-lobby/setu-pypi
6+
Author: GB
7+
Author-email: gandharva@setu.co
8+
License: MIT
9+
Description: UNKNOWN
10+
Platform: UNKNOWN

Setu.egg-info/SOURCES.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
README.md
2+
setup.py
3+
Setu.egg-info/PKG-INFO
4+
Setu.egg-info/SOURCES.txt
5+
Setu.egg-info/dependency_links.txt
6+
Setu.egg-info/not-zip-safe
7+
Setu.egg-info/top_level.txt
8+
setu/__init__.py
9+
setu/auth.py
10+
setu/deeplink.py
11+
setu/errors.py
12+
setu.egg-info/PKG-INFO
13+
setu.egg-info/SOURCES.txt
14+
setu.egg-info/dependency_links.txt
15+
setu.egg-info/not-zip-safe
16+
setu.egg-info/top_level.txt

Setu.egg-info/dependency_links.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Setu.egg-info/not-zip-safe

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Setu.egg-info/top_level.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setu

build/lib/setu/__init__.py

Whitespace-only changes.

build/lib/setu/auth.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import jwt
2+
import datetime
3+
import uuid
4+
5+
6+
def generate_JWT(schemeId, secret):
7+
payload = {
8+
"aud": schemeId,
9+
"iat": datetime.datetime.utcnow(),
10+
"jti": str(uuid.uuid1()),
11+
}
12+
13+
return jwt.encode(payload, secret, algorithm="HS256").decode("utf-8")
14+
15+
16+
def generate_bearer_JWT(schemeId, secret):
17+
return "Bearer {}".format(generate_JWT(schemeId, secret))
18+
19+
20+
def verify_JWT(token, schemeId, secret):
21+
try:
22+
jwt.decode(token, secret, audience=schemeId)
23+
print("Verified token")
24+
except jwt.PyJWTError:
25+
raise
26+
27+
28+
def generate_setu_headers(schemeId, secret, setuProductInstanceID):
29+
return {
30+
"Authorization": generate_bearer_JWT(schemeId, secret),
31+
"X-Setu-Product-Instance-ID": setuProductInstanceID
32+
}

build/lib/setu/deeplink.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import requests
2+
import datetime
3+
from .auth import generate_setu_headers
4+
from .errors import handle_setu_errors
5+
6+
7+
class URLS:
8+
class Sandbox:
9+
url = "https://sandbox.setu.co/api"
10+
11+
class Prod:
12+
url = "https://prod.setu.co/api"
13+
14+
15+
class Deeplink:
16+
def __init__(self, schemeId, secret, productInstance, production=False):
17+
self.schemeId = schemeId
18+
self.secret = secret
19+
self.productInstance = productInstance
20+
self.url = URLS.Sandbox.url if not production else URLS.Prod.url
21+
22+
def generate_link(self, amount, expiresInDays, payeeName, refId, exactness="EXACT"):
23+
expiryDate = datetime.datetime.now() + datetime.timedelta(days=expiresInDays)
24+
path = "/payment-links"
25+
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")),
31+
"name": payeeName,
32+
}
33+
34+
if exactness == "EXACT_UP":
35+
payload["validationRules"] = {"amount": {"maximum": 0, "minimum": amount}}
36+
elif exactness == "EXACT_DOWN":
37+
payload["validationRules"] = {"amount": {"maximum": amount, "minimum": 0}}
38+
39+
headers = generate_setu_headers(
40+
self.schemeId, self.secret, self.productInstance
41+
)
42+
response = requests.post(self.url + path, json=payload, headers=headers)
43+
handle_setu_errors(response)
44+
data = response.json()
45+
self.platformBillID = data["data"]["platformBillID"]
46+
return data["data"]
47+
48+
def check_status(self, platformBillID=None):
49+
bill_id = self.platformBillID
50+
if platformBillID:
51+
bill_id = platformBillID
52+
path = "/payment-links/{}".format(bill_id)
53+
headers = generate_setu_headers(
54+
self.schemeId, self.secret, self.productInstance
55+
)
56+
response = requests.get(self.url + path, headers=headers)
57+
data = response.json()
58+
print(data)
59+
return data["data"]
60+
61+
def mock_payment(self, amount, upiId):
62+
path = "/triggers/funds/addCredit"
63+
payload = {
64+
"amount": 0,
65+
"destinationAccount": {"accountID": 'Biller-66147538470438-001', "ifsc": "EXTERNALBRANCH001"},
66+
"sourceAccount": {"accountID": "123123123", "ifsc": "1231231"},
67+
"type": "UPI",
68+
}
69+
70+
headers = generate_setu_headers(
71+
self.schemeId, self.secret, self.productInstance
72+
)
73+
print("Coming soon!")
74+
# response = requests.post(self.url + path,json=payload, headers=headers)
75+
# data= response.json()
76+
# print('mock----',data)

0 commit comments

Comments
 (0)