auto recurring testing phase 19

This commit is contained in:
rizwanisready
2024-08-02 15:30:19 +05:30
parent 9ef1593f33
commit 1711af39bc
2 changed files with 12 additions and 16 deletions

View File

@@ -131,9 +131,6 @@ class WebhookService:
logger.error(f"Invalid subscription ID: {subscription_id}")
raise ValueError(f"Invalid subscription ID: {subscription_id}")
def get_stripe_subscription(self):
return self.charge_data.get("subscription")
def get_order_id(self):
return self.charge_data["metadata"]["order_id"]
@@ -292,7 +289,7 @@ class SubscriptionService:
class PaymentProcessingService:
def __init__(self, webhook_data, current_period_start, current_period_end):
def __init__(self, webhook_data, stripe_subscription, current_period_start, current_period_end):
self.webhook_service = WebhookService(webhook_data)
self.notification_service = NotificationService()
self.current_period_start = current_period_start
@@ -301,7 +298,7 @@ class PaymentProcessingService:
self.principal = self.webhook_service.get_principal()
self.transaction = self.webhook_service.get_transaction()
self.subscription = self.webhook_service.get_subscription()
self.stripe_subscription = self.webhook_service.get_stripe_subscription()
self.stripe_subscription = stripe_subscription
self.order_id = self.webhook_service.get_order_id()
self.coupon = self.webhook_service.get_coupon()
self.subscription_service = SubscriptionService()

View File

@@ -179,17 +179,7 @@ class StripeWebhookTest(APIView):
event_id = event["id"]
event_type = event["type"]
# principal_id = event["data"]["object"]["metadata"]["principal"]
stripe_subscription_id = stripe.Subscription.retrieve(
event["data"]["object"]["metadata"]["subscription"]
)
webhook_event, created = WebhookEvent.objects.get_or_create(
event_id=event_id,
defaults={
"event_type": event_type,
"event_payload": json.loads(payload),
},
)
stripe_subscription_id = event["data"]["object"].get("subscription")
if stripe_subscription_id:
stripe_subscription = stripe.Subscription.retrieve(stripe_subscription_id)
@@ -199,6 +189,14 @@ class StripeWebhookTest(APIView):
current_period_start = None
current_period_end = None
webhook_event, created = WebhookEvent.objects.get_or_create(
event_id=event_id,
defaults={
"event_type": event_type,
"event_payload": json.loads(payload),
},
)
if not created and webhook_event.status == "processed":
return ApiResponse.success(
status=status.HTTP_208_ALREADY_REPORTED,
@@ -207,6 +205,7 @@ class StripeWebhookTest(APIView):
payment_service = PaymentProcessingService(
webhook_data=event,
stripe_subscription=stripe_subscription_id,
current_period_start=current_period_start,
current_period_end=current_period_end,
)