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

Refactor: upgrade to version 0.3.0 of pywisetransfer #1285

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions apps/payments/wise.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from base64 import b64decode
import logging

from datetime import datetime, timedelta
from flask import abort, current_app as app, request
from pywisetransfer.webhooks import verify_signature
from pywisetransfer.webhooks import validate_request

from models.payment import BankAccount, BankTransaction
from . import payments
Expand Down Expand Up @@ -33,21 +32,11 @@ def wise_webhook():
request.headers,
)

environment = app.config["TRANSFERWISE_ENVIRONMENT"]
try:
b64decode(request.headers["X-Signature-SHA256"])
if request.json is None:
raise ValueError("Request does not contain JSON")
validate_request(request=request, environment=environment)
except Exception as e:
logger.info("Unable to parse Wise webhook request")
abort(400)

valid_signature = verify_signature(
request.data,
request.headers["X-Signature-SHA256"],
app.config["TRANSFERWISE_ENVIRONMENT"],
)
if not valid_signature:
logger.exception("Error verifying Wise webhook signature")
logger.info(e)
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
abort(400)

schema_version = request.json.get("schema_version")
Expand Down
Loading