Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use in webhook with fastapi #36

Open
galhadida80 opened this issue Jan 9, 2023 · 1 comment
Open

how to use in webhook with fastapi #36

galhadida80 opened this issue Jan 9, 2023 · 1 comment

Comments

@galhadida80
Copy link

No description provided.

@ayushanand18
Copy link

Hey, you just need to expose and endpoint where your request payload is a Charge, something like below can help:

@app.post("/coinbase-payment")
async def coinbase_payment(request: Request) -> dict:
    """Handle Webhook Events from Coinbase Commerce"""
    payload = await request.body()
    signature = request.headers.get('X-CC-Webhook-Signature')
    try:
        # Validate the webhook payload and signature
        event = Webhook.construct_event(payload.decode(), signature, COINBASE_SECRET)
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e))

    # Handle specific event types
    if event.type == 'charge:confirmed':
        handle_charge_confirmed(event.data)
    elif event.type == 'charge:failed':
        handle_charge_failed(event.data)
    else:
        logging.info(f"Coinbase: Unhandled Event Type {event.type}")

    return JSONResponse(content={'status': 'success'})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants