From 5b3db41c7865cb4ea45bf4222b45b721110bb0ac Mon Sep 17 00:00:00 2001 From: imbeer Date: Sat, 31 May 2025 18:31:45 +0300 Subject: [PATCH] try to fix yookassa payment id --- backend/subscription/service.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/subscription/service.py b/backend/subscription/service.py index fd284350..dda4113c 100644 --- a/backend/subscription/service.py +++ b/backend/subscription/service.py @@ -111,15 +111,15 @@ def handle_message_from_yookassa(data): def handle_success(response_object): subscription = get_subscription_from_webhook(response_object) metadata = response_object.metadata - payment = Payment.find_one(payment_id=response_object.payment_id) + payment = Payment.find_one(payment_id=response_object.id) if metadata.get('payment_type') == "initial_subscription": - subscription.activate(response_object.payment_id, payment.payment_method.id) + subscription.activate(response_object.id, payment.payment_method.id) logger.info(f"Initial subscription {subscription.subscription_id} activated") elif metadata.get('payment_type') == "reccurring_subscription": - subscription.renew_subscription(response_object.payment_id) + subscription.renew_subscription(response_object.id) logger.info(f"Initial subscription {subscription.subscription_id} updated") else: - raise YooKassaError(f"Payment type {response_object.event} not supported") + raise YooKassaError(f"Payment type {metadata.get('payment_type')} not supported") def handle_cancel(response_object): subscription = get_subscription_from_webhook(response_object) @@ -130,6 +130,8 @@ def handle_cancel(response_object): elif metadata.get('payment_type') == "reccurring_subscription": subscription.deactivate() logger.info(f"Initial subscription {subscription.subscription_id} deactivated, recurring payment canceled") + else: + raise YooKassaError(f"Payment type {metadata.get('payment_type')} not supported") def create_payment(subscription, description): return Payment.create({