Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One Time Checkout - validation message #6442

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 36 additions & 30 deletions support-frontend/assets/pages/[countryGroupId]/oneTimeCheckout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ function OneTimeCheckoutComponent({
elements,
});
}
if (paymentMethod === 'Stripe' && stripe && cardElement) {
if (
paymentMethod === 'Stripe' &&
stripe &&
cardElement &&
recaptchaToken
Copy link
Contributor Author

@andrewHEguardian andrewHEguardian Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually produce a validation message but does require the token to proceed with card payment. This puts us at parity with the generic checkout. Let's try add a message as part of this ticket: https://trello.com/c/jcYuEiiR/1112-investigate-validation-on-generic-checkout

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looks like it comes up with Please check the 'Im not a robot' checkbox with this anyway

) {
paymentMethodResult = await stripe.createPaymentMethod({
type: 'card',
card: cardElement,
Expand Down Expand Up @@ -448,7 +453,6 @@ function OneTimeCheckoutComponent({
billingPostcode,
),
publicKey: stripePublicKey,
// ToDo: validate recaptchaToken for card payments
recaptchaToken: recaptchaToken ?? '',
paymentMethodId: paymentMethodResult.paymentMethod.id,
};
Expand All @@ -459,29 +463,31 @@ function OneTimeCheckoutComponent({
}
}

setThankYouOrder({
firstName: '',
paymentMethod: paymentMethod,
});
const thankYouUrlSearchParams = new URLSearchParams();
thankYouUrlSearchParams.set('contribution', finalAmount.toString());
const nextStepRoute = paymentResultThankyouRoute(
paymentResult,
geoId,
thankYouUrlSearchParams,
);
setIsProcessingPayment(false);
if (nextStepRoute) {
window.location.href = nextStepRoute;
} else {
setErrorMessage('Sorry, something went wrong.');
if (
paymentResult &&
'paymentStatus' in paymentResult &&
paymentResult.paymentStatus === 'failure'
) {
setErrorContext(appropriateErrorMessage(paymentResult.error ?? ''));
if (paymentResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep undefined is assumed failure

setThankYouOrder({
firstName: '',
paymentMethod: paymentMethod,
});
const thankYouUrlSearchParams = new URLSearchParams();
thankYouUrlSearchParams.set('contribution', finalAmount.toString());
const nextStepRoute = paymentResultThankyouRoute(
paymentResult,
geoId,
thankYouUrlSearchParams,
);
if (nextStepRoute) {
window.location.href = nextStepRoute;
} else {
setErrorMessage('Sorry, something went wrong.');
if (
'paymentStatus' in paymentResult &&
paymentResult.paymentStatus === 'failure'
) {
setErrorContext(appropriateErrorMessage(paymentResult.error ?? ''));
}
}
} else {
setIsProcessingPayment(false);
}
}
};
Expand Down Expand Up @@ -765,7 +771,7 @@ function OneTimeCheckoutComponent({
}
onChange={() => {
setPaymentMethod(validPaymentMethod);

setPaymentMethodError(undefined);
// Track payment method selection with QM
sendEventPaymentMethodSelected(validPaymentMethod);
}}
Expand Down Expand Up @@ -821,11 +827,6 @@ function OneTimeCheckoutComponent({
type="submit"
/>
</div>
<div css={tcContainer}>
<FinePrint mobileTheme={'dark'}>
<TsAndCsFooterLinks countryGroupId={countryGroupId} />
</FinePrint>
</div>
{errorMessage && (
<div role="alert" data-qm-error>
<ErrorSummary
Expand All @@ -837,6 +838,11 @@ function OneTimeCheckoutComponent({
/>
</div>
)}
<div css={tcContainer}>
<FinePrint mobileTheme={'dark'}>
<TsAndCsFooterLinks countryGroupId={countryGroupId} />
</FinePrint>
</div>
</BoxContents>
</Box>
</form>
Expand Down