-
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.
Merge pull request #66 from xsolla/PAYMENTS-18110
feat (PAYMENTS-18110): add combined payment methods
- Loading branch information
Showing
6 changed files
with
81 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { PaymentMethod } from './payment-method.interface'; | ||
import { SavedMethod } from './saved-method.interface'; | ||
|
||
export interface CombinedPaymentMethods { | ||
paymentMethods: { | ||
quick: PaymentMethod[]; | ||
remained: PaymentMethod[]; | ||
}; | ||
savedMethods: SavedMethod[]; | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/core/guards/combined-payment-methods-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,22 @@ | ||
import { Message } from '../../core/message.interface'; | ||
import { isEventMessage } from './event-message.guard'; | ||
import { EventName } from '../../core/event-name.enum'; | ||
import { CombinedPaymentMethods } from '../combined-payment-methods.interface'; | ||
|
||
export const isCombinedMethodsEventMessage = ( | ||
messageData: unknown, | ||
): messageData is Message<{ | ||
combinedPaymentMethods: CombinedPaymentMethods; | ||
}> => { | ||
if (isEventMessage(messageData)) { | ||
return ( | ||
messageData.name === EventName.getCombinedPaymentMethods && | ||
!!( | ||
messageData.data as { | ||
[key: string]: unknown; | ||
} | ||
)?.combinedPaymentMethods | ||
); | ||
} | ||
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
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
20 changes: 20 additions & 0 deletions
20
...features/headless-checkout/post-messages-handlers/get-combined-payment-methods.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,20 @@ | ||
import { Handler } from '../../../core/post-messages-client/handler.type'; | ||
import { Message } from '../../../core/message.interface'; | ||
import { isCombinedMethodsEventMessage } from '../../../core/guards/combined-payment-methods-event-message.guard'; | ||
import { CombinedPaymentMethods } from '../../../core/combined-payment-methods.interface'; | ||
|
||
export const getCombinedPaymentMethodsHandler: Handler< | ||
CombinedPaymentMethods | ||
> = ( | ||
message: Message, | ||
): { isHandled: boolean; value: CombinedPaymentMethods } | null => { | ||
if (!isCombinedMethodsEventMessage(message)) { | ||
return null; | ||
} | ||
|
||
const combinedPaymentMethods = message.data?.combinedPaymentMethods; | ||
return { | ||
isHandled: true, | ||
value: combinedPaymentMethods as unknown as CombinedPaymentMethods, | ||
}; | ||
}; |