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;
currency: string;
metadata: object;
externalID?: string;
};
export const createInvoiceWithTemplate = async (

View File

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

View File

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

View File

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

View File

@ -22,6 +22,7 @@ export type PaymentStarted = {
eventId: number;
paymentId: string;
provider?: string;
externalId?: string;
isInstantPayment: boolean;
};

View File

@ -49,6 +49,7 @@ export const invoiceEventsToConditions = (
eventId: id,
provider: getProvider(change),
paymentId: change.payment.id,
externalId: change.payment.externalID,
isInstantPayment,
},
];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
export { getResultInfo } from './getResultInfo';
export { getPaymentFormViewId } from './getPaymentFormViewId';
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);
};