-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add server side validation for billing address postcode #6759
base: main
Are you sure you want to change the base?
Conversation
We've had an ongoing issue where requests where the payment method is PayPal make it to support workers with an email address in the billing postcode field. We're not sure why this happens but are hoping some server side validation will prevent it and alert users that they need to fix something. It primarily seems to affect USD Supporter Plus and recurring contributions (we collect the postcode for these) so I've focused on fixing those cases, in the PaidProductValidation object used by both products. I've introduced a concept of a preservable error message, i.e. something we can map to copy to show the user. It'd be nice to extend this but for now it's a one off for this field. As it stands, it's not perfect - if there are other validation errors we'll lose the message. I'd like to fix that in a future PR.
Size Change: +237 B (+0.01%) Total Size: 1.89 MB ℹ️ View Unchanged
|
@@ -102,6 +112,7 @@ object CheckoutValidationRules { | |||
case _: Contribution => PaidProductValidation.passes(createSupportWorkersRequest) | |||
case _: GuardianAdLite => PaidProductValidation.passes(createSupportWorkersRequest) | |||
}) match { | |||
case Invalid(message) if PreservableErrorMessages.isMessagePreservable(message) => Invalid(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presume this converts to a invalidPostCode
message to be picked up in errorReasons.tsx
later
@@ -393,6 +393,13 @@ class PaidProductValidationTest extends AnyFlatSpec with Matchers { | |||
PaidProductValidation.passes(requestSupporterPlus) shouldBe Valid | |||
} | |||
|
|||
it should "fail if the billing postcode field contains an email address" in { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for help getting tests running, works great with @
) | ||
) and | ||
// For products which use this validation, we only collect postal/zip code in the US | ||
hasValidBillingPostcodeCharacters(createSupportWorkersRequest.billingAddress.postCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Comment, presume this limits to the US postcodes only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look's great, keen to see how we get on here 🤞
What are you doing in this PR?
Add server side validation for billing address postcode.
Trello Card
Why are you doing this?
We've had an ongoing issue where requests where the payment method is PayPal make it to support workers with an email address in the billing postcode field. We're not sure why this happens but are hoping some server side validation will prevent it and alert users that they need to fix something. It primarily seems to affect USD Supporter Plus and recurring contributions (we collect the postcode for these) so I've focused on fixing those cases, in the PaidProductValidation object used by both products.
I've introduced a concept of a preservable error message, i.e. something we can map to copy to show the user. It'd be nice to extend this but for now it's a one off for this field. As it stands, it's not perfect - if there are other validation errors we'll lose the message. I'd like to fix that in a future PR.
Note: The error message copy needs updating.Copy has been updated.How to test
Entering something which looks like an email address (contains an
@
character) triggers the validation:How can we measure success?
Have we considered potential risks?
Accessibility test checklist
Screenshots