This commit is contained in:
behruz-dev
2025-09-04 15:39:08 +05:00
parent 031bdbe637
commit 3addf34466
2 changed files with 36 additions and 36 deletions

View File

@@ -29,45 +29,45 @@ class AtmosCallbackApiView(APIView):
client_ip = get_client_ip(request) client_ip = get_client_ip(request)
# if client_ip not in settings.ALLOWED_ATMOS_IPS: # if client_ip not in settings.ALLOWED_ATMOS_IPS:
# return Response({"status": 0, "message": "IP ruxsat etilmagan"}, status=403) # return Response({"status": 0, "message": "IP ruxsat etilmagan"}, status=403)
data = request.data # data = request.data
print(data) # print(data)
if not data: # if not data:
return Response( # return Response(
{'success': 0, "message": "Request body required"}, # {'success': 0, "message": "Request body required"},
status=status.HTTP_200_OK # status=status.HTTP_200_OK
) # )
store_id = data.get("store_id") # store_id = data.get("store_id")
transaction_id = data.get("transaction_id") # transaction_id = data.get("transaction_id")
invoice = data.get("invoice") # invoice = data.get("invoice")
amount = data.get("amount") # amount = data.get("amount")
sign = data.get("sign") # sign = data.get("sign")
check_string = f"{store_id}{transaction_id}{invoice}{amount}{settings.API_KEY}" # check_string = f"{store_id}{transaction_id}{invoice}{amount}{settings.API_KEY}"
generated_sign = hashlib.sha256(check_string.encode()).hexdigest() # generated_sign = hashlib.sha256(check_string.encode()).hexdigest()
print(generated_sign, '----------------------------------------------------') # print(generated_sign, '----------------------------------------------------')
if generated_sign != sign: # if generated_sign != sign:
return Response( # return Response(
{"status": 0, "message": f"Инвойс с номером {invoice} отсутствует в системе"}, # {"status": 0, "message": f"Инвойс с номером {invoice} отсутствует в системе"},
status=status.HTTP_200_OK # status=status.HTTP_200_OK
) # )
try: # try:
order = Order.objects.get(order_number=invoice) # order = Order.objects.get(order_number=invoice)
except Order.DoesNotExist: # except Order.DoesNotExist:
return Response( # return Response(
{"status": 0, "message": f"Инвойс с номером {invoice} отсутствует в системе"}, # {"status": 0, "message": f"Инвойс с номером {invoice} отсутствует в системе"},
status=status.HTTP_200_OK # status=status.HTTP_200_OK
) # )
if str(order.total_price) != str(amount): # if str(order.total_price) != str(amount):
return Response( # return Response(
{"status": 0, "message": f"Инвойс с номером {invoice} отсутствует в системе"}, # {"status": 0, "message": f"Инвойс с номером {invoice} отсутствует в системе"},
status=status.HTTP_200_OK # status=status.HTTP_200_OK
) # )
order.is_paid = True # order.is_paid = True
order.save() # order.save()
return Response( return Response(
{"status": 1, "message": "Успешно"}, {"status": 1, "message": "Успешно"},

View File

@@ -34,7 +34,7 @@ class Atmos:
'Authorization': f'Bearer {access_token}', 'Authorization': f'Bearer {access_token}',
} }
data = { data = {
'amount': amount, 'amount': int(amount) * 100,
'account': str(account), 'account': str(account),
'store_id': f'{self.store_id}' 'store_id': f'{self.store_id}'
} }