Skip to content

Commit

Permalink
fix: if webhooks are already registered, add them to the settings (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alchez authored Jan 30, 2023
1 parent d16e76e commit 3dd3ef6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion shopify_integration/payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def create_shopify_payouts(shop_name: str, start_date: str = str()):
**{"shop_name": shop_name, "payout_id": payout.id},
)

frappe.db.set_value("Shopify Settings", shop_name, "last_sync_datetime", now())
shopify_settings.last_sync_datetime = now()
shopify_settings.save()


def create_shopify_payout(shop_name: str, payout_id: str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,24 @@ def register_webhooks(self):
SHOPIFY_WEBHOOK_TOPIC_MAPPER,
)

for topic in SHOPIFY_WEBHOOK_TOPIC_MAPPER:
with self.get_shopify_session(temp=True):
webhook = Webhook.create(
{"topic": topic, "address": get_webhook_url(), "format": "json"}
)

webhooks = []

try:
webhooks = self.get_webhooks()
except Exception as e:
make_shopify_log(
shop_name=self.name, status="Error", exception=e, rollback=True
)

if not webhooks:
for topic in SHOPIFY_WEBHOOK_TOPIC_MAPPER:
with self.get_shopify_session(temp=True):
webhooks.append(Webhook.create(
{"topic": topic, "address": get_webhook_url(), "format": "json"}
))

webhook: Webhook
for webhook in webhooks:
if webhook.is_valid():
self.append(
"webhooks", {"webhook_id": webhook.id, "method": webhook.topic}
Expand Down

0 comments on commit 3dd3ef6

Please sign in to comment.