Skip to content

Commit b1552c4

Browse files
Merge pull request #17 from SetuHQ/move-to-generic-refund-status-api
feat(api)!: move to generic refund status API
2 parents 91cdf7d + 6227fed commit b1552c4

8 files changed

Lines changed: 280 additions & 146 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Ready to contribute? Here's how to set up `setu-python-sdk` for local developmen
5959
4. Install dependencies and start your virtualenv:
6060
6161
```
62-
$ poetry install -E test -E doc -E dev
62+
$ poetry install
6363
```
6464
6565
5. Create a branch for local development:

poetry.lock

Lines changed: 233 additions & 128 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ PyJWT = "^2.4.0"
2929
requests = "^2.27.1"
3030
marshmallow = "^3.14.1"
3131
marshmallow-oneofschema = "^3.0.1"
32+
Deprecated = "^1.2.13"
3233

3334
[tool.poetry.dev-dependencies]
3435
black = "22.3.0"

setu/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Top-level package for Setu UPI DeepLinks SDK."""
2-
from setu.deeplink import Deeplink
32
from setu.contract import SetuAPIException
3+
from setu.deeplink import Deeplink
44

55
__version__ = '1.1.1'
66

setu/contract.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dataclasses import dataclass
33
from datetime import datetime
44
from enum import Enum
5-
from typing import Any, Dict, List, NamedTuple, Optional, Union
5+
from typing import Any, Dict, List, Literal, NamedTuple, Optional, Union
66

77
# Auth types
88
AuthType = str # TODO: Figure out a way to use Literal["JWT", "OAUTH"] across Python versions
@@ -203,8 +203,10 @@ class InitiateBatchRefundResponse:
203203

204204

205205
@dataclass
206-
class BatchRefundStatusResponse:
207-
"""Batch Refund Status Response."""
206+
class RefundStatusByIdentifierResponse:
207+
"""Refund Status By Identifier Response."""
208208

209-
batch_id: str
210209
refunds: List[RefundResponseItem]
210+
211+
212+
RefundStatusIdentifierType = Literal["batch", "bill"]

setu/deeplink.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Any, Callable, Dict, List
55

66
import requests
7+
from deprecated import deprecated
78
from requests import Response
89

910
from setu.auth import generate_jwt_token, generate_oauth_token
@@ -18,26 +19,27 @@
1819
AUTH_TYPE_JWT,
1920
MODE_PRODUCTION,
2021
AuthType,
21-
BatchRefundStatusResponse,
2222
CreatePaymentLinkResponseData,
2323
InitiateBatchRefundResponse,
2424
MockCreditResponseData,
2525
Mode,
2626
PaymentLinkStatusResponseData,
2727
RefundRequestItem,
2828
RefundResponseItem,
29+
RefundStatusByIdentifierResponse,
30+
RefundStatusIdentifierType,
2931
SettlementSplits,
3032
SetuAPIException,
3133
ValidationRules,
3234
)
3335
from setu.endpoint import get_url_path
3436
from setu.serial import (
35-
BatchRefundStatusResponseSchema,
3637
CreatePaymentLinkResponseDataSchema,
3738
InitiateBatchRefundResponseDataSchema,
3839
MockCreditResponseDataSchema,
3940
PaymentLinkStatusResponseDataSchema,
4041
RefundResponseItemSchema,
42+
RefundStatusByIdentifierResponseSchema,
4143
SetuErrorResponseSchema,
4244
)
4345

@@ -213,14 +215,29 @@ def initiate_batch_refund(
213215
initiate_batch_refund_response_data_schema = InitiateBatchRefundResponseDataSchema()
214216
return initiate_batch_refund_response_data_schema.load(api_response.json()['data'])
215217

218+
@deprecated(version="1.2.0", reason="Use the more generic get_refund_status_by_identifier method instead")
216219
@Decorators.auth_handler
217-
def get_batch_refund_status(self, batch_refund_id: str) -> BatchRefundStatusResponse:
220+
def get_batch_refund_status(self, batch_refund_id: str) -> RefundStatusByIdentifierResponse:
218221
"""Get batch refund status."""
219222
api_response = self.session.get(
220223
"{}/batch/{}".format(get_url_path(API.REFUNDS_BASE, self.auth_type, self.mode), batch_refund_id),
221224
headers=self.headers,
222225
)
223-
batch_refund_status_response_schema = BatchRefundStatusResponseSchema()
226+
batch_refund_status_response_schema = RefundStatusByIdentifierResponseSchema()
227+
return batch_refund_status_response_schema.load(api_response.json()['data'])
228+
229+
@Decorators.auth_handler
230+
def get_refund_status_by_identifier(
231+
self, identifier_type: RefundStatusIdentifierType, identifier_value: str
232+
) -> RefundStatusByIdentifierResponse:
233+
"""Get batch refund status."""
234+
api_response = self.session.get(
235+
"{}/{}/{}".format(
236+
get_url_path(API.REFUNDS_BASE, self.auth_type, self.mode), identifier_type, identifier_value
237+
),
238+
headers=self.headers,
239+
)
240+
batch_refund_status_response_schema = RefundStatusByIdentifierResponseSchema()
224241
return batch_refund_status_response_schema.load(api_response.json()['data'])
225242

226243
@Decorators.auth_handler

setu/serial.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from setu.contract import (
88
Account,
99
Amount,
10-
BatchRefundStatusResponse,
1110
CreatePaymentLinkResponseData,
1211
InitiateBatchRefundResponse,
1312
MockCreditResponseData,
1413
PaymentLink,
1514
PaymentLinkStatusResponseData,
1615
Receipt,
1716
RefundResponseItem,
17+
RefundStatusByIdentifierResponse,
1818
SetuErrorResponseData,
1919
)
2020

@@ -206,13 +206,12 @@ def make_initiate_batch_refund_response_data(self, data, **kwargs):
206206
return InitiateBatchRefundResponse(**data)
207207

208208

209-
class BatchRefundStatusResponseSchema(Schema):
210-
"""Get Batch Refund Status Response Data Schema."""
209+
class RefundStatusByIdentifierResponseSchema(Schema):
210+
"""Get Refund Status By Identifier Response Data Schema."""
211211

212-
batch_id = fields.Str(data_key="batchID")
213212
refunds = fields.List(fields.Nested(RefundResponseItemSchema()))
214213

215214
@post_load
216215
def make_batch_refund_response(self, data, **kwargs):
217-
"""Deserialize to BatchRefundStatusResponse object."""
218-
return BatchRefundStatusResponse(**data)
216+
"""Deserialize to RefundStatusByIdentifierResponse object."""
217+
return RefundStatusByIdentifierResponse(**data)

tests/test_deeplink.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def test_deeplink(v2_creds):
1919
mode="SANDBOX",
2020
)
2121

22-
bill_amount = 100
22+
bill_amount = 1000
2323
split_account = SplitAccount(
2424
account_number="123456789",
2525
account_ifsc="KKBK0000001",
26-
amount_value=50,
26+
amount_value=500,
2727
)
2828

2929
try:
@@ -99,6 +99,16 @@ def test_deeplink(v2_creds):
9999
LOGGER.info(refund_batch_status_response)
100100
assert refund_batch_status_response.refunds[0].bill_id == link.platform_bill_id
101101

102+
refund_batch_status_response = dl.get_refund_status_by_identifier(
103+
"batch", batch_initiate_refund_response.batch_id
104+
)
105+
LOGGER.info(refund_batch_status_response)
106+
assert refund_batch_status_response.refunds[0].bill_id == link.platform_bill_id
107+
108+
refund_batch_status_response = dl.get_refund_status_by_identifier("bill", link.platform_bill_id)
109+
LOGGER.info(refund_batch_status_response)
110+
assert refund_batch_status_response.refunds[0].status == "MarkedForRefund"
111+
102112
# Get individual refund status
103113
refund_status_response = dl.get_refund_status(batch_initiate_refund_response.refunds[0].id)
104114
LOGGER.info(refund_status_response)

0 commit comments

Comments
 (0)