Skip to content

Commit

Permalink
Changes for HW-66706-V4PrepaidCards
Browse files Browse the repository at this point in the history
  • Loading branch information
ramahalingam committed Sep 10, 2020
1 parent 702857b commit 30e37cb
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public HyperwalletList<HyperwalletStatusTransition> listUserStatusTransitions(St
* @param prepaidCard Prepaid Card object to create
* @return HyperwalletPrepaidCard Prepaid Card object created
*/
public HyperwalletPrepaidCard createPrepaidCard(HyperwalletPrepaidCard prepaidCard) {
public HyperwalletPrepaidCard createOrReplacePrepaidCard(HyperwalletPrepaidCard prepaidCard) {
if (prepaidCard == null) {
throw new HyperwalletException("Prepaid Card is required");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public enum Brand {VISA, MASTERCARD}

public enum CardType {PERSONALIZED, INSTANT_ISSUE, VIRTUAL}

public enum EReplacePrepaidCardReason {LOST_STOLEN, DAMAGED, COMPROMISED, EXPIRED, VIRTUAL_TO_PHYSICAL}

private HyperwalletTransferMethod.Type type;

private String token;
Expand All @@ -37,6 +39,8 @@ public enum CardType {PERSONALIZED, INSTANT_ISSUE, VIRTUAL}

private String userToken;
private List<HyperwalletLink> links;
private String replacementOf;
private EReplacePrepaidCardReason replacementReason;

public HyperwalletTransferMethod.Type getType() {
return type;
Expand Down Expand Up @@ -310,4 +314,46 @@ public HyperwalletPrepaidCard clearLinks() {
this.links = null;
return this;
}

public String getReplacementOf() {
return replacementOf;
}

public void setReplacementOf(String replacementOf) {
addField("replacementOf", replacementOf);
this.replacementOf = replacementOf;
}

public HyperwalletPrepaidCard replacementOf(String replacementOf) {
addField("replacementOf", replacementOf);
this.replacementOf = replacementOf;
return this;
}

public HyperwalletPrepaidCard clearReplacementOf() {
clearField("replacementOf");
this.replacementOf = null;
return this;
}

public EReplacePrepaidCardReason getReplacementReason() {
return replacementReason;
}

public void setReplacementReason(EReplacePrepaidCardReason replacementReason) {
addField("replacementReason", replacementReason);
this.replacementReason = replacementReason;
}

public HyperwalletPrepaidCard replacementReason(EReplacePrepaidCardReason replacementReason) {
addField("replacementReason", replacementReason);
this.replacementReason = replacementReason;
return this;
}

public HyperwalletPrepaidCard clearReplacementReason() {
clearField("replacementReason");
this.replacementReason = null;
return this;
}
}
54 changes: 53 additions & 1 deletion src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.hyperwallet.clientsdk;

import com.hyperwallet.clientsdk.model.*;
import com.hyperwallet.clientsdk.model.HyperwalletPrepaidCard.Brand;
import com.hyperwallet.clientsdk.model.HyperwalletPrepaidCard.CardType;
import com.hyperwallet.clientsdk.model.HyperwalletPrepaidCard.EReplacePrepaidCardReason;
import com.hyperwallet.clientsdk.model.HyperwalletTransferMethod.Type;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpRequest;
Expand Down Expand Up @@ -112,7 +115,7 @@ public void testCreatePrepaidCard() throws Exception {

HyperwalletPrepaidCard returnValue;
try {
returnValue = client.createPrepaidCard(prepaidCard);
returnValue = client.createOrReplacePrepaidCard(prepaidCard);
} catch (Exception e) {
mockServer.verify(parseRequest(functionality));
throw e;
Expand Down Expand Up @@ -257,6 +260,55 @@ public void testListPrepaidCard() throws Exception {
assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams());
}

@Test
public void testReplacePrepaidCard() throws Exception {
String functionality = "replacePrepaidCard";
initMockServer(functionality);

HyperwalletPrepaidCard prepaidCard = new HyperwalletPrepaidCard()
.userToken("usr-c4292f1a-866f-4310-a289-b916853939de")
.type(Type.PREPAID_CARD)
.replacementOf("trm-3e23841c-34fd-41b1-9b81-ac2c3ad5ab84")
.replacementReason(EReplacePrepaidCardReason.DAMAGED)
.cardPackage("L1");

HyperwalletPrepaidCard returnValue;
try {
returnValue = client.createOrReplacePrepaidCard(prepaidCard);
} catch (Exception e) {
mockServer.verify(parseRequest(functionality));
throw e;
}

List<HyperwalletLink> hyperwalletLinks = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLink.setHref(
"https://localhost-hyperwallet.aws.paylution.net:8181/rest/v4/users/usr-85e743a2-beec-4817-9a10-2e0aede9afd7/prepaid-cards/trm"
+ "-3e23841c-34fd-41b1-9b81-ac2c3ad5ab84");
Map<String, String> mapParams = new HashMap<>();
mapParams.put("rel", "self");
hyperwalletLink.setParams(mapParams);
hyperwalletLinks.add(hyperwalletLink);

assertThat(returnValue.getToken(), is(equalTo("trm-3e23841c-34fd-41b1-9b81-ac2c3ad5ab84")));
assertThat(returnValue.getType(), is(equalTo(HyperwalletTransferMethod.Type.PREPAID_CARD)));
assertThat(returnValue.getStatus(), is(equalTo(HyperwalletTransferMethod.Status.PRE_ACTIVATED)));
assertThat(returnValue.getTransferMethodCountry(), is(equalTo("US")));
assertThat(returnValue.getTransferMethodCurrency(), is(equalTo("USD")));
assertThat(returnValue.getCardType(), is(equalTo(CardType.PERSONALIZED)));
assertThat(returnValue.getCardPackage(), is(equalTo("L1")));
assertThat(returnValue.getCardNumber(), is(equalTo("************0843")));
assertThat(returnValue.getCardBrand(), is(equalTo(Brand.VISA)));
assertThat(returnValue.getCreatedOn(), is(equalTo(dateFormat.parse("2020-09-10T14:31:43 UTC"))));
assertThat(returnValue.getDateOfExpiry(), is(equalTo(dateFormat.parse("2024-09-01T00:00:00 UTC"))));
assertThat(returnValue.getUserToken(), is(equalTo("usr-85e743a2-beec-4817-9a10-2e0aede9afd7")));
HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0);
HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0);
assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref())));
assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams());

}

//
// Bank Cards
//
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public void testListUserStatusTransitions_withSomeParameters() throws Exception
public void testCreatePrepaidCard_noPrepaidCard() {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.createPrepaidCard(null);
client.createOrReplacePrepaidCard(null);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
Expand All @@ -560,7 +560,7 @@ public void testCreatePrepaidCard_noUserToken() {

Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.createPrepaidCard(prepaidCard);
client.createOrReplacePrepaidCard(prepaidCard);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
Expand All @@ -580,7 +580,7 @@ public void testCreatePrepaidCard_prepaidCardTokenSpecified() {

Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.createPrepaidCard(prepaidCard);
client.createOrReplacePrepaidCard(prepaidCard);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
Expand Down Expand Up @@ -613,7 +613,7 @@ public void testCreatePrepaidCard_noType() throws Exception {

Mockito.when(mockApiClient.post(Mockito.anyString(), Mockito.anyObject(), Mockito.any(Class.class))).thenReturn(prepaidCardResponse);

HyperwalletPrepaidCard resp = client.createPrepaidCard(prepaidCard);
HyperwalletPrepaidCard resp = client.createOrReplacePrepaidCard(prepaidCard);
assertThat(resp, is(equalTo(prepaidCardResponse)));

ArgumentCaptor<HyperwalletPrepaidCard> argument = ArgumentCaptor.forClass(HyperwalletPrepaidCard.class);
Expand Down Expand Up @@ -656,7 +656,7 @@ public void testCreatePrepaidCard_withType() throws Exception {

Mockito.when(mockApiClient.post(Mockito.anyString(), Mockito.anyObject(), Mockito.any(Class.class))).thenReturn(prepaidCardResponse);

HyperwalletPrepaidCard resp = client.createPrepaidCard(prepaidCard);
HyperwalletPrepaidCard resp = client.createOrReplacePrepaidCard(prepaidCard);
assertThat(resp, is(equalTo(prepaidCardResponse)));

ArgumentCaptor<HyperwalletPrepaidCard> argument = ArgumentCaptor.forClass(HyperwalletPrepaidCard.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hyperwallet.clientsdk.model;

import com.hyperwallet.clientsdk.model.HyperwalletPrepaidCard.EReplacePrepaidCardReason;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -29,6 +31,8 @@ protected HyperwalletPrepaidCard createBaseModel() {

.dateOfExpiry(new Date())
.userToken("test-user-token")
.replacementOf("replacementOf")
.replacementReason(EReplacePrepaidCardReason.DAMAGED)
.links(hyperwalletLinkList);
return prepaidCard;
}
Expand Down

0 comments on commit 30e37cb

Please sign in to comment.