From d0372b0eee4c97f6ebef461c2bd0d5f2057bae6c Mon Sep 17 00:00:00 2001 From: CRIMINAL Date: Sat, 19 Jun 2021 07:14:16 +0100 Subject: [PATCH] API - Check if user has enough credit/wallet balance to subscribe Will return error_details object if failed. --- apis/onlyfans/classes/create_auth.py | 1 + apis/onlyfans/classes/create_user.py | 7 +++++-- apis/onlyfans/classes/extras.py | 2 +- datascraper/main_datascraper.py | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apis/onlyfans/classes/create_auth.py b/apis/onlyfans/classes/create_auth.py index fac521720..a4742d39b 100644 --- a/apis/onlyfans/classes/create_auth.py +++ b/apis/onlyfans/classes/create_auth.py @@ -40,6 +40,7 @@ def __init__( self.isPerformer = user.isPerformer self.chatMessagesCount = user.chatMessagesCount self.subscribesCount = user.subscribesCount + self.creditBalance = user.creditBalance self.lists = {} self.links = content_types() self.subscriptions: list[create_user] = [] diff --git a/apis/onlyfans/classes/create_user.py b/apis/onlyfans/classes/create_user.py index 8aa319a90..bb4cea510 100644 --- a/apis/onlyfans/classes/create_user.py +++ b/apis/onlyfans/classes/create_user.py @@ -488,8 +488,11 @@ async def buy_subscription(self): "token": "", "unavailablePaymentGates": [], } - link = endpoint_links().pay - result = await self.session_manager.json_request(link, method="POST", payload=x) + if self.subscriber.creditBalance >= subscription_price: + link = endpoint_links().pay + result = await self.session_manager.json_request(link, method="POST", payload=x) + else: + result = error_details({"code":2011,"message":"Insufficient Credit Balance"}) return result def set_scraped(self, name, scraped): diff --git a/apis/onlyfans/classes/extras.py b/apis/onlyfans/classes/extras.py index 054e1ce30..f96f86782 100644 --- a/apis/onlyfans/classes/extras.py +++ b/apis/onlyfans/classes/extras.py @@ -145,7 +145,7 @@ def __init__( # Lol? class error_details: def __init__(self, result) -> None: - error = result["error"] + error = result["error"] if "error" in result else result self.code = error["code"] self.message = error["message"] diff --git a/datascraper/main_datascraper.py b/datascraper/main_datascraper.py index 5e59ebc2f..d61444135 100644 --- a/datascraper/main_datascraper.py +++ b/datascraper/main_datascraper.py @@ -1,3 +1,5 @@ +from apis.onlyfans.classes.create_user import create_user +from apis.onlyfans.classes.extras import error_details import os import timeit from typing import Optional @@ -88,6 +90,7 @@ async def start_datascraper( auth_count += 1 subscription_array += subscriptions await main_helper.process_webhooks(api, "auth_webhook", "succeeded") + # Do stuff with authed user subscription_list = module.format_options( subscription_array, "usernames", api.auths )