feat: stirpe subscription re checkout
fix: other small changes
This commit is contained in:
parent
e6fbae493b
commit
4df268c8ac
|
|
@ -217,7 +217,7 @@ class AuthService:
|
|||
if not user:
|
||||
raise ResourceNotFoundException("User not found")
|
||||
|
||||
user.username = data.username.lower()
|
||||
user.username = data.username
|
||||
|
||||
self.db.add(user)
|
||||
self.db.commit()
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class MasterAppointmentServices:
|
|||
if existing_appointment_type and existing_appointment_type.id != appointment_type_id:
|
||||
raise ResourceNotFoundException("Appointment type already exists")
|
||||
|
||||
appointment_type_db.type = appointment_type.type
|
||||
appointment_type_db.type = appointment_type.type.lower()
|
||||
|
||||
self.db.add(appointment_type_db)
|
||||
self.db.commit()
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class StripeServices:
|
|||
self.db: Session = next(get_db())
|
||||
self.logger = logger
|
||||
self.webhook_secret = os.getenv("STRIPE_WEBHOOK_SECRET")
|
||||
self.redirect_url = os.getenv("FRONTEND_URL")
|
||||
self.dashboard_service = DashboardService()
|
||||
|
||||
async def create_customer(self, user_id: int, email: str, name: str):
|
||||
|
|
@ -214,8 +215,8 @@ class StripeServices:
|
|||
'payment_method_types': ['card'],
|
||||
'mode': 'subscription',
|
||||
'line_items': line_items,
|
||||
'success_url': 'http://54.79.156.66/',
|
||||
'cancel_url': 'http://54.79.156.66/',
|
||||
'success_url': self.redirect_url,
|
||||
'cancel_url': self.redirect_url,
|
||||
'metadata': metadata,
|
||||
'subscription_data': {
|
||||
'metadata': metadata
|
||||
|
|
@ -268,7 +269,13 @@ class StripeServices:
|
|||
self.logger.info("Async payment succeeded")
|
||||
|
||||
elif event["type"] == "checkout.session.completed":
|
||||
self.update_payment_log(event["data"]["object"]["metadata"]["unique_clinic_id"], event["data"]["object"]["metadata"]["clinic_id"])
|
||||
unique_clinic_id = event["data"]["object"]["metadata"]["unique_clinic_id"]
|
||||
clinic_id = event["data"]["object"]["metadata"]["clinic_id"]
|
||||
customer_id = event["data"]["object"]["metadata"]["customer_id"]
|
||||
account_id = event["data"]["object"]["metadata"]["account_id"]
|
||||
total = event["data"]["object"]["amount_total"]
|
||||
metadata = event["data"]["object"]["metadata"]
|
||||
self.update_payment_log(unique_clinic_id, clinic_id, customer_id, account_id, total, metadata)
|
||||
|
||||
# TODO: handle subscription period end
|
||||
|
||||
|
|
@ -280,17 +287,26 @@ class StripeServices:
|
|||
finally:
|
||||
self.db.close()
|
||||
|
||||
def update_payment_log(self, unique_clinic_id:str, clinic_id:int):
|
||||
def update_payment_log(self, unique_clinic_id:str, clinic_id:int, customer_id:str, account_id:str, total:float, metadata:any):
|
||||
try:
|
||||
payment_log = self.db.query(PaymentLogs).filter(PaymentLogs.unique_clinic_id == unique_clinic_id).first()
|
||||
self.db.query(PaymentSessions).filter(PaymentSessions.clinic_id == clinic_id).delete()
|
||||
if payment_log:
|
||||
payment_log.payment_status = "success"
|
||||
|
||||
payment_log = PaymentLogs(
|
||||
customer_id=customer_id,
|
||||
account_id=account_id,
|
||||
amount=total,
|
||||
clinic_id=clinic_id,
|
||||
unique_clinic_id=unique_clinic_id,
|
||||
payment_status="paid",
|
||||
metadata_logs=json.dumps(metadata.to_dict())
|
||||
)
|
||||
self.db.add(payment_log)
|
||||
self.db.commit()
|
||||
|
||||
clinic = self.db.query(Clinics).filter(Clinics.id == clinic_id).first()
|
||||
if clinic:
|
||||
clinic.status = ClinicStatus.UNDER_REVIEW
|
||||
self.db.add(clinic)
|
||||
self.db.commit()
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ class UserServices:
|
|||
fees_to_be["per_call_charges"] = offer.per_call_charges
|
||||
fees_to_be["total"] = offer.setup_fees + fees_to_be["subscription_fees"] + offer.per_call_charges
|
||||
|
||||
payment_link = await self.stripe_service.create_subscription_checkout(fees_to_be, 1, stripe_account.id,stripe_customer.id)
|
||||
payment_link = await self.stripe_service.create_subscription_checkout(fees_to_be, new_clinic.id, stripe_account.id,stripe_customer.id)
|
||||
|
||||
return payment_link.url
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Reference in New Issue