in client/components/mma/paymentUpdate/dd/DirectDebitInputForm.tsx [67:110]
async function validateDirectDebitDetails(
newPaymentMethod: NewPaymentMethodDetail,
) {
try {
const validateDirectDebitDetailsFetch = await fetch(
`/api/validate/payment/dd?mode=${
props.testUser ? 'test' : 'live'
}`,
{
credentials: 'include',
method: 'POST',
body: JSON.stringify({
accountNumber,
sortCode: cleanSortCode(sortCode),
}),
headers: { 'Content-Type': 'application/json' },
},
);
const response =
await processResponse<DirectDebitValidationResponse>(
validateDirectDebitDetailsFetch,
);
if (response && response.data.accountValid) {
setIsValidating(false);
props.executePaymentUpdate(newPaymentMethod);
} else if (response && response.data.goCardlessStatusCode === 429) {
setIsValidating(false);
setError(
'We cannot currently validate your bank details. Please try again later.',
);
} else {
setIsValidating(false);
setError(
'Your bank details are invalid. Please check them and try again.',
);
}
} catch {
setIsValidating(false);
setError(
'Could not validate your bank details, please check them and try again.',
);
}
}