-
Notifications
You must be signed in to change notification settings - Fork 57
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
refactor: enable passing multiple merchant ids #992
Merged
jadutter
merged 5 commits into
paypal:develop
from
surekhaw:fix/disable-multi-merchant-messaging
Oct 10, 2023
Merged
refactor: enable passing multiple merchant ids #992
jadutter
merged 5 commits into
paypal:develop
from
surekhaw:fix/disable-multi-merchant-messaging
Oct 10, 2023
+19
−5
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
surekhaw
changed the title
enable passing multiple merchant ids
fix: enable passing multiple merchant ids
Oct 2, 2023
Seavenly
reviewed
Oct 3, 2023
Comment on lines
71
to
83
let invalidId; | ||
if (!validateType(Types.STRING, merchantId)) { | ||
logInvalidType('merchantId', Types.STRING, merchantId); | ||
} else if (merchantId.length !== 13 && merchantId.length !== 10) { | ||
logInvalid('merchantId', 'Ensure the correct Merchant ID has been entered.'); | ||
} else { | ||
return merchantId; | ||
invalidId = merchantId; | ||
} | ||
const ids = merchantId.toString().split(','); | ||
ids.forEach(id => { | ||
if (id.length !== 13 && id.length !== 10) { | ||
logInvalid('merchantId', 'Ensure the correct Merchant ID has been entered.'); | ||
invalidId = id; | ||
} | ||
}); | ||
return invalidId ? undefined : merchantId; |
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.
Consider the following which contains a few modifications:
- Tightens the scope where
invalidId
(renamed toisInvalid
since we're using it as a boolean) is used to reduce mental overhead - The
forEach
will potentially log multiple times with the same message if there are multiple bad IDs but we only need it to log once. We can make use ofArray.prototype.some
to short circuit after a single invalid match. It will return aboolean
value. - More closely follows the pattern of other validators by returning the value in an
else
block after all checks have passed.
if (!validateType(Types.STRING, merchantId)) {
logInvalidType('merchantId', Types.STRING, merchantId);
} else {
const isInvalid = merchantId.split(',').some(id => id.length !== 13 && id.length !== 10);
if (isInvalid) {
logInvalid('merchantId', 'Ensure the correct Merchant ID has been entered.');
} else {
return merchantId;
}
}
surekhaw
changed the title
fix: enable passing multiple merchant ids
feat: enable passing multiple merchant ids
Oct 3, 2023
Seavenly
changed the title
feat: enable passing multiple merchant ids
refactor: enable passing multiple merchant ids
Oct 9, 2023
Seavenly
approved these changes
Oct 9, 2023
🎉 This PR is included in version 1.49.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
enable passing multiple merchant ids to cpnw.
Screenshots
N/A
Testing instructions
valid merchant ids of 10 or 13 characters should pass when inputted as merchant-id=* and data-merchant-id='id1, id2'. otherwise an appropriate error message will appear in the console.log.