Skip to content
Open
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
10 changes: 7 additions & 3 deletions src/main/java/com/beanstream/api/ProfilesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/beanstream/util/ProfilesUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -88,6 +88,8 @@ public static void validateProfileReq(ProfileRequest profileRequest)
validateToken(token);
}

validateBillingAddr(billing);
if (validateBillingAddress){
validateBillingAddr(billing);
}
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/beanstream/api/test/ProfilesAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down