mirror of
https://github.com/valitydev/checkout.git
synced 2024-11-06 10:35:20 +00:00
Add fields checking for instant payment (#129)
This commit is contained in:
parent
571710ded0
commit
84ae285e44
@ -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>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user