Skip to content

Commit 8825d3d

Browse files
committed
update to 0.1.5 add getBankList and getAccountByPhone
1 parent 73fc596 commit 8825d3d

File tree

2 files changed

+57
-62
lines changed

2 files changed

+57
-62
lines changed

mbbank/main.py

+30
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,36 @@ def getCardTransactionHistory(self, cardNo: str, from_date: datetime.datetime, t
306306
data_out = self._req("https://online.mbbank.com.vn/api/retail_web/common/getTransactionHistory", json=json_data)
307307
return data_out
308308

309+
def getBankList(self):
310+
"""
311+
Get transfer all bank list
312+
313+
Returns:
314+
success (dict): bank list
315+
316+
Raises:
317+
MBBankError: if api response not ok
318+
"""
319+
data_out = await self._req("https://online.mbbank.com.vn/api/retail_web/common/getBankList")
320+
return data_out
321+
322+
def getAccountByPhone(self, phone: str):
323+
"""
324+
Get transfer account info by phone (MBank internal account only)
325+
326+
Args:
327+
phone (str): MBBank account phone number
328+
329+
Returns:
330+
success (dict): account info
331+
332+
"""
333+
json_data = {
334+
"phone": phone
335+
}
336+
data_out = self._req("https://online.mbbank.com.vn/api/retail_web/common/getAccountByPhone", json=json_data)
337+
return data_out
338+
309339
def userinfo(self):
310340
"""
311341
Get current user info

mbbank/mbasync.py

+27-62
Original file line numberDiff line numberDiff line change
@@ -291,84 +291,49 @@ async def getCardTransactionHistory(self, cardNo: str, from_date: datetime.datet
291291
json=json_data)
292292
return data_out
293293

294-
async def userinfo(self):
294+
async def getBankList(self):
295295
"""
296-
Get current user info
296+
Get transfer all bank list
297297
298298
Returns:
299-
success (dict): user info
299+
success (dict): bank list
300300
301301
Raises:
302302
MBBankError: if api response not ok
303303
"""
304-
if self._userinfo is None:
305-
await self._authenticate()
306-
else:
307-
await self.getBalance()
308-
return self._userinfo
309-
310-
# working on beta
311-
312-
async def getBankList(self):
313304
data_out = await self._req("https://online.mbbank.com.vn/api/retail_web/common/getBankList")
314305
return data_out
315306

316-
async def inquiryAccountName(self, *, typeTransfer: str = None, debitAccount: str, bankCode: str = None,
317-
creditAccount: str, creditAccountType: typing.Literal["ACCOUNT", "CARD"]):
318-
creditCardNo = None
319-
if (bankCode is None or typeTransfer is None) and creditAccountType != "CARD":
320-
raise TypeError("creditAccount must be \"CARD\" so bankCode or typeTransfer can be None")
321-
elif creditAccountType == "CARD":
322-
out = await self.getBankList()
323-
for i in out['listBank']:
324-
bankCode = None
325-
typeTransfer = None
326-
if creditAccount.startswith(i["smlCode"]):
327-
bankCode = i["smlCode"]
328-
typeTransfer = i["typeTransfer"]
329-
datacard = await self.cardGenerateID(creditAccount)
330-
creditCardNo = datacard["cardNumber"]
331-
creditAccount = datacard["cardID"]
332-
break
333-
if bankCode is None or typeTransfer is None:
334-
raise Exception(f"Invaild card")
335-
elif not creditAccount:
336-
raise Exception(f"Card not exist")
337-
json_data = {
338-
"creditAccount": creditAccount,
339-
"creditAccountType": creditAccountType,
340-
"bankCode": bankCode,
341-
"debitAccount": debitAccount,
342-
"type": typeTransfer,
343-
"remark": "",
344-
}
345-
if creditCardNo is not None:
346-
json_data.setdefault("creditCardNo", creditCardNo)
347-
data_out = await self._req("https://online.mbbank.com.vn/api/retail_web/transfer/inquiryAccountName",
348-
json=json_data)
349-
return data_out
307+
async def getAccountByPhone(self, phone: str):
308+
"""
309+
Get transfer account info by phone (MBank internal account only)
350310
351-
async def getServiceToken(self):
352-
data_out = await self._req("https://online.mbbank.com.vn/api/retail_web/common/getServiceToken")
353-
return data_out
311+
Args:
312+
phone (str): MBBank account phone number
354313
355-
async def cardGenerateID(self, cardNumber: str):
356-
headers = headers_default.copy()
357-
json_data = {
358-
"requestID": f"{self.__userid}-{get_now_time()}",
359-
"cardNumber": cardNumber
360-
}
361-
tok = await self.getServiceToken()
362-
headers["Authorization"] = tok["type"].capitalize() + " " + tok["token"]
363-
async with aiohttp.ClientSession() as s:
364-
async with s.post("https://mbcard.mbbank.com.vn:8446/mbcardgw/internet/cardinfo/v1_0/generateid",
365-
headers=headers, json=json_data) as r:
366-
return await r.json()
314+
Returns:
315+
success (dict): account info
367316
368-
async def getAccountByPhone(self, phone: str):
317+
"""
369318
json_data = {
370319
"phone": phone
371320
}
372321
data_out = await self._req("https://online.mbbank.com.vn/api/retail_web/common/getAccountByPhone",
373322
json=json_data)
374323
return data_out
324+
325+
async def userinfo(self):
326+
"""
327+
Get current user info
328+
329+
Returns:
330+
success (dict): user info
331+
332+
Raises:
333+
MBBankError: if api response not ok
334+
"""
335+
if self._userinfo is None:
336+
await self._authenticate()
337+
else:
338+
await self.getBalance()
339+
return self._userinfo

0 commit comments

Comments
 (0)