Skip to content

Commit e12e43a

Browse files
author
krishna
committed
Re Initializing headers (token) in case of JWT
1 parent de372ce commit e12e43a

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

setu/deeplink.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ def __init__(self, schemeId, secret, productInstance, authType="JWT", mode="SAND
2323
self.mode = mode
2424
self.authType = authType
2525

26-
# Generate required headers
27-
self.headers = generate_setu_headers(
28-
self.schemeId, self.secret, self.productInstance, self.url, self.authType
29-
)
30-
26+
3127
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
3233
self.url = self.url + '/v2'
3334

3435
# Generate UPI payment link method
@@ -69,6 +70,12 @@ def create_payment_link(
6970
if validationRules is not None:
7071
payload.update({"validationRules": validationRules})
7172

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+
)
78+
7279
# Call API with required parameters
7380
response = requests.post(
7481
self.url + path, json=payload, headers=self.headers
@@ -86,6 +93,12 @@ def check_payment_status(
8693
):
8794
path = "/payment-links/{}".format(platformBillID)
8895

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+
)
101+
89102
# Call API with required parameters
90103
response = requests.get(
91104
self.url + path, headers=self.headers
@@ -114,6 +127,12 @@ def trigger_mock_payment(self, amountValue, upiID):
114127
"type": "UPI",
115128
}
116129

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+
)
135+
117136
# Call API with required parameters
118137
response = requests.post(
119138
self.url + path, json=payload, headers=self.headers

0 commit comments

Comments
 (0)