next billing date
This commit is contained in:
@@ -111,14 +111,14 @@ def merms_account():
|
||||
@jwt_required()
|
||||
def merms_account_bar():
|
||||
data = request.get_json()
|
||||
response = AccountService.process_bar_request(data)
|
||||
response = AccountService.process_bar_data(data)
|
||||
return response
|
||||
|
||||
@api.route("/panel/account/bar", methods=["POST"])
|
||||
@jwt_required()
|
||||
def merms_account_bar2():
|
||||
data = request.get_json()
|
||||
response = AccountService.process_bar_request(data)
|
||||
response = AccountService.process_bar_data(data)
|
||||
return response
|
||||
|
||||
@api.route("/panel/account/actions", methods=["POST"])
|
||||
|
||||
+71
-21
@@ -2,12 +2,12 @@ from flask import session, jsonify
|
||||
# from app.models.loan import Loan
|
||||
from app.utils.logger import logger
|
||||
from app.api.services.base_service import BaseService
|
||||
#from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||
# from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||
from marshmallow import ValidationError
|
||||
from app.api.enums import TransactionType
|
||||
# from app.api.integrations import SimbrellaIntegration
|
||||
from app.extensions import db
|
||||
from app.models import Members, MembersActions, MembersProfile
|
||||
from app.models import Members, MembersActions, MembersProfile
|
||||
# from app.api.services.offer_analysis import OfferAnalysis
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
@@ -28,17 +28,71 @@ class AccountService(BaseService):
|
||||
"last_update": datetime.datetime.utcnow(),
|
||||
"top_bar": [
|
||||
{"id": "1", "description": "Contacts", "last_update": "10-10-2010 11:00 AM",
|
||||
"value": random.randint(0, 10), "data_span": 'Last 2 months',"link":"#", "extra_style" : ''},
|
||||
"value": random.randint(0, 10), "data_span": 'Last 2 months', "link": "#", "extra_style": ''},
|
||||
{"id": "2", "description": "Site Traffic", "last_update": "10-10-2010 11:30 AM",
|
||||
"value": random.randint(0, 10), "data_span": 'Past 12 hours',"link":"#", "extra_style" : ''},
|
||||
"value": random.randint(0, 10), "data_span": 'Past 12 hours', "link": "#", "extra_style": ''},
|
||||
{"id": "3", "description": "Appointments", "last_update": "10-12-2010 11:30 AM",
|
||||
"value": random.randint(0, 10), "data_span": 'Last 14 days',"link":"#", "extra_style" : ''},
|
||||
"value": random.randint(0, 10), "data_span": 'Last 14 days', "link": "#", "extra_style": ''},
|
||||
{"id": "4", "description": "Upgrade Account", "last_update": "10-12-2010 11:30 AM",
|
||||
"value": "Free Trial", "data_span": 'End: 10/10/2025',"link":"/subscription", "extra_style" : " billing "}
|
||||
]
|
||||
"value": "Free Trial", "data_span": 'End: 10/10/2025', "link": "/subscription",
|
||||
"extra_style": " billing "}
|
||||
]
|
||||
}
|
||||
return ResponseHelper.success(data=bar_data)
|
||||
|
||||
@staticmethod
|
||||
def process_bar_data(data):
|
||||
|
||||
try:
|
||||
with db.session.begin():
|
||||
|
||||
validated_data = AccountService.validate_data(data, UserSchema())
|
||||
user_token = validated_data.get('token')
|
||||
uid = str(validated_data.get('uid'))
|
||||
member_data = Members.get_member_by_uid(uid)
|
||||
|
||||
|
||||
option_name = member_data.option_name # "Free Trial"
|
||||
if option_name is not None and option_name != "":
|
||||
next_bill = f"Bill: {member_data.next_billing}"
|
||||
view_sub = "Account"
|
||||
else:
|
||||
option_name = "Free Trial"
|
||||
next_bill = "End: 10/10/202"
|
||||
view_sub = "Upgrade Account"
|
||||
|
||||
|
||||
bar_data = {
|
||||
"last_update": datetime.datetime.utcnow(),
|
||||
"top_bar": [
|
||||
{"id": "1", "description": "Contacts", "last_update": "10-10-2010 11:00 AM",
|
||||
"value": random.randint(0, 10), "data_span": 'Last 2 months', "link": "#", "extra_style": ''},
|
||||
{"id": "2", "description": "Site Traffic", "last_update": "10-10-2010 11:30 AM",
|
||||
"value": random.randint(0, 10), "data_span": 'Past 12 hours', "link": "#", "extra_style": ''},
|
||||
{"id": "3", "description": "Appointments", "last_update": "10-12-2010 11:30 AM",
|
||||
"value": random.randint(0, 10), "data_span": 'Last 14 days', "link": "#", "extra_style": ''},
|
||||
{"id": "4", "description": view_sub, "last_update": "10-12-2010 11:30 AM",
|
||||
"value": option_name, "data_span": next_bill, "link": "/subscription",
|
||||
"extra_style": " billing "}
|
||||
]
|
||||
}
|
||||
return ResponseHelper.success(data=bar_data)
|
||||
|
||||
except ValidationError as err:
|
||||
|
||||
logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}")
|
||||
db.session.rollback()
|
||||
return ResponseHelper.unprocessable_entity(result_description="Validation exception")
|
||||
|
||||
except ValueError as err:
|
||||
logger.error(f"{getattr(err, 'messages', str(err))}")
|
||||
db.session.rollback()
|
||||
return ResponseHelper.error(result_description=str(err))
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
def process_action_request(data):
|
||||
|
||||
@@ -67,7 +121,6 @@ class AccountService(BaseService):
|
||||
'updated': t.updated
|
||||
})
|
||||
|
||||
|
||||
action_data = {
|
||||
"recent_actions": member_actions_data,
|
||||
"last_update": datetime.datetime.utcnow(),
|
||||
@@ -97,8 +150,6 @@ class AccountService(BaseService):
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
try:
|
||||
@@ -113,14 +164,14 @@ class AccountService(BaseService):
|
||||
# Simulate processing
|
||||
response_data = {
|
||||
"member_id": member.id,
|
||||
"uid": str(uid),
|
||||
"uid": str(uid),
|
||||
"username": member.username,
|
||||
"account_name": member.account_name,
|
||||
"profile_completed": member.profile_completed,
|
||||
"firstname":member.firstname,
|
||||
"firstname": member.firstname,
|
||||
"lastname": member.lastname,
|
||||
"email": member.email,
|
||||
"room": member.uid,
|
||||
"room": member.uid,
|
||||
"token": user_token
|
||||
}
|
||||
|
||||
@@ -142,7 +193,6 @@ class AccountService(BaseService):
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def process_startprofile(data):
|
||||
try:
|
||||
@@ -161,21 +211,22 @@ class AccountService(BaseService):
|
||||
# Simulate processing
|
||||
member_data = {
|
||||
"member_id": member.id,
|
||||
"uid": str(uid),
|
||||
"uid": str(uid),
|
||||
"username": member.username,
|
||||
"account_name": member.account_name,
|
||||
"firstname":member.firstname,
|
||||
"firstname": member.firstname,
|
||||
"lastname": member.lastname,
|
||||
"email": member.email,
|
||||
"room": member.uid,
|
||||
"room": member.uid,
|
||||
"token": user_token
|
||||
}
|
||||
current_profile = MembersProfile.get_member_profile_by_member_id(member.id)
|
||||
if current_profile is not None:
|
||||
profile_uid=current_profile.uid
|
||||
profile_uid = current_profile.uid
|
||||
profile_completed = member.profile_completed
|
||||
else:
|
||||
profle_result = MembersProfile.create_member_profile(member.id, practice, specialization, introduction)
|
||||
profle_result = MembersProfile.create_member_profile(member.id, practice, specialization,
|
||||
introduction)
|
||||
if profle_result:
|
||||
profile_uid = profle_result.uid
|
||||
if profile_uid is not None and profile_uid != '':
|
||||
@@ -205,7 +256,6 @@ class AccountService(BaseService):
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def process_calendar(data):
|
||||
try:
|
||||
@@ -264,4 +314,4 @@ class AccountService(BaseService):
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
@@ -269,7 +269,7 @@ class SubscriptionsService(BaseService):
|
||||
paymentAddResult = Payments.add_payment(payment_data["member_id"], payment_data["payment_uid"], payment_data["option_name"],
|
||||
payment_data["amount"], payment_data["option_type"], payment_data["next_billing_days"])
|
||||
logger.info(f"HOOK paymentAddResult next_billing ==>>>> {paymentAddResult.next_billing}")
|
||||
logger.info(f"HOOK paymentAddResult uid ==>>>> {paymentAddResult.uid}")
|
||||
logger.info(f"HOOK paymentAddResult id ==>>>> {paymentAddResult.id}")
|
||||
logger.info(f"HOOK paymentAddResult payment_uid ==>>>> {paymentAddResult.payment_uid}")
|
||||
if paymentAddResult:
|
||||
Members.set_user_option_name(payment_data["member_id"], payment_data["option_name"])
|
||||
|
||||
@@ -24,6 +24,7 @@ class Members(db.Model):
|
||||
profile_completed = db.Column(db.DateTime(timezone=False))
|
||||
stripe_customer_id = db.Column(db.String(100), nullable=True)
|
||||
option_name = db.Column(db.String(100), nullable=True)
|
||||
next_billing= db.Column(db.DateTime(timezone=False))
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
@@ -43,6 +44,7 @@ class Members(db.Model):
|
||||
"firstname": self.firstname,
|
||||
"lastname": self.lastname,
|
||||
'option_name': self.option_name,
|
||||
"next_billing": self.next_billing,
|
||||
"stripe_customer_id": self.stripe_customer_id
|
||||
}
|
||||
|
||||
@@ -134,7 +136,7 @@ class Members(db.Model):
|
||||
member = cls.query.filter_by(id=member_id).first()
|
||||
if not member:
|
||||
raise ValueError(f"Member with ID {member_id} does not exist.")
|
||||
# Update stripe_customer_id
|
||||
# Update next_billing
|
||||
member.next_billing = next_billing
|
||||
|
||||
return next_billing
|
||||
|
||||
Reference in New Issue
Block a user