Disable retry payment with externalID (#310)

This commit is contained in:
Ildar Galeev 2024-06-10 18:52:15 +07:00 committed by GitHub
parent 812afc589e
commit 3f0ff96ede
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 30 additions and 10 deletions

View File

@ -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 (

View File

@ -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;
}; };

View File

@ -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,

View File

@ -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),
}; };
}; };

View File

@ -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;
}; };

View File

@ -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,
}, },
]; ];

View File

@ -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);
}; };

View File

@ -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);

View File

@ -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 = (

View File

@ -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,

View File

@ -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;

View File

@ -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>

View File

@ -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';

View File

@ -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);
};