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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/library/zoid/message/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ export default {
if (typeof merchantId !== 'undefined') {
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 {
const isInvalid = merchantId.split(',').some(id => id.length !== 13 && id.length !== 10);
if (isInvalid) {
logInvalid('merchantId', 'Ensure the correct Merchant ID has been entered.');
}
return merchantId;
}
}

return undefined;
},
customerId: ({ props: { customerId } }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function getMerchantConfig() {
export function getAccount() {
if (__MESSAGES__.__TARGET__ === 'SDK') {
// TODO: Should we pass both up if they exist so that nodeweb can create a partner context?
return getMerchantID()[0] || `client-id:${getClientID()}`;
return getMerchantID().join(',') || `client-id:${getClientID()}`;
} else {
return undefined;
}
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/spec/src/zoid/message/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,22 @@ describe('validate', () => {
expect(merchantId).toEqual(merchantId);
expect(console.warn).not.toHaveBeenCalled();

merchantId = validate.merchantId({ props: { merchantId: 'DEV00000000NI,DEV00000001NI' } });
expect(merchantId).toEqual(merchantId);
expect(console.warn).not.toHaveBeenCalled();

merchantId = validate.merchantId({ props: { merchantId: 'DEV00000000,DEV00000001NI' } });

expect(merchantId).toEqual(merchantId);
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenLastCalledWith(
expect.stringContaining('invalid_option_value'),
expect.objectContaining({ location: 'merchantId' })
);

merchantId = validate.merchantId({ props: { merchantId: 'client-id:test_client_id' } });

expect(merchantId).toBeUndefined();
expect(merchantId).toEqual(merchantId);
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenLastCalledWith(
expect.stringContaining('invalid_option_value'),
Expand Down
Loading