feat: For Shipping Zones Zip Regex - Correctly handle UK postcodes redacted by Apple Pay #3592
+46
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improved upon idea in #2646 So that user does not need to add special syntax into shipping zones regex
Fixes #2645
Changes proposed in this Pull Request:
UK Postcodes consist of an outcode 2,3 or 4 characters long, then an optional space, and then 3 more characters.
Apple Pay intelligently truncates the UK postcode removing the outcode. Futhermore It keeps the optional space at the end of it's redacted string if it was there in the original.
With this behaviour known, we need to code it more intelligently when padding with stars than just assuming a UK postcode is 7 characters long.
This PR implements that behaviour.
This also enabled full support for the Regex within Shipping Zones so that Regex like
N1 *
(N1 space star) correctly match postcodes like N12AA and N1 2AA to mean all N1 postcodes and correctly avoids accidental matches of N10, N11, N12 postcodes etcThis enabled proper bevaviour of shipping zones such that a user can ship to N1 for one price and N19 for another. The main scenario of this is an artistan seller/maker who will drive or walk to N1 to hand deliver, but won't to N19 without a fee (or even not at all)
Questions for the PR author:
If Apple changed the way it redacts the postcodes
if the truncated postcode excluding space is more than 5 characters, it just returns it as is as it is highly likely it is has not been truncated. This is because it would be a bad implementation by a third party to truncate a postcode to 5 chars for privacy reasons, when many true valid postcodes are 5 characters long.
Also the only impact of the postcode not validating is that shipping zones come up wrong due to non matches of the truncated/altered postcode. Therefore the behaviour cannot be made any worse than now.
Testing instructions
Admin: Enable Apple pay via Stripe on the Basket
Admin: Setup shipping zones with a regex like 'N1 *' for free and 'N10 * for a fee.
Customer: Setup addresses in your real apple pay on your device eg N1 4AB, N10 5BC, N11AA, N191AA (you can set any addresses as you don't need to complete purchases or validate addresses)
Customer: Add items to the basket
Customer: for each of the addresses in apple pay
Unit tests not added as this piece of code yet as it didn't have any before - however can easily add some if this change is likely to progress into the codebase
changelog.txt
andreadme.txt
(or does not apply)Post merge