mirror of
https://github.com/valitydev/checkout.git
synced 2024-11-06 02:25:18 +00:00
Provide interaction completed invoice event (#309)
This commit is contained in:
parent
29950a5740
commit
812afc589e
@ -1,5 +1,5 @@
|
||||
import { PaymentCondition } from './types';
|
||||
import { invoiceEventsToConditions, provideInstantPayment } from './utils';
|
||||
import { invoiceEventsToConditions, provideInstantPayment, provideInteractionCompleted } from './utils';
|
||||
import { ServiceProviderContactInfo, ServiceProviderMetadataField, getInvoiceEvents } from '../backend/payments';
|
||||
import { InitContext, PaymentModel, PaymentModelInvoice, PaymentTerminal } from '../paymentModel';
|
||||
import { extractError, isNil, last, withRetry } from '../utils';
|
||||
@ -104,8 +104,9 @@ const provideInvoiceUnpaid = async (model: PaymentModelInvoice): Promise<Payment
|
||||
case 'paymentStarted':
|
||||
case 'paymentStatusChanged':
|
||||
case 'interactionRequested':
|
||||
case 'interactionCompleted':
|
||||
return conditions;
|
||||
case 'interactionCompleted':
|
||||
return provideInteractionCompleted(model, lastEventId);
|
||||
}
|
||||
}
|
||||
} catch (exception) {
|
||||
|
@ -2,3 +2,4 @@ export { invoiceEventsToConditions } from './invoiceEventsToConditions';
|
||||
export { pollingResultToConditions } from './pollingResultToConditions';
|
||||
export { toDefaultFormValuesMetadata } from './toDefaultFormValuesMetadata';
|
||||
export { provideInstantPayment } from './provideInstantPayment';
|
||||
export { provideInteractionCompleted } from './provideInteractionCompleted';
|
||||
|
@ -0,0 +1,28 @@
|
||||
import { pollInvoiceEvents } from 'checkout/paymentMgmt';
|
||||
import { PaymentModelInvoice } from 'checkout/paymentModel';
|
||||
|
||||
import { pollingResultToConditions } from './pollingResultToConditions';
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 60 * 1000 * 3;
|
||||
const API_METHOD_CALL_MS = 1000;
|
||||
|
||||
export const provideInteractionCompleted = async (model: PaymentModelInvoice, lastEventId: number) => {
|
||||
const {
|
||||
invoiceParams: { invoiceID, invoiceAccessToken },
|
||||
apiEndpoint,
|
||||
} = model;
|
||||
const pollingResult = await pollInvoiceEvents({
|
||||
apiEndpoint,
|
||||
invoiceAccessToken,
|
||||
invoiceID,
|
||||
startFromEventID: lastEventId,
|
||||
stopPollingTypes: ['PaymentStatusChanged'],
|
||||
delays: {
|
||||
pollingTimeout: DEFAULT_TIMEOUT_MS,
|
||||
apiMethodCall: API_METHOD_CALL_MS,
|
||||
},
|
||||
});
|
||||
const skipUserInteraction = false;
|
||||
const isInstantPayment = false;
|
||||
return pollingResultToConditions(pollingResult, skipUserInteraction, isInstantPayment);
|
||||
};
|
@ -216,7 +216,6 @@ export const useViewModel = (paymentMethods: PaymentMethod[], conditions: Paymen
|
||||
switch (lastCondition.name) {
|
||||
case 'invoiceStatusChanged':
|
||||
case 'paymentStatusChanged':
|
||||
case 'interactionCompleted':
|
||||
case 'paymentStatusUnknown':
|
||||
case 'paymentStarted':
|
||||
dispatch({ type: 'SET_VIEW', payload: { name: 'PaymentResultView', id: 'PaymentResultView' } });
|
||||
@ -231,6 +230,11 @@ export const useViewModel = (paymentMethods: PaymentMethod[], conditions: Paymen
|
||||
payload: { name: 'PaymentProcessFailedView', id: 'PaymentProcessFailedView' },
|
||||
});
|
||||
break;
|
||||
case 'interactionCompleted':
|
||||
// Error for an inappropriate condition usage. 'InteractionCompleted' event requires invoice status change waiting.
|
||||
console.error('Inappropriate condition state: interactionCompleted');
|
||||
dispatch({ type: 'SET_VIEW', payload: { name: 'PaymentResultView', id: 'PaymentResultView' } });
|
||||
break;
|
||||
}
|
||||
}, [lastCondition]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user