Skip to content

Commit

Permalink
Code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
VSydor committed Nov 14, 2024
1 parent 492e89e commit eb66d00
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -423,7 +424,7 @@ protected MemberInfo toMcMemberInfo(EnvironmentConfig.CommunicationPlatform mail
mcContact.merge_fields.mapping.put(LAST_NAME, crmContact.lastName);
mcContact.merge_fields.mapping.put(PHONE_NUMBER, crmContact.mobilePhone);

if (smsAllowed(crmContact, mailchimpConfig)) {
if (smsAllowed(mailchimpConfig, crmContact)) {
mcContact.consents_to_one_to_one_messaging = true;
mcContact.sms_subscription_status = SUBSCRIBED;
String phoneNumber = crmContact.phoneNumberForSMS();
Expand All @@ -443,7 +444,7 @@ protected MemberInfo toMcMemberInfo(EnvironmentConfig.CommunicationPlatform mail
return mcContact;
}

private boolean smsAllowed(CrmContact crmContact, EnvironmentConfig.CommunicationPlatform mailchimpConfig) {
private boolean smsAllowed(EnvironmentConfig.CommunicationPlatform mailchimpConfig, CrmContact crmContact) {
boolean smsOptIn = Boolean.TRUE == crmContact.smsOptIn && Boolean.FALSE == crmContact.smsOptOut;
if (!smsOptIn) {
return false;
Expand All @@ -456,10 +457,12 @@ private boolean smsAllowed(CrmContact crmContact, EnvironmentConfig.Communicatio
boolean smsAllowed = false;
if (!Strings.isNullOrEmpty(mailchimpConfig.countryCode) && phoneNumber.startsWith(mailchimpConfig.countryCode)) {
smsAllowed = true;
} else if (!phoneNumber.startsWith("+") && !Strings.isNullOrEmpty(mailchimpConfig.country)
&& crmContact.account.billingAddress != null && !Strings.isNullOrEmpty(crmContact.account.billingAddress.country)
&& crmContact.account.billingAddress.country.equalsIgnoreCase(mailchimpConfig.country)) {
smsAllowed = true;
} else if (!Strings.isNullOrEmpty(mailchimpConfig.country) && !phoneNumber.startsWith("+")) {
smsAllowed = Stream.of(crmContact.account.billingAddress, crmContact.account.mailingAddress, crmContact.mailingAddress)
.filter(Objects::nonNull)
.map(crmAddress -> crmAddress.country)
.filter(country -> mailchimpConfig.country.equalsIgnoreCase(country))
.findFirst().isPresent();
}
return smsAllowed;
}
Expand Down

0 comments on commit eb66d00

Please sign in to comment.