Fix payment webhook
This commit is contained in:
parent
f05e663a10
commit
f96ec74176
@ -19,6 +19,7 @@ export DOCKER_BACKEND_HOME=$DOCKER_APP_HOME/$APP_NAME
|
||||
export DOCKER_BACKEND_LOG_HOME=$DOCKER_BACKEND_HOME/log
|
||||
export MONGODB_URI=mongodb://localhost:27017/
|
||||
export FREELEAPS_ENV=local
|
||||
export SITE_URL_ROOT=http://localhost/
|
||||
export SITE_URL_ROOT=http://localhost:5173/
|
||||
export LOG_BASE_PATH=${CODEBASE_ROOT}/log
|
||||
export STRIPE_API_KEY=sk_test_51Ogsw5B0IyqaSJBrwczlr820jnmvA1qQQGoLZ2XxOsIzikpmXo4pRLjw4XVMTEBR8DdVTYySiAv1XX53Zv5xqynF00GfMqttFd
|
||||
export STRIPE_WEBHOOK_SECRET=whsec_59191b39e20582f0a7eafa7370613ffdaf848fb94d6617493a806d9d2a00ed63
|
||||
|
||||
@ -79,10 +79,10 @@ class PaymentHub:
|
||||
return await self.stripe_manager.fetch_checkout_session_url(transaction_id)
|
||||
|
||||
async def invoke_checkout_session_webhook(
|
||||
self, payload: str, stripe_signature: str
|
||||
self, event: dict
|
||||
) -> Tuple[bool, Optional[str], Optional[str]]:
|
||||
return await self.stripe_manager.invoke_checkout_session_webhook(
|
||||
payload, stripe_signature
|
||||
event
|
||||
)
|
||||
|
||||
async def handle_account_update(
|
||||
|
||||
@ -322,30 +322,16 @@ class StripeManager:
|
||||
return None
|
||||
|
||||
async def invoke_checkout_session_webhook(
|
||||
self, payload: str, stripe_signature: str
|
||||
self, event: dict
|
||||
) -> Tuple[bool, Optional[str], Optional[str]]:
|
||||
try:
|
||||
event = stripe.Webhook.construct_event(
|
||||
payload, stripe_signature, app_settings.STRIPE_WEBHOOK_SECRET
|
||||
)
|
||||
except ValueError as e:
|
||||
await self.module_logger.log_exception(exception=e, text="Invalid payload")
|
||||
|
||||
return False, None, None
|
||||
except SignatureVerificationError as e:
|
||||
await self.module_logger.log_exception(
|
||||
exception=e, text="Invalid signature"
|
||||
)
|
||||
return False, None, None
|
||||
|
||||
# Handle the checkout.session.completed event
|
||||
if event["type"] == "checkout.session.completed":
|
||||
session = event["data"]["object"]
|
||||
transaction = await self.__fetch_transaction_by_session_id(session.id)
|
||||
transaction = await self.__fetch_transaction_by_session_id(session["id"])
|
||||
if not transaction:
|
||||
await self.module_logger.log_error(
|
||||
error="Transaction not found for session_id: {}".format(session.id),
|
||||
properties={"session_id": session.id},
|
||||
error="Transaction not found for session_id: {}".format(session["id"]),
|
||||
properties={"session_id": session["id"]},
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
@ -184,8 +184,8 @@ async def fetch_checkout_session_url(transaction_id: str) -> Optional[str]:
|
||||
summary="Invoke checkout session webhook",
|
||||
description="Invoke checkout session webhook",
|
||||
)
|
||||
async def invoke_checkout_session_webhook(payload: str, stripe_signature: str):
|
||||
return await payment_hub.invoke_checkout_session_webhook(payload, stripe_signature)
|
||||
async def invoke_checkout_session_webhook(event: dict):
|
||||
return await payment_hub.invoke_checkout_session_webhook(event)
|
||||
|
||||
|
||||
@router.post(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user