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

Add server side validation for billing address postcode #6759

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tjmw
Copy link
Member

@tjmw tjmw commented Feb 5, 2025

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:

Screenshot 2025-02-06 at 09 32 31

How can we measure success?

Have we considered potential risks?

Accessibility test checklist

Screenshots

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.
Copy link
Contributor

github-actions bot commented Feb 5, 2025

Size Change: +237 B (+0.01%)

Total Size: 1.89 MB

ℹ️ View Unchanged
Filename Size Change
./public/compiled-assets/javascripts/[countryGroupId]/events/router.js 90.3 kB 0 B
./public/compiled-assets/javascripts/[countryGroupId]/router.js 93.4 kB 0 B
./public/compiled-assets/javascripts/ausMomentMap.js 108 kB 0 B
./public/compiled-assets/javascripts/contributionsRedirectStyles.js 20 B 0 B
./public/compiled-assets/javascripts/digitalSubscriptionLandingPage.js 222 kB +50 B (+0.02%)
./public/compiled-assets/javascripts/downForMaintenancePage.js 67.3 kB 0 B
./public/compiled-assets/javascripts/error404Page.js 67.3 kB 0 B
./public/compiled-assets/javascripts/error500Page.js 67.2 kB 0 B
./public/compiled-assets/javascripts/favicons.js 617 B 0 B
./public/compiled-assets/javascripts/paperSubscriptionCheckoutPage.js 163 kB +45 B (+0.03%)
./public/compiled-assets/javascripts/paperSubscriptionLandingPage.js 87.6 kB 0 B
./public/compiled-assets/javascripts/payPalErrorPage.js 65.9 kB 0 B
./public/compiled-assets/javascripts/payPalErrorPageStyles.js 20 B 0 B
./public/compiled-assets/javascripts/promotionTerms.js 73.5 kB 0 B
./public/compiled-assets/javascripts/subscriptionsLandingPage.js 72.9 kB 0 B
./public/compiled-assets/javascripts/subscriptionsRedemptionPage.js 118 kB +48 B (+0.04%)
./public/compiled-assets/javascripts/unsupportedBrowserStyles.js 20 B 0 B
./public/compiled-assets/javascripts/weeklySubscriptionCheckoutPage.js 160 kB +47 B (+0.03%)
./public/compiled-assets/javascripts/weeklySubscriptionLandingPage.js 88.2 kB 0 B
./public/compiled-assets/webpack/114.js 12.2 kB 0 B
./public/compiled-assets/webpack/127.js 3.53 kB 0 B
./public/compiled-assets/webpack/136.js 2.17 kB 0 B
./public/compiled-assets/webpack/163.js 8.9 kB 0 B
./public/compiled-assets/webpack/187.js 20 kB 0 B
./public/compiled-assets/webpack/192.js 5.69 kB 0 B
./public/compiled-assets/webpack/276.js 4.39 kB 0 B
./public/compiled-assets/webpack/344.js 2 kB 0 B
./public/compiled-assets/webpack/445.js 6.87 kB 0 B
./public/compiled-assets/webpack/492.js 7.58 kB 0 B
./public/compiled-assets/webpack/706.js 107 kB 0 B
./public/compiled-assets/webpack/719.js 13.5 kB 0 B
./public/compiled-assets/webpack/847.js 26 kB 0 B
./public/compiled-assets/webpack/969.js 37.9 kB +47 B (+0.12%)
./public/compiled-assets/webpack/checkout.js 17.2 kB 0 B
./public/compiled-assets/webpack/GuardianAdLiteLanding.js 8.27 kB 0 B
./public/compiled-assets/webpack/LandingPage.js 15.5 kB 0 B
./public/compiled-assets/webpack/oneTimeCheckout.js 6.07 kB 0 B
./public/compiled-assets/webpack/ThankYou.js 44.4 kB 0 B

compressed-size-action

@tjmw tjmw marked this pull request as ready for review February 6, 2025 09:42
@@ -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)
Copy link
Contributor

@paul-daniel-dempsey paul-daniel-dempsey Feb 6, 2025

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 {
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor

@paul-daniel-dempsey paul-daniel-dempsey left a 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 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants