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,
|
Payer,
|
||||||
PaymentResourcePayer,
|
PaymentResourcePayer,
|
||||||
ContactInfo,
|
ContactInfo,
|
||||||
|
PaymentFlow,
|
||||||
|
PaymentFlowInstant,
|
||||||
|
PaymentFlowHold,
|
||||||
} from './paymentModel';
|
} from './paymentModel';
|
||||||
export type {
|
export type {
|
||||||
ServiceProviderMetadata,
|
ServiceProviderMetadata,
|
||||||
|
@ -30,7 +30,6 @@ export type PaymentFlowInstant = {
|
|||||||
export type PaymentFlowHold = {
|
export type PaymentFlowHold = {
|
||||||
type: 'PaymentFlowHold';
|
type: 'PaymentFlowHold';
|
||||||
onHoldExpiration: 'cancel' | 'capture';
|
onHoldExpiration: 'cancel' | 'capture';
|
||||||
heldUntil?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PaymentFlow = PaymentFlowInstant | PaymentFlowHold;
|
export type PaymentFlow = PaymentFlowInstant | PaymentFlowHold;
|
||||||
|
@ -30,6 +30,7 @@ it('should return resolved init config', () => {
|
|||||||
redirectUrl: null,
|
redirectUrl: null,
|
||||||
skipUserInteraction: false,
|
skipUserInteraction: false,
|
||||||
theme: null,
|
theme: null,
|
||||||
|
paymentFlow: null,
|
||||||
};
|
};
|
||||||
expect(actual).toEqual(expected);
|
expect(actual).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
@ -31,6 +31,7 @@ export const resolveInitConfig = (userConfig: Partial<InitConfig>): InitConfig =
|
|||||||
skipUserInteraction,
|
skipUserInteraction,
|
||||||
isExternalIDIncluded,
|
isExternalIDIncluded,
|
||||||
theme,
|
theme,
|
||||||
|
paymentFlow,
|
||||||
} = userConfig;
|
} = userConfig;
|
||||||
return {
|
return {
|
||||||
...resolvedIntegrationType,
|
...resolvedIntegrationType,
|
||||||
@ -48,5 +49,6 @@ export const resolveInitConfig = (userConfig: Partial<InitConfig>): InitConfig =
|
|||||||
skipUserInteraction: setDefault(resolveBoolean(skipUserInteraction), false),
|
skipUserInteraction: setDefault(resolveBoolean(skipUserInteraction), false),
|
||||||
isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded), true),
|
isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded), true),
|
||||||
theme: resolveString(theme),
|
theme: resolveString(theme),
|
||||||
|
paymentFlow: resolveObject(paymentFlow),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,7 @@ export type InitConfig = {
|
|||||||
terminalFormValues?: object;
|
terminalFormValues?: object;
|
||||||
skipUserInteraction?: boolean;
|
skipUserInteraction?: boolean;
|
||||||
isExternalIDIncluded?: boolean;
|
isExternalIDIncluded?: boolean;
|
||||||
|
paymentFlow?: object;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ThemeConfig = Record<string, any>;
|
export type ThemeConfig = Record<string, any>;
|
||||||
|
@ -10,11 +10,9 @@ export const createPayment = async (
|
|||||||
payload: StartPaymentPayload,
|
payload: StartPaymentPayload,
|
||||||
): Promise<Payment> => {
|
): Promise<Payment> => {
|
||||||
const payer = await createPayer(model, invoiceContext, payload);
|
const payer = await createPayer(model, invoiceContext, payload);
|
||||||
const { isExternalIDIncluded, metadata, recurring } = model.initContext;
|
const { isExternalIDIncluded, metadata, recurring, paymentFlow } = model.initContext;
|
||||||
const params: PaymentParams = {
|
const params: PaymentParams = {
|
||||||
flow: {
|
flow: paymentFlow,
|
||||||
type: 'PaymentFlowInstant',
|
|
||||||
},
|
|
||||||
payer,
|
payer,
|
||||||
metadata,
|
metadata,
|
||||||
makeRecurrent: recurring,
|
makeRecurrent: recurring,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { PaymentFlow, PaymentFlowHold, PaymentFlowInstant } from 'checkout/backend/payments';
|
||||||
|
|
||||||
import { InitContext } from './types';
|
import { InitContext } from './types';
|
||||||
import { InitConfig } from '../init';
|
import { InitConfig } from '../init';
|
||||||
import { isNil } from '../utils';
|
import { isNil } from '../utils';
|
||||||
@ -7,6 +9,29 @@ const toContactInfo = ({ phoneNumber, email }: InitConfig) => ({
|
|||||||
email: isNil(email) ? undefined : email,
|
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 => ({
|
export const toInitContext = (initConfig: InitConfig): InitContext => ({
|
||||||
skipUserInteraction: initConfig?.skipUserInteraction,
|
skipUserInteraction: initConfig?.skipUserInteraction,
|
||||||
isExternalIDIncluded: initConfig?.isExternalIDIncluded,
|
isExternalIDIncluded: initConfig?.isExternalIDIncluded,
|
||||||
@ -16,4 +41,5 @@ export const toInitContext = (initConfig: InitConfig): InitContext => ({
|
|||||||
redirectUrl: initConfig.redirectUrl,
|
redirectUrl: initConfig.redirectUrl,
|
||||||
metadata: initConfig.metadata,
|
metadata: initConfig.metadata,
|
||||||
recurring: initConfig.recurring,
|
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 = {
|
export type PaymentAmount = {
|
||||||
readonly value: number;
|
readonly value: number;
|
||||||
@ -40,6 +40,7 @@ export type InitContextContactInfo = {
|
|||||||
|
|
||||||
export type InitContext = {
|
export type InitContext = {
|
||||||
readonly skipUserInteraction: boolean;
|
readonly skipUserInteraction: boolean;
|
||||||
|
readonly paymentFlow: PaymentFlow;
|
||||||
readonly contactInfo?: InitContextContactInfo;
|
readonly contactInfo?: InitContextContactInfo;
|
||||||
readonly terminalFormValues?: object;
|
readonly terminalFormValues?: object;
|
||||||
readonly paymentMetadata?: object;
|
readonly paymentMetadata?: object;
|
||||||
|
Loading…
Reference in New Issue
Block a user