-
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 7, 2023
1 parent
42692f6
commit e2da1ac
Showing
10 changed files
with
188 additions
and
19 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
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,19 @@ | ||
import { EventName } from '../event-name.enum'; | ||
import { isGetPaymentStatusMessage } from './get-payment-status-message.guard'; | ||
|
||
describe('GetPaymentStatus event message guard', () => { | ||
it('Should return true', () => { | ||
const isCorrectEvent = isGetPaymentStatusMessage({ | ||
name: EventName.getPaymentStatus, | ||
}); | ||
|
||
expect(isCorrectEvent).toBeTruthy(); | ||
}); | ||
it('Should return false', () => { | ||
const isWrongEvent = isGetPaymentStatusMessage({ | ||
name: EventName.initPayment, | ||
}); | ||
|
||
expect(isWrongEvent).toBeFalsy(); | ||
}); | ||
}); |
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,14 @@ | ||
import { Message } from '../message.interface'; | ||
import { Status } from '../status/status.interface'; | ||
import { isEventMessage } from './event-message.guard'; | ||
import { EventName } from '../event-name.enum'; | ||
|
||
export const isGetPaymentStatusMessage = ( | ||
messageData: unknown | ||
): messageData is Message<Status> => { | ||
if (isEventMessage(messageData)) { | ||
return messageData.name === EventName.getPaymentStatus; | ||
} | ||
|
||
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,11 @@ | ||
export enum StatusEnum { | ||
created = 'created', | ||
awaiting = 'awaiting', | ||
processing = 'processing', | ||
authorized = 'authorized', | ||
held = 'held', | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { StatusEnum } from './status.enum'; | ||
import { TitleClass } from './title-class.enum'; | ||
|
||
export interface Status { | ||
statusState: StatusEnum; | ||
statusMessage: string; | ||
group: string; | ||
postMessageStatus?: string; | ||
virtualCurrencyAmount?: number; | ||
email?: string; | ||
financeInfo?: { | ||
[key: string]: { | ||
key?: string; | ||
pref?: string; | ||
value?: string; | ||
}; | ||
}; | ||
isCancelUser?: boolean; | ||
backUrlSettings?: { | ||
backUrl: string; | ||
backUrlAction?: string; | ||
backUrlCaption: string; | ||
returnRegion: string; | ||
showBackButton?: boolean; | ||
}; | ||
additionalBackButton?: { | ||
link: string; | ||
action: string; | ||
label: string; | ||
region: string; | ||
isEnabled: boolean; | ||
}; | ||
needToCheck?: boolean; | ||
autoRedirect?: { time: number }; | ||
userReturnStatus?: string; | ||
discount?: number | null; | ||
userId?: string; | ||
invoice?: number; | ||
pid?: number; | ||
projectAmount?: { | ||
amount: string; | ||
currency: string; | ||
}; | ||
titleClass?: TitleClass; | ||
isSuccess?: boolean; | ||
isCanceled?: boolean; | ||
paymentCountryIso?: string; | ||
order?: { | ||
lineitems?: Array<{ | ||
name: string; | ||
quantity: number; | ||
currency: string; | ||
amount: number; | ||
amount_without_discount: number; | ||
indirect_tax_rate: number; | ||
}>; | ||
shipping?: { | ||
currency: string; | ||
amount: number; | ||
}; | ||
contained_taxes?: { | ||
sales_tax?: boolean; | ||
user_vat?: boolean; | ||
}; | ||
}; | ||
} |
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 enum TitleClass { | ||
done = 'done', | ||
cancel = 'cancel', | ||
cancelUser = 'canceluser', | ||
} |
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
...ess-checkout/post-messages-handlers/get-payment-status/get-payment-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,21 @@ | ||
import { EventName } from '../../../../core/event-name.enum'; | ||
import { Message } from '../../../../core/message.interface'; | ||
import { getPaymentStatusHandler } from './get-payment-status.handler'; | ||
|
||
const mockMessage: Message = { | ||
name: EventName.getPaymentStatus, | ||
}; | ||
describe('getPaymentStatusHandler', () => { | ||
it('should handle status', () => { | ||
expect(getPaymentStatusHandler(mockMessage)).toEqual({ | ||
isHandled: true, | ||
value: undefined, | ||
}); | ||
}); | ||
|
||
it('should return null', () => { | ||
expect( | ||
getPaymentStatusHandler({ name: EventName.getPaymentMethodsList }) | ||
).toBeNull(); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
...headless-checkout/post-messages-handlers/get-payment-status/get-payment-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,17 @@ | ||
import { Handler } from '../../../../core/post-messages-client/handler.type'; | ||
import { Message } from '../../../../core/message.interface'; | ||
import { Status } from '../../../../core/status/status.interface'; | ||
import { isGetPaymentStatusMessage } from '../../../../core/guards/get-payment-status-message.guard'; | ||
|
||
export const getPaymentStatusHandler: Handler<Status> = ( | ||
message: Message | ||
): { isHandled: boolean; value?: Status } | null => { | ||
if (!isGetPaymentStatusMessage(message)) { | ||
return null; | ||
} | ||
|
||
return { | ||
isHandled: true, | ||
value: message.data, | ||
}; | ||
}; |