Skip to content

Commit

Permalink
feat: POST to integrations settings API on onboarding completion
Browse files Browse the repository at this point in the history
(cherry picked from commit 8f9fe42)
  • Loading branch information
JustARatherRidiculouslyLongUsername committed Jan 31, 2025
1 parent a2da725 commit a8fbc6d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/fyle/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def post_request(url, body, refresh_token=None):
data=json.dumps(body)
)

if response.status_code == 200:
if response.status_code in (200, 201):
return json.loads(response.text)
else:
raise Exception(response.text)
Expand Down
3 changes: 2 additions & 1 deletion apps/workspaces/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from typing import Dict
from rest_framework import serializers
from apps.workspaces.tasks import post_to_integration_settings
from django_q.tasks import async_task
from django.core.cache import cache
from apps.mappings.models import QBDMapping
Expand Down Expand Up @@ -225,5 +226,5 @@ def create(self, validated_data):
workspace.onboarding_state = 'COMPLETE'
workspace.save()
async_task('apps.workspaces.tasks.async_create_admin_subcriptions', workspace_id)

post_to_integration_settings(workspace_id, True)
return advanced_setting
23 changes: 23 additions & 0 deletions apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,26 @@ def async_update_timestamp_in_qbd_direct(workspace_id: int) -> None:
raise Exception('Auth Token not present for workspace id {}'.format(workspace.id))
except Exception as e:
logger.error("Failed to sync timestamp to QBD Connector: {}".format(e))


def post_to_integration_settings(workspace_id: int, active: bool):
"""
Post to integration settings
"""
refresh_token = FyleCredential.objects.get(workspace_id=workspace_id).refresh_token
url = '{}/integrations/'.format(settings.INTEGRATIONS_SETTINGS_API)
payload = {
'tpa_id': settings.FYLE_CLIENT_ID,
'tpa_name': 'Fyle Quickbooks Desktop (IIF) Integration',
'type': 'ACCOUNTING',
'is_active': active,
'connected_at': datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')
}

try:
post_request(url, json.dumps(payload), refresh_token)
org_id = Workspace.objects.get(id=workspace_id).org_id
logger.info(f'New integration record: Fyle Quickbooks Desktop (IIF) Integration (ACCOUNTING) | {workspace_id = } | {org_id = }')

except Exception as error:
logger.error(error)
1 change: 1 addition & 0 deletions quickbooks_desktop_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
FYLE_TOKEN_URI = os.environ.get('FYLE_TOKEN_URI')
FYLE_CLIENT_ID = os.environ.get('FYLE_CLIENT_ID')
FYLE_CLIENT_SECRET = os.environ.get('FYLE_CLIENT_SECRET')
INTEGRATIONS_SETTINGS_API = os.environ.get('INTEGRATIONS_SETTINGS_API')

QBD_DIRECT_API_URL = os.environ.get('QBD_DIRECT_API_URL')

Expand Down
1 change: 1 addition & 0 deletions quickbooks_desktop_api/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
FYLE_TOKEN_URI = os.environ.get('FYLE_TOKEN_URI')
FYLE_CLIENT_ID = os.environ.get('FYLE_CLIENT_ID')
FYLE_CLIENT_SECRET = os.environ.get('FYLE_CLIENT_SECRET')
INTEGRATIONS_SETTINGS_API = os.environ.get('INTEGRATIONS_SETTINGS_API')

QBD_DIRECT_API_URL = os.environ.get('QBD_DIRECT_API_URL')

Expand Down

0 comments on commit a8fbc6d

Please sign in to comment.