-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikolay Poluhin
committed
Aug 11, 2023
1 parent
65895ed
commit 7300539
Showing
17 changed files
with
200 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
declare module '*.svg'; | ||
declare module '*.png'; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,4 @@ export enum StatusEnum { | |
done = 'done', | ||
error = 'error', | ||
canceled = 'canceled', | ||
unknown = 'unknown', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export const headlessCheckoutAppUrl = | ||
'https://secure.xsolla.com/headless-checkout'; | ||
export const headlessCheckoutAppUrl = 'http://localhost:4200'; | ||
export const cdnUrl = 'https://cdn3.xsolla.com'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/features/headless-checkout/web-components/legal/secure-connection.component.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/features/headless-checkout/web-components/status/status.component.config.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface StatusComponentConfig { | ||
title: string; | ||
image: string | null; | ||
description: string; | ||
showDescription: boolean; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/features/headless-checkout/web-components/status/status.component.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { StatusComponentConfig } from './status.component.config.interface'; | ||
|
||
export const getStatusComponentTemplate = ( | ||
statusConfig: StatusComponentConfig | ||
): string => { | ||
return ` | ||
<div class="status"> | ||
${ | ||
statusConfig.image | ||
? ` | ||
<div class="image-container"> | ||
<img class="image" src="${statusConfig.image}" alt="${statusConfig.title}" /> | ||
</div>` | ||
: '' | ||
} | ||
<div class="title"> | ||
<h2 class="title-text">${statusConfig.title}</h2> | ||
</div> | ||
${ | ||
statusConfig.showDescription | ||
? `<p class="description">${statusConfig.description}</p>` | ||
: '' | ||
} | ||
</div> | ||
`; | ||
}; |
105 changes: 105 additions & 0 deletions
105
src/features/headless-checkout/web-components/status/status.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { container } from 'tsyringe'; | ||
import i18next from 'i18next'; | ||
import { WebComponentAbstract } from '../../../../core/web-components/web-component.abstract'; | ||
import { Status } from '../../../../core/status/status.interface'; | ||
import { StatusEnum } from '../../../../core/status/status.enum'; | ||
import { HeadlessCheckout } from '../../headless-checkout'; | ||
import { getStatusComponentTemplate } from './status.component.template'; | ||
import { StatusComponentConfig } from './status.component.config.interface'; | ||
import successImage from '../../../../assets/statuses/success.png'; | ||
import failedImage from '../../../../assets/statuses/failed.png'; | ||
|
||
export class StatusComponent extends WebComponentAbstract { | ||
private readonly headlessCheckout: HeadlessCheckout; | ||
|
||
private statusConfig: StatusComponentConfig | null = null; | ||
|
||
public constructor() { | ||
super(); | ||
|
||
this.headlessCheckout = container.resolve(HeadlessCheckout); | ||
} | ||
|
||
protected connectedCallback(): void { | ||
void this.getStatus(); | ||
|
||
this.headlessCheckout.form.onNextAction((nextAction) => { | ||
if (nextAction.type === 'status_updated') { | ||
void this.getStatus(); | ||
} | ||
}); | ||
} | ||
|
||
protected getHtml(): string { | ||
if (this.statusConfig) { | ||
return getStatusComponentTemplate(this.statusConfig); | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
private statusLoadedHandler( | ||
statusConfig: StatusComponentConfig | null | ||
): void { | ||
this.statusConfig = statusConfig; | ||
|
||
this.render(); | ||
} | ||
|
||
private async getStatus(): Promise<void> { | ||
const status = await this.headlessCheckout.getStatus(); | ||
|
||
const statusConfig = this.getStatusConfig(status); | ||
|
||
this.statusLoadedHandler(statusConfig); | ||
} | ||
|
||
private getStatusConfig(status: Status): StatusComponentConfig | null { | ||
if (!status) { | ||
return null; | ||
} | ||
|
||
const isProcessing = [ | ||
StatusEnum.processing, | ||
StatusEnum.created, | ||
StatusEnum.held, | ||
].includes(status.statusState); | ||
const isError = | ||
[StatusEnum.canceled, StatusEnum.error].includes(status.statusState) || | ||
status.isCancelUser; | ||
const isSuccess = | ||
status.statusState === StatusEnum.done ?? | ||
status.statusState === StatusEnum.authorized; | ||
|
||
if (isProcessing) { | ||
return { | ||
image: null, | ||
title: i18next.t('status.processing.title'), | ||
description: i18next.t('status.processing.description'), | ||
showDescription: true, | ||
}; | ||
} | ||
|
||
if (isError) { | ||
return { | ||
image: failedImage, | ||
title: i18next.t('status.error.title'), | ||
description: '', | ||
showDescription: false, | ||
}; | ||
} | ||
|
||
if (isSuccess) { | ||
return { | ||
image: successImage, | ||
title: i18next.t('status.success.title'), | ||
description: i18next.t('status.success.description', { | ||
email: status.email, | ||
}), | ||
showDescription: !!status.email, | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters