Skip to content

Commit

Permalink
resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jkurra-hw committed Nov 20, 2020
1 parent e0258d9 commit 18d64ca
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.hyperwallet.clientsdk.model.*;
import com.hyperwallet.clientsdk.util.HyperwalletApiClient;
import com.hyperwallet.clientsdk.util.HyperwalletEncryption;
import com.hyperwallet.clientsdk.util.HyperwalletJsonUtil;
import com.hyperwallet.clientsdk.util.*;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.TimeZone;
import java.util.*;

/**
* The Hyperwallet Client
Expand Down Expand Up @@ -2287,6 +2283,37 @@ public HyperwalletList<HyperwalletTransferRefund> listTransferRefunds(String tra
});
}

//--------------------------------------
// Upload documents for user endpoint
//--------------------------------------

/**
* Upload documents
*
* @param userToken userToken for which documents to be uploaded
* @param uploadData HyperwalletVerificationDocument to get uploaded
* @return HyperwalletUser user object with document upload status
*/
public HyperwalletUser uploadUserDocuments(String userToken, List<HyperwalletVerificationDocument> uploadData) {
Multipart multipart = new Multipart();
if (StringUtils.isEmpty(userToken)) {
throw new HyperwalletException("User token is not present");
}
if (uploadData == null || uploadData.size() < 1) {
throw new HyperwalletException("Data for upload is missing");
}
if (uploadData.get(0).getUploadFiles() == null || uploadData.get(0).getUploadFiles().size() < 1) {
throw new HyperwalletException("Upload Files are missing");
}
try {
multipart = HyperwalletMultipartUtils.convert(uploadData);
} catch(IOException e) {
throw new HyperwalletException("Unable to convert to Multipart formdata");
}
return apiClient.put(url + "/users/" + userToken, multipart, HyperwalletUser.class);
}


//--------------------------------------
// Internal utils
//--------------------------------------
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7500,4 +7500,66 @@ public void testListTransferRefunds_noTransferToken() {
checkHyperwalletException(e, expectedException);
}
}

//--------------------------------------
// Upload documents for user endpoint
//--------------------------------------

@Test
public void testUploadUserDocuments_noUserToken() {
List<HyperwalletVerificationDocument> testUploadData = new ArrayList<>();
Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.uploadUserDocuments(null,testUploadData);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("User token is not present")));
assertThat(e.getMessage(), is(equalTo("User token is not present")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
assertThat(e.getRelatedResources(), is(nullValue()));
}
}

@Test
public void testUploadUserDocuments_noUploadData() {
List<HyperwalletVerificationDocument> testUploadData = new ArrayList<>();
Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.uploadUserDocuments("test-userToken",null);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("Data for upload is missing")));
assertThat(e.getMessage(), is(equalTo("Data for upload is missing")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
assertThat(e.getRelatedResources(), is(nullValue()));
}
}

@Test
public void testUploadUserDocuments_uploadFilesMissing() {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
List<HyperwalletVerificationDocument> testUploadData = new ArrayList<>();
HyperwalletVerificationDocument hyperwalletVerificationDocument = new HyperwalletVerificationDocument();;
hyperwalletVerificationDocument.setType("test_DRIVERS_LICENSE");
hyperwalletVerificationDocument.setCategory("test_IDENTIFICATION");
hyperwalletVerificationDocument.setCountry("test_US");
Map<String, String> fileList = new HashMap<>();
hyperwalletVerificationDocument.setUploadFiles(fileList);
testUploadData.add(hyperwalletVerificationDocument);
try {
client.uploadUserDocuments("test-userToken",testUploadData);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("Upload Files are missing")));
assertThat(e.getMessage(), is(equalTo("Upload Files are missing")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
assertThat(e.getRelatedResources(), is(nullValue()));
}
}
}

0 comments on commit 18d64ca

Please sign in to comment.