Check before setting up Revolut callback URL
This commit is contained in:
parent
480e1298cd
commit
18aecc216a
|
@ -99,13 +99,25 @@ class Revolut(object):
|
|||
return False
|
||||
|
||||
def setup_webhook(self):
|
||||
webhooks = self.get_webhooks()
|
||||
if "url" in webhooks.keys():
|
||||
if webhooks["url"] == settings.Revolut.WebhookURL:
|
||||
self.log.info("Webhook exists - skipping setup: {url}", url=webhooks["url"])
|
||||
return True # Webhook already exists
|
||||
self.log.info("Setting up webhook: {url}", url=settings.Revolut.WebhookURL)
|
||||
headers = {"Authorization": f"Bearer {self.token}"}
|
||||
data = {"url": settings.Revolut.WebhookURL}
|
||||
r = requests.post(f"{settings.Revolut.Base}/webhook", data=dumps(data), headers=headers)
|
||||
if r.status_code == 204:
|
||||
self.log.info("Set up webhook: {url}", url=settings.Revolut.WebhookURL)
|
||||
return dumps({"success": True})
|
||||
return True
|
||||
else:
|
||||
parsed = r.json()
|
||||
self.log.info("Failed setting up webhook: {parsed}", parsed=parsed)
|
||||
|
||||
def get_webhooks(self):
|
||||
headers = {"Authorization": f"Bearer {self.token}"}
|
||||
r = requests.get(f"{settings.Revolut.Base}/webhook", headers=headers)
|
||||
if r.status_code == 200:
|
||||
parsed = r.json()
|
||||
return parsed
|
||||
|
|
Loading…
Reference in New Issue