mirror of
https://github.com/valitydev/checkout.git
synced 2024-11-06 02:25:18 +00:00
Disable retry payment with externalID (#310)
This commit is contained in:
parent
812afc589e
commit
3f0ff96ede
@ -5,6 +5,7 @@ export type InvoiceParamsWithTemplate = {
|
|||||||
amount: number;
|
amount: number;
|
||||||
currency: string;
|
currency: string;
|
||||||
metadata: object;
|
metadata: object;
|
||||||
|
externalID?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createInvoiceWithTemplate = async (
|
export const createInvoiceWithTemplate = async (
|
||||||
|
@ -224,6 +224,7 @@ export type InvoiceTemplate = {
|
|||||||
lifetime: LifetimeInterval;
|
lifetime: LifetimeInterval;
|
||||||
details: InvoiceTemplateMultiLine | InvoiceTemplateSingleLine;
|
details: InvoiceTemplateMultiLine | InvoiceTemplateSingleLine;
|
||||||
metadata: object;
|
metadata: object;
|
||||||
|
externalID?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ServiceProvider = {
|
export type ServiceProvider = {
|
||||||
@ -273,5 +274,5 @@ export type Invoice = {
|
|||||||
status: InvoiceStatus;
|
status: InvoiceStatus;
|
||||||
reason: string;
|
reason: string;
|
||||||
cart: InvoiceLine[];
|
cart: InvoiceLine[];
|
||||||
externalID: string;
|
externalID?: string;
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,7 @@ it('should return resolved init config', () => {
|
|||||||
invoiceID: 'someID',
|
invoiceID: 'someID',
|
||||||
invoiceAccessToken: 'some token',
|
invoiceAccessToken: 'some token',
|
||||||
recurring: false,
|
recurring: false,
|
||||||
isExternalIDIncluded: false,
|
isExternalIDIncluded: true,
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
requireCardHolder: false,
|
requireCardHolder: false,
|
||||||
obscureCardCvv: true,
|
obscureCardCvv: true,
|
||||||
|
@ -45,6 +45,6 @@ export const resolveInitConfig = (userConfig: Partial<InitConfig>): InitConfig =
|
|||||||
metadata: setDefault(resolveObject(metadata), undefined),
|
metadata: setDefault(resolveObject(metadata), undefined),
|
||||||
terminalFormValues: setDefault(resolveObject(terminalFormValues), undefined),
|
terminalFormValues: setDefault(resolveObject(terminalFormValues), undefined),
|
||||||
skipUserInteraction: setDefault(resolveBoolean(skipUserInteraction), false),
|
skipUserInteraction: setDefault(resolveBoolean(skipUserInteraction), false),
|
||||||
isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded), false),
|
isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded), true),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -22,6 +22,7 @@ export type PaymentStarted = {
|
|||||||
eventId: number;
|
eventId: number;
|
||||||
paymentId: string;
|
paymentId: string;
|
||||||
provider?: string;
|
provider?: string;
|
||||||
|
externalId?: string;
|
||||||
isInstantPayment: boolean;
|
isInstantPayment: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ export const invoiceEventsToConditions = (
|
|||||||
eventId: id,
|
eventId: id,
|
||||||
provider: getProvider(change),
|
provider: getProvider(change),
|
||||||
paymentId: change.payment.id,
|
paymentId: change.payment.id,
|
||||||
|
externalId: change.payment.externalID,
|
||||||
isInstantPayment,
|
isInstantPayment,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -7,12 +7,14 @@ export const createInvoiceWithTemplate = async (model: PaymentModelInvoiceTempla
|
|||||||
apiEndpoint,
|
apiEndpoint,
|
||||||
metadata,
|
metadata,
|
||||||
paymentAmount,
|
paymentAmount,
|
||||||
|
externalID,
|
||||||
invoiceTemplateParams: { invoiceTemplateID, invoiceTemplateAccessToken },
|
invoiceTemplateParams: { invoiceTemplateID, invoiceTemplateAccessToken },
|
||||||
} = model;
|
} = model;
|
||||||
const invoiceAndToken = await request(apiEndpoint, invoiceTemplateAccessToken, invoiceTemplateID, {
|
const invoiceAndToken = await request(apiEndpoint, invoiceTemplateAccessToken, invoiceTemplateID, {
|
||||||
amount: paymentAmount.value,
|
amount: paymentAmount.value,
|
||||||
currency: paymentAmount.currency,
|
currency: paymentAmount.currency,
|
||||||
metadata,
|
metadata,
|
||||||
|
externalID,
|
||||||
});
|
});
|
||||||
return invoiceToInvoiceContext(invoiceAndToken);
|
return invoiceToInvoiceContext(invoiceAndToken);
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,7 @@ export const createPayment = async (
|
|||||||
payer,
|
payer,
|
||||||
metadata,
|
metadata,
|
||||||
makeRecurrent: recurring,
|
makeRecurrent: recurring,
|
||||||
externalID: isExternalIDIncluded ? invoiceContext.externalID : undefined,
|
externalID: isExternalIDIncluded ? invoiceContext?.externalID : undefined,
|
||||||
};
|
};
|
||||||
const { invoiceID, invoiceAccessToken } = invoiceContext.invoiceParams;
|
const { invoiceID, invoiceAccessToken } = invoiceContext.invoiceParams;
|
||||||
const createPaymentWithRetry = withRetry(request);
|
const createPaymentWithRetry = withRetry(request);
|
||||||
|
@ -19,11 +19,12 @@ const applyInvoice = (
|
|||||||
|
|
||||||
const applyInvoiceTemplate = (
|
const applyInvoiceTemplate = (
|
||||||
{ invoiceTemplateParams, type }: Partial<InvoiceTemplateContext>,
|
{ invoiceTemplateParams, type }: Partial<InvoiceTemplateContext>,
|
||||||
{ invoiceTemplate: { metadata } }: BackendModelInvoiceTemplate,
|
{ invoiceTemplate: { metadata, externalID } }: BackendModelInvoiceTemplate,
|
||||||
): InvoiceTemplateContext => ({
|
): InvoiceTemplateContext => ({
|
||||||
type,
|
type,
|
||||||
invoiceTemplateParams,
|
invoiceTemplateParams,
|
||||||
metadata,
|
metadata,
|
||||||
|
externalID,
|
||||||
});
|
});
|
||||||
|
|
||||||
const applyBackendModel = (
|
const applyBackendModel = (
|
||||||
|
@ -8,10 +8,10 @@ const toContactInfo = ({ phoneNumber, email }: InitConfig) => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const toInitContext = (initConfig: InitConfig): InitContext => ({
|
export const toInitContext = (initConfig: InitConfig): InitContext => ({
|
||||||
skipUserInteraction: initConfig?.skipUserInteraction || false,
|
skipUserInteraction: initConfig?.skipUserInteraction,
|
||||||
|
isExternalIDIncluded: initConfig?.isExternalIDIncluded,
|
||||||
terminalFormValues: initConfig.terminalFormValues,
|
terminalFormValues: initConfig.terminalFormValues,
|
||||||
paymentMetadata: initConfig.metadata,
|
paymentMetadata: initConfig.metadata,
|
||||||
isExternalIDIncluded: initConfig.isExternalIDIncluded,
|
|
||||||
contactInfo: toContactInfo(initConfig),
|
contactInfo: toContactInfo(initConfig),
|
||||||
redirectUrl: initConfig.redirectUrl,
|
redirectUrl: initConfig.redirectUrl,
|
||||||
metadata: initConfig.metadata,
|
metadata: initConfig.metadata,
|
||||||
|
@ -74,14 +74,15 @@ export type InvoiceTemplateContext = {
|
|||||||
readonly type: 'InvoiceTemplateContext';
|
readonly type: 'InvoiceTemplateContext';
|
||||||
readonly invoiceTemplateParams: InvoiceTemplateParams;
|
readonly invoiceTemplateParams: InvoiceTemplateParams;
|
||||||
readonly metadata: object;
|
readonly metadata: object;
|
||||||
|
readonly externalID?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type InvoiceContext = {
|
export type InvoiceContext = {
|
||||||
readonly type: 'InvoiceContext';
|
readonly type: 'InvoiceContext';
|
||||||
readonly invoiceParams: InvoiceParams;
|
readonly invoiceParams: InvoiceParams;
|
||||||
readonly dueDate: string;
|
readonly dueDate: string;
|
||||||
readonly externalID: string;
|
|
||||||
readonly status: InvoiceStatus;
|
readonly status: InvoiceStatus;
|
||||||
|
readonly externalID?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PaymentModelInvoice = InvoiceContext & CommonPaymentModel;
|
export type PaymentModelInvoice = InvoiceContext & CommonPaymentModel;
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
import { isNil, last } from 'checkout/utils';
|
import { isNil, last } from 'checkout/utils';
|
||||||
|
|
||||||
import { ResultIcon } from './ResultIcon';
|
import { ResultIcon } from './ResultIcon';
|
||||||
import { getPaymentFormViewId, getResultInfo, isInstantPayment } from './utils';
|
import { getPaymentFormViewId, getResultInfo, isExternalIdEmpty, isInstantPayment } from './utils';
|
||||||
|
|
||||||
export function PaymentResultView() {
|
export function PaymentResultView() {
|
||||||
const { l } = useContext(LocaleContext);
|
const { l } = useContext(LocaleContext);
|
||||||
@ -66,7 +66,7 @@ export function PaymentResultView() {
|
|||||||
</VStack>
|
</VStack>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<VStack align="stretch" spacing={6}>
|
<VStack align="stretch" spacing={6}>
|
||||||
{hasActions && (
|
{hasActions && isExternalIdEmpty(conditions) && (
|
||||||
<Button borderRadius="lg" colorScheme="teal" size="lg" variant="solid" onClick={retry}>
|
<Button borderRadius="lg" colorScheme="teal" size="lg" variant="solid" onClick={retry}>
|
||||||
{l['form.button.pay.again.label']}
|
{l['form.button.pay.again.label']}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
export { getResultInfo } from './getResultInfo';
|
export { getResultInfo } from './getResultInfo';
|
||||||
export { getPaymentFormViewId } from './getPaymentFormViewId';
|
export { getPaymentFormViewId } from './getPaymentFormViewId';
|
||||||
export { isInstantPayment } from './isInstantPayment';
|
export { isInstantPayment } from './isInstantPayment';
|
||||||
|
export { isExternalIdEmpty } from './isExternalIdEmpty';
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
import { PaymentCondition, PaymentStarted } from 'checkout/paymentCondition';
|
||||||
|
import { isNil } from 'checkout/utils';
|
||||||
|
|
||||||
|
export const isExternalIdEmpty = (conditions: PaymentCondition[]): boolean => {
|
||||||
|
const found = conditions
|
||||||
|
.slice()
|
||||||
|
.reverse()
|
||||||
|
.find((condition) => condition.name === 'paymentStarted') as PaymentStarted;
|
||||||
|
if (isNil(found)) return false;
|
||||||
|
return isNil(found.externalId);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user