mirror of
https://github.com/valitydev/checkout.git
synced 2024-11-06 02:25:18 +00:00
Return payment flow hold (#318)
This commit is contained in:
parent
7f714d28fd
commit
bb91ee091d
@ -38,6 +38,9 @@ export type {
|
||||
Payer,
|
||||
PaymentResourcePayer,
|
||||
ContactInfo,
|
||||
PaymentFlow,
|
||||
PaymentFlowInstant,
|
||||
PaymentFlowHold,
|
||||
} from './paymentModel';
|
||||
export type {
|
||||
ServiceProviderMetadata,
|
||||
|
@ -30,7 +30,6 @@ export type PaymentFlowInstant = {
|
||||
export type PaymentFlowHold = {
|
||||
type: 'PaymentFlowHold';
|
||||
onHoldExpiration: 'cancel' | 'capture';
|
||||
heldUntil?: string;
|
||||
};
|
||||
|
||||
export type PaymentFlow = PaymentFlowInstant | PaymentFlowHold;
|
||||
|
@ -30,6 +30,7 @@ it('should return resolved init config', () => {
|
||||
redirectUrl: null,
|
||||
skipUserInteraction: false,
|
||||
theme: null,
|
||||
paymentFlow: null,
|
||||
};
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
@ -31,6 +31,7 @@ export const resolveInitConfig = (userConfig: Partial<InitConfig>): InitConfig =
|
||||
skipUserInteraction,
|
||||
isExternalIDIncluded,
|
||||
theme,
|
||||
paymentFlow,
|
||||
} = userConfig;
|
||||
return {
|
||||
...resolvedIntegrationType,
|
||||
@ -48,5 +49,6 @@ export const resolveInitConfig = (userConfig: Partial<InitConfig>): InitConfig =
|
||||
skipUserInteraction: setDefault(resolveBoolean(skipUserInteraction), false),
|
||||
isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded), true),
|
||||
theme: resolveString(theme),
|
||||
paymentFlow: resolveObject(paymentFlow),
|
||||
};
|
||||
};
|
||||
|
@ -18,6 +18,7 @@ export type InitConfig = {
|
||||
terminalFormValues?: object;
|
||||
skipUserInteraction?: boolean;
|
||||
isExternalIDIncluded?: boolean;
|
||||
paymentFlow?: object;
|
||||
};
|
||||
|
||||
export type ThemeConfig = Record<string, any>;
|
||||
|
@ -10,11 +10,9 @@ export const createPayment = async (
|
||||
payload: StartPaymentPayload,
|
||||
): Promise<Payment> => {
|
||||
const payer = await createPayer(model, invoiceContext, payload);
|
||||
const { isExternalIDIncluded, metadata, recurring } = model.initContext;
|
||||
const { isExternalIDIncluded, metadata, recurring, paymentFlow } = model.initContext;
|
||||
const params: PaymentParams = {
|
||||
flow: {
|
||||
type: 'PaymentFlowInstant',
|
||||
},
|
||||
flow: paymentFlow,
|
||||
payer,
|
||||
metadata,
|
||||
makeRecurrent: recurring,
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { PaymentFlow, PaymentFlowHold, PaymentFlowInstant } from 'checkout/backend/payments';
|
||||
|
||||
import { InitContext } from './types';
|
||||
import { InitConfig } from '../init';
|
||||
import { isNil } from '../utils';
|
||||
@ -7,6 +9,29 @@ const toContactInfo = ({ phoneNumber, email }: InitConfig) => ({
|
||||
email: isNil(email) ? undefined : email,
|
||||
});
|
||||
|
||||
const isPaymentFlowInstant = (obj: any): obj is PaymentFlowInstant => {
|
||||
if (isNil(obj)) return false;
|
||||
return obj.type === 'PaymentFlowInstant';
|
||||
};
|
||||
|
||||
const isPaymentFlowHold = (obj: any): obj is PaymentFlowHold => {
|
||||
if (isNil(obj)) return false;
|
||||
const isOnHoldExpiration = obj.onHoldExpiration === 'cancel' || obj.onHoldExpiration === 'capture';
|
||||
return obj.type === 'PaymentFlowHold' && isOnHoldExpiration;
|
||||
};
|
||||
|
||||
const toPaymentFlow = (paymentFlow: object | null): PaymentFlow => {
|
||||
if (isPaymentFlowInstant(paymentFlow)) {
|
||||
return paymentFlow;
|
||||
}
|
||||
if (isPaymentFlowHold(paymentFlow)) {
|
||||
return paymentFlow;
|
||||
}
|
||||
return {
|
||||
type: 'PaymentFlowInstant',
|
||||
};
|
||||
};
|
||||
|
||||
export const toInitContext = (initConfig: InitConfig): InitContext => ({
|
||||
skipUserInteraction: initConfig?.skipUserInteraction,
|
||||
isExternalIDIncluded: initConfig?.isExternalIDIncluded,
|
||||
@ -16,4 +41,5 @@ export const toInitContext = (initConfig: InitConfig): InitContext => ({
|
||||
redirectUrl: initConfig.redirectUrl,
|
||||
metadata: initConfig.metadata,
|
||||
recurring: initConfig.recurring,
|
||||
paymentFlow: toPaymentFlow(initConfig.paymentFlow),
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { InvoiceStatus, ServiceProviderMetadata } from '../backend/payments';
|
||||
import { InvoiceStatus, PaymentFlow, ServiceProviderMetadata } from '../backend/payments';
|
||||
|
||||
export type PaymentAmount = {
|
||||
readonly value: number;
|
||||
@ -40,6 +40,7 @@ export type InitContextContactInfo = {
|
||||
|
||||
export type InitContext = {
|
||||
readonly skipUserInteraction: boolean;
|
||||
readonly paymentFlow: PaymentFlow;
|
||||
readonly contactInfo?: InitContextContactInfo;
|
||||
readonly terminalFormValues?: object;
|
||||
readonly paymentMetadata?: object;
|
||||
|
Loading…
Reference in New Issue
Block a user