Add fields checking for instant payment (#129)

This commit is contained in:
Ildar Galeev 2022-08-05 16:04:26 +03:00 committed by GitHub
parent 571710ded0
commit 84ae285e44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,8 +36,23 @@ const Container = styled.div`
justify-content: space-between; justify-content: space-between;
`; `;
const isInstantPayment = (form: ServiceProviderMetadataField[], contactInfo: ServiceProviderContactInfo) => const isContactInfoRequired = (
isNil(form) && isNil(contactInfo); contactInfo: ServiceProviderContactInfo,
emailFieldVisible: boolean,
phoneNumberFieldVisible: boolean
): boolean => {
if (isNil(contactInfo)) {
return false;
}
return emailFieldVisible || phoneNumberFieldVisible;
};
const isInstantPayment = (
form: ServiceProviderMetadataField[],
contactInfo: ServiceProviderContactInfo,
emailFieldVisible: boolean,
phoneNumberFieldVisible: boolean
) => isNil(form) && !isContactInfoRequired(contactInfo, emailFieldVisible, phoneNumberFieldVisible);
const PaymentTerminalFormRef: React.FC<InjectedFormProps> = ({ submitFailed, initialize, handleSubmit }) => { const PaymentTerminalFormRef: React.FC<InjectedFormProps> = ({ submitFailed, initialize, handleSubmit }) => {
const initConfig = useAppSelector(getInitConfigSelector); const initConfig = useAppSelector(getInitConfigSelector);
@ -55,7 +70,7 @@ const PaymentTerminalFormRef: React.FC<InjectedFormProps> = ({ submitFailed, ini
useEffect(() => { useEffect(() => {
dispatch(setViewInfoError(false)); dispatch(setViewInfoError(false));
if (!isInstantPayment(form, contactInfo)) { if (!isInstantPayment(form, contactInfo, email.visible, phoneNumber.visible)) {
switch (paymentStatus) { switch (paymentStatus) {
case PaymentStatus.pristine: case PaymentStatus.pristine:
initialize({ initialize({
@ -119,7 +134,7 @@ const PaymentTerminalFormRef: React.FC<InjectedFormProps> = ({ submitFailed, ini
</FormGroup> </FormGroup>
)} )}
</div> </div>
{!isInstantPayment(form, contactInfo) && <PayButton />} {!isInstantPayment(form, contactInfo, email.visible, phoneNumber.visible) && <PayButton />}
</Container> </Container>
</form> </form>
); );