Skip to content

Commit

Permalink
business central oauth url setting (#384)
Browse files Browse the repository at this point in the history
business central oauth url setting
  • Loading branch information
DhaaraniCIT authored Jan 9, 2024
1 parent 23554b3 commit 13b42ee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { environment } from "src/environments/environment";
export type BusinessCentralConnector = {
code: string;
callback_url: string;
workspace: number
}

export interface BusinessCentralConnectorPost extends BusinessCentralConnector {}

export class BusinessCentralConnectorModel {
static constructPayload(code: string): BusinessCentralConnectorPost {
static constructPayload(code: string, workspaceId: number): BusinessCentralConnectorPost {
return {
code,
callback_url: `${environment.business_central_oauth_redirect_uri}`
callback_url: `${environment.business_central_oauth_redirect_uri}`,
workspace: workspaceId
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class BusinessCentralConnectorService {
cacheBusterObserver: businessCentralCredentialsCache$
})
getBusinessCentralCredentials(): Observable<BusinessCentralCredential> {
return this.apiService.get(`/workspaces/${this.workspaceId}/credentials/business_central/`, {});
return this.apiService.get(`/workspaces/${this.workspaceService.getWorkspaceId()}/credentials/business_central/`, {});
}

@Cacheable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,19 @@ export class BusinessCentralOnboardingConnectorComponent implements OnInit, OnDe

connectBusinessCentral(): void {
this.businessCentralConnectionInProgress = true;
const url = `${environment.business_central_authorize_uri}client_id=${environment.business_central_oauth_client_id}&scope=com.intuit.quickbooks.accounting&response_type=code&redirect_uri=${environment.business_central_oauth_redirect_uri}&state=business_central_local_redirect`;
const url = `${environment.business_central_authorize_uri}client_id=${environment.business_central_oauth_client_id}&redirect_uri=${environment.business_central_oauth_redirect_uri}&state=business_central_local_redirect&response_type=code`;

this.oauthCallbackSubscription = this.helperService.oauthCallbackUrl.subscribe((callbackURL: string) => {
const code = callbackURL.split('code=')[1].split('&')[0];
this.postBusinessCentralCredentials(code);
});

this.helperService.oauthHandler(url);
}

save(): void {
// TODO
}

acceptWarning(data: ConfigurationWarningOut): void {
this.isIncorrectBusinessCentralConnectedDialogVisible = false;
if (data.hasAccepted) {
this.router.navigate([`/integrations/business_central/onboarding/landing`]);
this.router.navigate([`/integrations/business_central/onboarding/connector`]);
}
}

Expand All @@ -124,7 +119,7 @@ export class BusinessCentralOnboardingConnectorComponent implements OnInit, OnDe
}

private postBusinessCentralCredentials(code: string): void {
const payload: BusinessCentralConnectorPost = BusinessCentralConnectorModel.constructPayload(code);
const payload: BusinessCentralConnectorPost = BusinessCentralConnectorModel.constructPayload(code, +this.workspaceService.getWorkspaceId());

this.businessCentralConnectorService.connectBusinessCentral(payload).subscribe((businessCentralCredential: BusinessCentralCredential) => {
this.businessCentralConnectorService.getBusinessCentralCompany().subscribe((businessCentralCompanyDetails: BusinessCentralCompanyDetails) => {
Expand All @@ -138,7 +133,7 @@ export class BusinessCentralOnboardingConnectorComponent implements OnInit, OnDe
});
});
}, (error) => {
const errorMessage = 'message' in error.error ? error.error.message : 'Failed to connect to Dynamic 360 Business Central. Please try again';
const errorMessage = 'message' in error ? error.message : 'Failed to connect to Dynamic 360 Business Central. Please try again';
if (errorMessage === 'Please choose the correct Dynamic 360 Business Central account') {
this.isIncorrectBusinessCentralConnectedDialogVisible = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div *ngIf="!isIncorrectQBOConnectedDialogVisible">
<p (click)="connectBusinessCentral()">Connect QBO Button will be added somewhere in this page</p>
<div>
<app-landing-page-header [logoWidth]="'65px'" [logoStyleClasses]="'tw-p-0'" [logoSectionStyleClasses]="''" [iconPath]="'assets/logos/BusinessCentral-logo.svg'" [appName]="'Dynamics 365 Business Central'" [appDescription]="'Import data from Dynamics 365 Business Central to ' + brandingConfig.brandName + ' and Export expenses from ' + brandingConfig.brandName + ' to Dynamics 365 Business Central. '" [isLoading]="false" [isIntegrationSetupInProgress]="businessCentralConnectionInProgress" [isIntegrationConnected]="isIntegrationConnected" [redirectLink]="redirectLink" [buttonText]="'Connect'" [postConnectionRoute]="'business_central/onboarding/connector'" (connectIntegration)="connectBusinessCentral()"></app-landing-page-header>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ export class BusinessCentralOnboardingLandingComponent implements OnInit, OnDest

connectBusinessCentral(): void {
this.businessCentralConnectionInProgress = true;
const url = `${environment.business_central_authorize_uri}?client_id=${environment.business_central_oauth_client_id}&scope=com.intuit.quickbooks.accounting&response_type=code&redirect_uri=${environment.business_central_oauth_redirect_uri}&state=business_central_local_redirect`;
const url = `${environment.business_central_authorize_uri}client_id=${environment.business_central_oauth_client_id}&redirect_uri=${environment.business_central_oauth_redirect_uri}&state=business_central_local_redirect&response_type=code`;

this.oauthCallbackSubscription = this.helperService.oauthCallbackUrl.subscribe((callbackURL: string) => {
const code = callbackURL.split('code=')[1].split('&')[0];
this.checkProgressAndRedirect(code);
this.postBusinessCentralCredentials(code);
});

this.helperService.oauthHandler(url);
}

private postBusinessCentralCredentials(code: string): void {
const payload: BusinessCentralConnectorPost = BusinessCentralConnectorModel.constructPayload(code);
const payload: BusinessCentralConnectorPost = BusinessCentralConnectorModel.constructPayload(code, +this.workspaceService.getWorkspaceId());

this.businessCentralConnectorService.connectBusinessCentral(payload).subscribe(() => {
this.businessCentralConnectionInProgress = false;
Expand Down

0 comments on commit 13b42ee

Please sign in to comment.