Created
September 2, 2018 21:36
-
-
Save mahdizojaji/200669c5789e1206b78a73f4a49a80bf to your computer and use it in GitHub Desktop.
چک کردن تراکنش کارت به کارت بانک ملی
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# trans_id -> شماره ارجاع یا پیگیری | |
# card -> چهار رقم آخر شماره کارت بانکی | |
# amount -> مبلغ تراکنش به ریال | |
# با تغییر در کد میتوانید کلیه تراکنش هارو چک کنید. ولی این فقط برای تراکنش های ورودی کارت به کارت هستش | |
def check_payment(trans_id, card, amount): | |
login_url = 'https://my.bmi.ir/portalserver/j_spring_security_check' | |
headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'} | |
username = '' | |
password = '' | |
data = { | |
'j_username': username, | |
'j_password': password, | |
'security_answer': 'undefined', | |
'portal_name': 'ibankportal' | |
} | |
session = requests.Session() | |
session.post(login_url, data=data, headers=headers) | |
card_url = 'https://my.bmi.ir/portalserver/services/rest/customer/accounts/full/group' | |
shomarehesab = json.loads(session.get(card_url, headers=headers).text)['loan-account'][0]['id'] | |
trans_url = 'https://my.bmi.ir/portalserver/services/rest/customer/accounts/' \ | |
'{}/int-transactions?f=1&l=200&sort=false'.format(shomarehesab) | |
trans_req = session.get(trans_url).text | |
tr_id = None | |
for x in json.loads(trans_req): | |
if x['transactionTrace'] == trans_id: | |
if x['transactionAmountWithSign'] == '+{}'.format(amount): | |
tr_id = x['id'] | |
break | |
if tr_id: | |
data_url = 'https://my.bmi.ir/portalserver/services/rest/customer/accounts/' \ | |
'{}/int-transactions/{}/details'.format(shomarehesab, tr_id) | |
data_req = session.get(data_url).text | |
jdat = json.loads(data_req) | |
card_number = jdat['transactionDescription'].split(' ')[0][-4:] | |
if card == card_number: | |
pdf_url = 'https://my.bmi.ir/portalserver/services/rest/download/' \ | |
'{}/transactions/{}/pdf'.format(shomarehesab, tr_id) | |
with open('downloads/{}.pdf'.format(tr_id), "wb") as file: | |
response = session.get(pdf_url) | |
file.write(response.content) | |
return { | |
'success': True, | |
'pdf': 'downloads/{}.pdf'.format(tr_id), | |
'card': jdat['transactionDescription'].split(' ')[0], | |
'time': jdat['transactionTime'], | |
'date': jdat['jalaliTransactionDate'] | |
} | |
else: | |
return {'success': False} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment