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

refactor: enable passing multiple merchant ids #992

Merged

Conversation

surekhaw
Copy link
Contributor

@surekhaw surekhaw commented Oct 2, 2023

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.

@surekhaw surekhaw requested a review from Seavenly October 2, 2023 22:25
@surekhaw surekhaw changed the title enable passing multiple merchant ids fix: enable passing multiple merchant ids Oct 2, 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;
Copy link
Collaborator

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:

  1. Tightens the scope where invalidId (renamed to isInvalid since we're using it as a boolean) is used to reduce mental overhead
  2. 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 of Array.prototype.some to short circuit after a single invalid match. It will return a boolean value.
  3. 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 surekhaw changed the title fix: enable passing multiple merchant ids feat: enable passing multiple merchant ids Oct 3, 2023
@Seavenly Seavenly changed the title feat: enable passing multiple merchant ids refactor: enable passing multiple merchant ids Oct 9, 2023
@jadutter jadutter merged commit 4ac100f into paypal:develop Oct 10, 2023
49 checks passed
github-actions bot pushed a commit that referenced this pull request Oct 11, 2023
### [1.49.1](v1.49.0...v1.49.1) (2023-10-11)

### Code Refactoring

* enable passing multiple merchant ids ([#992](#992)) ([4ac100f](4ac100f))
* update modal css ([#996](#996)) ([8dc900d](8dc900d))
* update when error icon shows in Pay Monthly modal ([#988](#988)) ([08c126f](08c126f))
@github-actions
Copy link

🎉 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants