-
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.
feat(PAYMENTS-19009): add xsolla-number component
- Loading branch information
1 parent
6787c68
commit c622fdf
Showing
34 changed files
with
1,074 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Action } from './action.interface'; | ||
|
||
export type ShowCashPaymentActionType = 'show_cash_payment_instruction'; | ||
|
||
export type ShowCashPaymentAction = Action<ShowCashPaymentActionType, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface CashPaymentData { | ||
isCashPaymentMethod: boolean; | ||
xsollaNumber: string; | ||
pid: number; | ||
publicId: string; | ||
title: string; | ||
projectName: string; | ||
printUrl: string; | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/core/guards/get-cash-payment-data/get-cash-payment-data-event-message.guard.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,13 @@ | ||
import { Message } from '../../message.interface'; | ||
import { CashPaymentData } from '../../cash-payment-data.interface'; | ||
import { isEventMessage } from '../event-message.guard'; | ||
import { EventName } from '../../event-name.enum'; | ||
|
||
export const isGetCashPaymentDataEventMessage = ( | ||
messageData: unknown, | ||
): messageData is Message<CashPaymentData | null | undefined> => { | ||
if (isEventMessage(messageData)) { | ||
return messageData.name === EventName.getCashPaymentData; | ||
} | ||
return false; | ||
}; |
13 changes: 13 additions & 0 deletions
13
src/core/guards/send-cash-payment-data-status/send-cash-payment-data-event-message.guard.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,13 @@ | ||
import { Message } from '../../message.interface'; | ||
import { isEventMessage } from '../event-message.guard'; | ||
import { EventName } from '../../event-name.enum'; | ||
import { SendCashPaymentDataStatus } from '../../send-cash-payment-data-status.interface'; | ||
|
||
export const isSentCashPaymentDataStatus = ( | ||
messageData: unknown, | ||
): messageData is Message<SendCashPaymentDataStatus | null | undefined> => { | ||
if (isEventMessage(messageData)) { | ||
return messageData.name === EventName.sendCashPaymentDataStatus; | ||
} | ||
return false; | ||
}; |
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,5 @@ | ||
export interface SendCashPaymentDataStatus { | ||
status: 'succeed' | 'failed'; | ||
type: 'sms' | 'email'; | ||
errors: string[]; | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...eckout/post-messages-handlers/get-cash-payment-data/get-cash-payment-data.handler.spec.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,21 @@ | ||
import { EventName } from '../../../../core/event-name.enum'; | ||
import { Message } from '../../../../core/message.interface'; | ||
import { getCashPaymentDataHandler } from './get-cash-payment-data.handler'; | ||
|
||
const mockMessage: Message = { | ||
name: EventName.getCashPaymentData, | ||
}; | ||
describe('getCashPaymentDataHandler', () => { | ||
it('should handle status', () => { | ||
expect(getCashPaymentDataHandler(mockMessage)).toEqual({ | ||
isHandled: true, | ||
value: undefined, | ||
}); | ||
}); | ||
|
||
it('should return null', () => { | ||
expect( | ||
getCashPaymentDataHandler({ name: EventName.getPaymentMethodsList }), | ||
).toBeNull(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...ss-checkout/post-messages-handlers/get-cash-payment-data/get-cash-payment-data.handler.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,18 @@ | ||
import { Handler } from '../../../../core/post-messages-client/handler.type'; | ||
import { Message } from '../../../../core/message.interface'; | ||
import { CashPaymentType } from '../../web-components/cash-payment-instruction/cash-payment.type'; | ||
import { isGetCashPaymentDataEventMessage } from '../../../../core/guards/get-cash-payment-data/get-cash-payment-data-event-message.guard'; | ||
|
||
export const getCashPaymentDataHandler: Handler<CashPaymentType | null> = ( | ||
message: Message, | ||
): { isHandled: boolean; value: CashPaymentType | null | undefined } | null => { | ||
if (!isGetCashPaymentDataEventMessage(message)) { | ||
return null; | ||
} | ||
|
||
const cashPaymentData = message.data; | ||
return { | ||
isHandled: true, | ||
value: cashPaymentData, | ||
}; | ||
}; |
23 changes: 23 additions & 0 deletions
23
...ages-handlers/send-cash-payment-data-status/send-cash-payment-data-status.handler.spec.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,23 @@ | ||
import { EventName } from '../../../../core/event-name.enum'; | ||
import { Message } from '../../../../core/message.interface'; | ||
import { sendCashPaymentDataStatusHandler } from './send-cash-payment-data-status.handler'; | ||
|
||
const mockMessage: Message = { | ||
name: EventName.sendCashPaymentDataStatus, | ||
}; | ||
describe('sendCashPaymentDataStatusHandler', () => { | ||
it('should handle status', () => { | ||
expect(sendCashPaymentDataStatusHandler(mockMessage)).toEqual({ | ||
isHandled: true, | ||
value: undefined, | ||
}); | ||
}); | ||
|
||
it('should return null', () => { | ||
expect( | ||
sendCashPaymentDataStatusHandler({ | ||
name: EventName.getPaymentMethodsList, | ||
}), | ||
).toBeNull(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
...-messages-handlers/send-cash-payment-data-status/send-cash-payment-data-status.handler.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,23 @@ | ||
import { Handler } from '../../../../core/post-messages-client/handler.type'; | ||
import { Message } from '../../../../core/message.interface'; | ||
import { isSentCashPaymentDataStatus } from '../../../../core/guards/send-cash-payment-data-status/send-cash-payment-data-event-message.guard'; | ||
import { SendCashPaymentDataStatus } from '../../../../core/send-cash-payment-data-status.interface'; | ||
|
||
export const sendCashPaymentDataStatusHandler: Handler< | ||
SendCashPaymentDataStatus | null | undefined | ||
> = ( | ||
message: Message, | ||
): { | ||
isHandled: boolean; | ||
value: SendCashPaymentDataStatus | null | undefined; | ||
} | null => { | ||
if (!isSentCashPaymentDataStatus(message)) { | ||
return null; | ||
} | ||
|
||
const cashPaymentData = message.data; | ||
return { | ||
isHandled: true, | ||
value: cashPaymentData, | ||
}; | ||
}; |
87 changes: 87 additions & 0 deletions
87
...eckout/web-components/cash-payment-instruction/cash-payment-instruction.component.spec.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,87 @@ | ||
import { container } from 'tsyringe'; | ||
import { WebComponentTagName } from '../../../../core/web-components/web-component-tag-name.enum'; | ||
import { noopStub } from '../../../../tests/stubs/noop.stub'; | ||
import { FormSpy } from '../../../../core/spy/form-spy/form-spy'; | ||
import { PostMessagesClient } from '../../../../core/post-messages-client/post-messages-client'; | ||
import { CashPaymentData } from '../../../../core/cash-payment-data.interface'; | ||
import { CashPaymentInstructionComponent } from './cash-payment-instruction.component'; | ||
import { timeout } from '../../../../tests/stubs/timeout'; | ||
|
||
function createComponent(): void { | ||
const element = document.createElement( | ||
WebComponentTagName.CashPaymentInstructionComponent, | ||
); | ||
(document.getElementById('container')! as HTMLElement).appendChild(element); | ||
} | ||
|
||
const cashPaymentData = { | ||
isCashPaymentMethod: false, | ||
} as CashPaymentData; | ||
|
||
describe('CashPaymentInstructionComponent', () => { | ||
let formSpy: FormSpy; | ||
let postMessagesClient: PostMessagesClient; | ||
|
||
window.customElements.define( | ||
WebComponentTagName.CashPaymentInstructionComponent, | ||
CashPaymentInstructionComponent, | ||
); | ||
|
||
beforeEach(() => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
|
||
postMessagesClient = { | ||
init: noopStub, | ||
send: noopStub, | ||
listen: noopStub, | ||
} as unknown as PostMessagesClient; | ||
|
||
formSpy = { | ||
listenFormInit: noopStub, | ||
get formWasInit() { | ||
return; | ||
}, | ||
} as unknown as FormSpy; | ||
|
||
container.clearInstances(); | ||
|
||
container | ||
.register<FormSpy>(FormSpy, { | ||
useValue: formSpy, | ||
}) | ||
.register<PostMessagesClient>(PostMessagesClient, { | ||
useValue: postMessagesClient, | ||
}) | ||
.register<Window>(Window, { useValue: window }); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
it('Should draw cash payment component', () => { | ||
spyOnProperty(formSpy, 'formWasInit').and.returnValue(true); | ||
spyOn(postMessagesClient, 'send').and.returnValue(Promise.resolve(null)); | ||
createComponent(); | ||
expect( | ||
document.querySelector( | ||
WebComponentTagName.CashPaymentInstructionComponent, | ||
)!.innerHTML, | ||
).not.toContain(WebComponentTagName.XsollaNumberComponent); | ||
}); | ||
|
||
it('Should draw XsollaNumberComponent', async () => { | ||
spyOnProperty(formSpy, 'formWasInit').and.returnValue(true); | ||
spyOn(postMessagesClient, 'send').and.returnValue( | ||
Promise.resolve(cashPaymentData), | ||
); | ||
createComponent(); | ||
const delay = 100; | ||
await timeout(delay); | ||
expect( | ||
document.querySelector( | ||
WebComponentTagName.CashPaymentInstructionComponent, | ||
)!.innerHTML, | ||
).toContain(WebComponentTagName.XsollaNumberComponent); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
...ss-checkout/web-components/cash-payment-instruction/cash-payment-instruction.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,56 @@ | ||
import { container } from 'tsyringe'; | ||
import { FormSpy } from '../../../../core/spy/form-spy/form-spy'; | ||
import { EventName } from '../../../../core/event-name.enum'; | ||
import { PostMessagesClient } from '../../../../core/post-messages-client/post-messages-client'; | ||
import { Message } from '../../../../core/message.interface'; | ||
import { getCashPaymentDataHandler } from '../../post-messages-handlers/get-cash-payment-data/get-cash-payment-data.handler'; | ||
import { CashPaymentData } from '../../../../core/cash-payment-data.interface'; | ||
import { CashPaymentType } from './cash-payment.type'; | ||
import { WebComponentAbstract } from '../../../../core/web-components/web-component.abstract'; | ||
import { WebComponentTagName } from '../../../../core/web-components/web-component-tag-name.enum'; | ||
|
||
export class CashPaymentInstructionComponent extends WebComponentAbstract { | ||
private readonly formSpy: FormSpy; | ||
private readonly postMessagesClient: PostMessagesClient; | ||
private cashPaymentData?: CashPaymentData | null; | ||
public constructor() { | ||
super(); | ||
this.formSpy = container.resolve(FormSpy); | ||
this.postMessagesClient = container.resolve(PostMessagesClient); | ||
} | ||
|
||
protected connectedCallback(): void { | ||
if (!this.formSpy.formWasInit) { | ||
this.formSpy.listenFormInit(() => this.connectedCallback()); | ||
return; | ||
} | ||
|
||
void this.getCashPaymentData().then(this.configLoadedHandler); | ||
} | ||
|
||
protected getHtml(): string { | ||
if (this.cashPaymentData?.isCashPaymentMethod) { | ||
return ''; | ||
} | ||
|
||
return `<${WebComponentTagName.XsollaNumberComponent}></${WebComponentTagName.XsollaNumberComponent}>`; | ||
} | ||
|
||
private async getCashPaymentData(): Promise<CashPaymentType> { | ||
const msg: Message = { | ||
name: EventName.getCashPaymentData, | ||
}; | ||
|
||
return this.postMessagesClient.send<CashPaymentType>( | ||
msg, | ||
getCashPaymentDataHandler, | ||
) as Promise<CashPaymentType>; | ||
} | ||
|
||
private readonly configLoadedHandler = ( | ||
cashPaymentData: CashPaymentType, | ||
): void => { | ||
this.cashPaymentData = cashPaymentData; | ||
super.render(); | ||
}; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/features/headless-checkout/web-components/cash-payment-instruction/cash-payment.type.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,3 @@ | ||
import { CashPaymentData } from '../../../../core/cash-payment-data.interface'; | ||
|
||
export type CashPaymentType = CashPaymentData | null; |
4 changes: 4 additions & 0 deletions
4
src/features/headless-checkout/web-components/xsolla-number/send-button-status.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,4 @@ | ||
export interface SendButtonStatus { | ||
channelType: 'phone' | 'email'; | ||
isDisabled: boolean; | ||
} |
28 changes: 28 additions & 0 deletions
28
...ures/headless-checkout/web-components/xsolla-number/templates/get-instruction.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 i18next from 'i18next'; | ||
|
||
export const getInstructionTemplate = ( | ||
paymentMethodName: string, | ||
projectName?: string, | ||
): string => { | ||
return `<div class='instruction-wrapper'> | ||
<h3 class="title">${i18next.t('xsolla-number.instruction.how-to')}</h3> | ||
<ul class="instruction"> | ||
<li class="paragraph">${i18next.t('xsolla-number.instruction.paragraph-one', { | ||
paymentMethodName, | ||
})}</li> | ||
<li class="paragraph"> | ||
${i18next.t('xsolla-number.instruction.paragraph-two', { projectName })} | ||
</li> | ||
<li class="paragraph"> | ||
${i18next.t('xsolla-number.instruction.paragraph-three')} | ||
</li> | ||
<li class="paragraph"> | ||
${i18next.t('xsolla-number.instruction.paragraph-four')} | ||
</li> | ||
</ul> | ||
<p class='notifier'> | ||
${i18next.t('xsolla-number.instruction.notification')} | ||
</p> | ||
</div>`; | ||
}; |
Oops, something went wrong.