Skip to content

Commit

Permalink
feat/MSSDK-2112: Add errors for google recaptcha (#452)
Browse files Browse the repository at this point in the history
* feat/MSSDK-2112: Add errors for google recaptcha

* feat/MSSDK-2112: Update after CR
  • Loading branch information
pawelacio authored Jan 23, 2025
1 parent 818f0da commit 42570a3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/components/Payment/Payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ import PayPal from './PayPal/PayPal';
import DropInSection from './DropInSection/DropInSection';
import { PaymentProps } from './Payment.types';

type ErrorMapType = {
[key: string]: [string, string];
};

const GERNERAL_ERRORS_MAP: ErrorMapType = {
CPT0002: [
'payment.error.captcha-verification-failed',
'An error occurred during payment. Please try again later. If the issue persists, please reach out to our support team for assistance.'
],
ADYEN_DEFAULT: [
'payment.error.payment-not-processed',
'The payment has not been processed. Please, try again with a different payment method.'
],
PAYPAL_DEFAULT: [
'payment.error.paypal-failed',
'The payment failed. Please try again.'
]
};

const Payment = ({ onPaymentComplete }: PaymentProps) => {
const { paymentMethods: publisherPaymentMethods, isPayPalHidden } =
useAppSelector(selectPublisherConfig);
Expand Down Expand Up @@ -245,16 +264,13 @@ const Payment = ({ onPaymentComplete }: PaymentProps) => {
}

setIsLoading(true);
const { responseData } = await submitPayPalPayment(captchaToken);
const { responseData, code } = await submitPayPalPayment(captchaToken);
if (responseData?.redirectUrl) {
window.location.href = responseData.redirectUrl;
} else {
setIsLoading(false);
setGeneralError(
t(
'payment.error.paypal-failed',
'The payment failed. Please try again.'
)
t(...(GERNERAL_ERRORS_MAP[code] || GERNERAL_ERRORS_MAP.PAYPAL_DEFAULT))
);
}
};
Expand Down Expand Up @@ -292,7 +308,7 @@ const Payment = ({ onPaymentComplete }: PaymentProps) => {
return;
}

const { errors, responseData } = await submitPayment({
const { errors, responseData, code } = await submitPayment({
paymentMethod,
browserInfo,
billingAddress,
Expand All @@ -302,19 +318,8 @@ const Payment = ({ onPaymentComplete }: PaymentProps) => {
eventDispatcher(MSSDK_PURCHASE_FAILED, {
reason: errors[0]
});
const notSupportedMethod = errors[0].includes(
'Payment details are not supported'
);
setGeneralError(
notSupportedMethod
? t(
'payment.error.payment-method-not-supported',
'Payment method not supported. Try different payment method'
)
: t(
'payment.error.payment-not-processed',
'The payment has not been processed. Please, try again with a different payment method.'
)
t(...(GERNERAL_ERRORS_MAP[code] || GERNERAL_ERRORS_MAP.ADYEN_DEFAULT))
);

setIsLoading(false);
Expand Down
7 changes: 7 additions & 0 deletions src/components/RegisterPage/useRegisterForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ function useRegisterForm({ onSuccess }: UseRegisterFormProps) {
"We couldn't verify the email address you entered. Please check it for accuracy and try again. If you're sure the address is correct and still see this message, you may need to use a different email or contact support for help."
)
);
} else if (response.code === ERROR_CODES.CAPTCHA.VERIFICATION_FAILED) {
renderError(
t(
'register-form.error.captcha-verification-failed',
'An error occurred during registration. Please try again later. If the issue persists, please reach out to our support team for assistance.'
)
);
} else if (response.code) {
renderError(t('register-form.error.general', 'An error occurred.'));
}
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
"payment.complete-purchase": "Complete purchase",
"payment.error.cannot-fetch-payment-methods": "Cannot fetch payment methods",
"payment.error.failed": "The payment failed. Please try again.",
"payment.error.captcha-verification-failed": "An error occurred during payment. Please try again later. If the issue persists, please reach out to our support team for assistance.",
"payment.error.payment-method-not-supported": "Payment method not supported. Try different payment method",
"payment.error.payment-methods-not-available": "Payment methods not available",
"payment.error.payment-methods-not-defined": "Payment methods are not defined",
Expand Down Expand Up @@ -452,6 +453,7 @@
"register-form.error.general": "An error occured.",
"register-form.error.server-overloaded": "Server overloaded. Please try again later.",
"register-form.error.email-verification-failed": "We couldn't verify the email address you entered. Please check it for accuracy and try again. If you're sure the address is correct and still see this message, you may need to use a different email or contact support for help.",
"register-form.error.captcha-verification-failed": "An error occurred during registration. Please try again later. If the issue persists, please reach out to our support team for assistance.",
"register-form.label.email": "E-mail",
"register-form.label.password": "Password",
"register.button.have-an-account": "Have an account?",
Expand Down

0 comments on commit 42570a3

Please sign in to comment.