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
|
return False
|
||||||
|
|
||||||
def setup_webhook(self):
|
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)
|
self.log.info("Setting up webhook: {url}", url=settings.Revolut.WebhookURL)
|
||||||
headers = {"Authorization": f"Bearer {self.token}"}
|
headers = {"Authorization": f"Bearer {self.token}"}
|
||||||
data = {"url": settings.Revolut.WebhookURL}
|
data = {"url": settings.Revolut.WebhookURL}
|
||||||
r = requests.post(f"{settings.Revolut.Base}/webhook", data=dumps(data), headers=headers)
|
r = requests.post(f"{settings.Revolut.Base}/webhook", data=dumps(data), headers=headers)
|
||||||
if r.status_code == 204:
|
if r.status_code == 204:
|
||||||
self.log.info("Set up webhook: {url}", url=settings.Revolut.WebhookURL)
|
self.log.info("Set up webhook: {url}", url=settings.Revolut.WebhookURL)
|
||||||
return dumps({"success": True})
|
return True
|
||||||
else:
|
else:
|
||||||
parsed = r.json()
|
parsed = r.json()
|
||||||
self.log.info("Failed setting up webhook: {parsed}", parsed=parsed)
|
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