diff --git a/src/main/java/com/beanstream/api/ProfilesAPI.java b/src/main/java/com/beanstream/api/ProfilesAPI.java index e7c1bc4..d78813c 100644 --- a/src/main/java/com/beanstream/api/ProfilesAPI.java +++ b/src/main/java/com/beanstream/api/ProfilesAPI.java @@ -61,6 +61,8 @@ public class ProfilesAPI { private Configuration config; private HttpsConnector connector; private final Gson gson = new Gson(); + private final boolean validateBillingAddress = + Boolean.valueOf(System.getProperty("bamboraSDK.profiles.validateBillingAddress", "true")); public ProfilesAPI(Configuration config) { this.config = config; @@ -186,7 +188,7 @@ private ProfileResponse createProfile(Card card, Token token, ProfileRequest req = new ProfileRequest(card, token, billing, custom, language, comments); - ProfilesUtils.validateProfileReq(req); + ProfilesUtils.validateProfileReq(req, validateBillingAddress); String url = PaymentsUrls.getProfilesUrl(config.getPlatform(), config.getVersion()); @@ -253,8 +255,10 @@ public ProfileResponse updateProfile(PaymentProfile profile) Gateway.assertNotNull(profile, "profile to update is null"); ProfilesUtils.validateProfileId(profile.getId()); - ProfilesUtils.validateBillingAddr(profile.getBilling()); - + if (validateBillingAddress){ + ProfilesUtils.validateBillingAddr(profile.getBilling()); + } + String url = PaymentsUrls.getProfilesUrl(config.getPlatform(), config.getVersion(), profile.getId()); diff --git a/src/main/java/com/beanstream/util/ProfilesUtils.java b/src/main/java/com/beanstream/util/ProfilesUtils.java index da26d7a..e4f14d5 100644 --- a/src/main/java/com/beanstream/util/ProfilesUtils.java +++ b/src/main/java/com/beanstream/util/ProfilesUtils.java @@ -68,7 +68,7 @@ public static void validateBillingAddr(Address billing) * a BeanstreamApiException with a bad request status, if any required * property is missing */ - public static void validateProfileReq(ProfileRequest profileRequest) + public static void validateProfileReq(ProfileRequest profileRequest, boolean validateBillingAddress) throws BeanstreamApiException { Gateway.assertNotNull(profileRequest, "profile request object is null"); Card card = profileRequest.getCard(); @@ -88,6 +88,8 @@ public static void validateProfileReq(ProfileRequest profileRequest) validateToken(token); } - validateBillingAddr(billing); + if (validateBillingAddress){ + validateBillingAddr(billing); + } } } diff --git a/src/test/java/com/beanstream/api/test/ProfilesAPITest.java b/src/test/java/com/beanstream/api/test/ProfilesAPITest.java index d30d89d..a953b25 100644 --- a/src/test/java/com/beanstream/api/test/ProfilesAPITest.java +++ b/src/test/java/com/beanstream/api/test/ProfilesAPITest.java @@ -134,6 +134,25 @@ public void invalidBillingAddrCreateProfile() { } + @Test + public void testProfileCreationWhenDisabledAddressValidation() throws BeanstreamApiException { + + System.setProperty("bamboraSDK.profiles.validateBillingAddress", "false"); + + Address nullBillingAddress = null; + Card card = getTestCard(); + + try { + ProfileResponse createdProfile = gateway.profiles().createProfile(card, nullBillingAddress); + + Assert.assertNotNull(createdProfile.getId()); + Assert.assertNotNull(createdProfile.getCode()); + + }finally { + System.clearProperty("bamboraSDK.profiles.validateBillingAddress"); + } + } + @Test public void testProfileCrudUsingCard() throws BeanstreamApiException { String profileId = null;