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;
|
||||
currency: string;
|
||||
metadata: object;
|
||||
externalID?: string;
|
||||
};
|
||||
|
||||
export const createInvoiceWithTemplate = async (
|
||||
|
@ -224,6 +224,7 @@ export type InvoiceTemplate = {
|
||||
lifetime: LifetimeInterval;
|
||||
details: InvoiceTemplateMultiLine | InvoiceTemplateSingleLine;
|
||||
metadata: object;
|
||||
externalID?: string;
|
||||
};
|
||||
|
||||
export type ServiceProvider = {
|
||||
@ -273,5 +274,5 @@ export type Invoice = {
|
||||
status: InvoiceStatus;
|
||||
reason: string;
|
||||
cart: InvoiceLine[];
|
||||
externalID: string;
|
||||
externalID?: string;
|
||||
};
|
||||
|
@ -18,7 +18,7 @@ it('should return resolved init config', () => {
|
||||
invoiceID: 'someID',
|
||||
invoiceAccessToken: 'some token',
|
||||
recurring: false,
|
||||
isExternalIDIncluded: false,
|
||||
isExternalIDIncluded: true,
|
||||
locale: 'en',
|
||||
requireCardHolder: false,
|
||||
obscureCardCvv: true,
|
||||
|
@ -45,6 +45,6 @@ export const resolveInitConfig = (userConfig: Partial<InitConfig>): InitConfig =
|
||||
metadata: setDefault(resolveObject(metadata), undefined),
|
||||
terminalFormValues: setDefault(resolveObject(terminalFormValues), undefined),
|
||||
skipUserInteraction: setDefault(resolveBoolean(skipUserInteraction), false),
|
||||
isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded), false),
|
||||
isExternalIDIncluded: setDefault(resolveBoolean(isExternalIDIncluded), true),
|
||||
};
|
||||
};
|
||||
|
@ -22,6 +22,7 @@ export type PaymentStarted = {
|
||||
eventId: number;
|
||||
paymentId: string;
|
||||
provider?: string;
|
||||
externalId?: string;
|
||||
isInstantPayment: boolean;
|
||||
};
|
||||
|
||||
|
@ -49,6 +49,7 @@ export const invoiceEventsToConditions = (
|
||||
eventId: id,
|
||||
provider: getProvider(change),
|
||||
paymentId: change.payment.id,
|
||||
externalId: change.payment.externalID,
|
||||
isInstantPayment,
|
||||
},
|
||||
];
|
||||
|
@ -7,12 +7,14 @@ export const createInvoiceWithTemplate = async (model: PaymentModelInvoiceTempla
|
||||
apiEndpoint,
|
||||
metadata,
|
||||
paymentAmount,
|
||||
externalID,
|
||||
invoiceTemplateParams: { invoiceTemplateID, invoiceTemplateAccessToken },
|
||||
} = model;
|
||||
const invoiceAndToken = await request(apiEndpoint, invoiceTemplateAccessToken, invoiceTemplateID, {
|
||||
amount: paymentAmount.value,
|
||||
currency: paymentAmount.currency,
|
||||
metadata,
|
||||
externalID,
|
||||
});
|
||||
return invoiceToInvoiceContext(invoiceAndToken);
|
||||
};
|
||||
|
@ -18,7 +18,7 @@ export const createPayment = async (
|
||||
payer,
|
||||
metadata,
|
||||
makeRecurrent: recurring,
|
||||
externalID: isExternalIDIncluded ? invoiceContext.externalID : undefined,
|
||||
externalID: isExternalIDIncluded ? invoiceContext?.externalID : undefined,
|
||||
};
|
||||
const { invoiceID, invoiceAccessToken } = invoiceContext.invoiceParams;
|
||||
const createPaymentWithRetry = withRetry(request);
|
||||
|
@ -19,11 +19,12 @@ const applyInvoice = (
|
||||
|
||||
const applyInvoiceTemplate = (
|
||||
{ invoiceTemplateParams, type }: Partial<InvoiceTemplateContext>,
|
||||
{ invoiceTemplate: { metadata } }: BackendModelInvoiceTemplate,
|
||||
{ invoiceTemplate: { metadata, externalID } }: BackendModelInvoiceTemplate,
|
||||
): InvoiceTemplateContext => ({
|
||||
type,
|
||||
invoiceTemplateParams,
|
||||
metadata,
|
||||
externalID,
|
||||
});
|
||||
|
||||
const applyBackendModel = (
|
||||
|
@ -8,10 +8,10 @@ const toContactInfo = ({ phoneNumber, email }: InitConfig) => ({
|
||||
});
|
||||
|
||||
export const toInitContext = (initConfig: InitConfig): InitContext => ({
|
||||
skipUserInteraction: initConfig?.skipUserInteraction || false,
|
||||
skipUserInteraction: initConfig?.skipUserInteraction,
|
||||
isExternalIDIncluded: initConfig?.isExternalIDIncluded,
|
||||
terminalFormValues: initConfig.terminalFormValues,
|
||||
paymentMetadata: initConfig.metadata,
|
||||
isExternalIDIncluded: initConfig.isExternalIDIncluded,
|
||||
contactInfo: toContactInfo(initConfig),
|
||||
redirectUrl: initConfig.redirectUrl,
|
||||
metadata: initConfig.metadata,
|
||||
|
@ -74,14 +74,15 @@ export type InvoiceTemplateContext = {
|
||||
readonly type: 'InvoiceTemplateContext';
|
||||
readonly invoiceTemplateParams: InvoiceTemplateParams;
|
||||
readonly metadata: object;
|
||||
readonly externalID?: string;
|
||||
};
|
||||
|
||||
export type InvoiceContext = {
|
||||
readonly type: 'InvoiceContext';
|
||||
readonly invoiceParams: InvoiceParams;
|
||||
readonly dueDate: string;
|
||||
readonly externalID: string;
|
||||
readonly status: InvoiceStatus;
|
||||
readonly externalID?: string;
|
||||
};
|
||||
|
||||
export type PaymentModelInvoice = InvoiceContext & CommonPaymentModel;
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
import { isNil, last } from 'checkout/utils';
|
||||
|
||||
import { ResultIcon } from './ResultIcon';
|
||||
import { getPaymentFormViewId, getResultInfo, isInstantPayment } from './utils';
|
||||
import { getPaymentFormViewId, getResultInfo, isExternalIdEmpty, isInstantPayment } from './utils';
|
||||
|
||||
export function PaymentResultView() {
|
||||
const { l } = useContext(LocaleContext);
|
||||
@ -66,7 +66,7 @@ export function PaymentResultView() {
|
||||
</VStack>
|
||||
<Spacer />
|
||||
<VStack align="stretch" spacing={6}>
|
||||
{hasActions && (
|
||||
{hasActions && isExternalIdEmpty(conditions) && (
|
||||
<Button borderRadius="lg" colorScheme="teal" size="lg" variant="solid" onClick={retry}>
|
||||
{l['form.button.pay.again.label']}
|
||||
</Button>
|
||||
|
@ -1,3 +1,4 @@
|
||||
export { getResultInfo } from './getResultInfo';
|
||||
export { getPaymentFormViewId } from './getPaymentFormViewId';
|
||||
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