use of com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange in project java-sdk by hyperwallet.
the class HyperwalletTest method testCreateTransfer_successful.
@Test
public void testCreateTransfer_successful() throws Exception {
ForeignExchange foreignExchange = new ForeignExchange();
foreignExchange.setSourceAmount(200.0);
foreignExchange.setSourceCurrency("USD");
foreignExchange.setDestinationAmount(100.0);
foreignExchange.setDestinationCurrency("CAD");
foreignExchange.setRate(2.3);
HyperwalletTransfer transfer = new HyperwalletTransfer();
transfer.setSourceToken("test-source-token");
transfer.setDestinationToken("test-destination-token");
transfer.setStatus(HyperwalletTransfer.Status.QUOTED);
transfer.setCreatedOn(new Date());
transfer.setClientTransferId("test-client-transfer-id");
transfer.setSourceCurrency("USD");
transfer.setForeignExchanges(Collections.singletonList(foreignExchange));
HyperwalletTransfer transferResponse = new HyperwalletTransfer();
Hyperwallet client = new Hyperwallet("test-username", "test-password");
HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);
Mockito.when(mockApiClient.post(ArgumentMatchers.anyString(), ArgumentMatchers.anyObject(), ArgumentMatchers.any(Class.class))).thenReturn(transferResponse);
HyperwalletTransfer resp = client.createTransfer(transfer);
assertThat(resp, is(equalTo(transferResponse)));
ArgumentCaptor<HyperwalletTransfer> argument = ArgumentCaptor.forClass(HyperwalletTransfer.class);
Mockito.verify(mockApiClient).post(ArgumentMatchers.eq("https://api.sandbox.hyperwallet.com/rest/v4/transfers"), argument.capture(), ArgumentMatchers.eq(transfer.getClass()));
HyperwalletTransfer apiTransfer = argument.getValue();
assertThat(apiTransfer, is(notNullValue()));
assertThat(apiTransfer.getSourceToken(), is(equalTo("test-source-token")));
assertThat(apiTransfer.getClientTransferId(), is(equalTo("test-client-transfer-id")));
assertThat(apiTransfer.getSourceCurrency(), is(equalTo("USD")));
assertThat(apiTransfer.getStatus(), is(nullValue()));
assertThat(apiTransfer.getCreatedOn(), is(nullValue()));
assertThat(apiTransfer.getExpiresOn(), is(nullValue()));
ForeignExchange foreignExchangeResponse = apiTransfer.getForeignExchanges().get(0);
assertThat(foreignExchange.getSourceAmount(), is(equalTo(200.0)));
assertThat(foreignExchange.getSourceCurrency(), is(equalTo("USD")));
assertThat(foreignExchange.getDestinationAmount(), is(equalTo(100.0)));
assertThat(foreignExchange.getDestinationCurrency(), is(equalTo("CAD")));
assertThat(foreignExchange.getRate(), is(equalTo(2.3)));
}
use of com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange in project java-sdk by hyperwallet.
the class HyperwalletIT method testCreateTransfer.
//
// Transfers
//
@Test
public void testCreateTransfer() throws Exception {
String functionality = "createTransfer";
initMockServer(functionality);
HyperwalletTransfer transfer = new HyperwalletTransfer().sourceToken("usr-c4292f1a-866f-4310-a289-b916853939de").destinationToken("trm-ff53d939-49c3-412f-8d83-ab4f7e83d553").clientTransferId("clientTransferId");
HyperwalletTransfer returnValue;
try {
returnValue = client.createTransfer(transfer);
} catch (Exception e) {
mockServer.verify(parseRequest(functionality));
throw e;
}
List<HyperwalletLink> hyperwalletLinks = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLink.setHref("https://api.sandbox.hyperwallet.com/rest/v4/transfers/trf-59f67c62-fd06-497e-a9ea-99d6eb38b12b");
Map<String, String> mapParams = new HashMap<>();
mapParams.put("rel", "self");
hyperwalletLink.setParams(mapParams);
hyperwalletLinks.add(hyperwalletLink);
assertThat(returnValue.getToken(), is(equalTo("trm-59f67c62-fd06-497e-a9ea-99d6eb38b12b")));
assertThat(returnValue.getStatus(), is(equalTo(HyperwalletTransfer.Status.QUOTED)));
assertThat(returnValue.getCreatedOn(), is(equalTo(dateFormat.parse("2017-10-31T22:32:57 UTC"))));
assertThat(returnValue.getClientTransferId(), is(equalTo("clientTransferId")));
assertThat(returnValue.getSourceToken(), is(equalTo("usr-c4292f1a-866f-4310-a289-b916853939de")));
assertThat(returnValue.getSourceAmount(), is(equalTo("2100.4")));
assertThat(returnValue.getSourceFeeAmount(), is(equalTo("20.3")));
assertThat(returnValue.getSourceCurrency(), is(equalTo("USD")));
assertThat(returnValue.getDestinationToken(), is(equalTo("usr-c4292f1a-866f-4310-a289-b916853939de")));
assertThat(returnValue.getDestinationAmount(), is(equalTo("2100.2")));
assertThat(returnValue.getDestinationFeeAmount(), is(equalTo("30.5")));
assertThat(returnValue.getDestinationCurrency(), is(equalTo("USD")));
assertThat(returnValue.getNotes(), is(equalTo("notes")));
assertThat(returnValue.getMemo(), is(equalTo("memo")));
assertThat(returnValue.getExpiresOn(), is(equalTo(dateFormat.parse("2017-10-31T22:32:57 UTC"))));
ForeignExchange foreignExchange = returnValue.getForeignExchanges().get(0);
assertThat(foreignExchange.getSourceAmount(), is(equalTo(100.00)));
assertThat(foreignExchange.getSourceCurrency(), is(equalTo("USD")));
assertThat(foreignExchange.getDestinationAmount(), is(equalTo(63.49)));
assertThat(foreignExchange.getDestinationCurrency(), is(equalTo("CAD")));
assertThat(foreignExchange.getRate(), is(equalTo(0.79)));
HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0);
HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0);
assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref())));
assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams());
}
use of com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange in project java-sdk by hyperwallet.
the class HyperwalletIT method checkForeignExchange.
private void checkForeignExchange(HyperwalletTransferRefund actual, HyperwalletTransferRefund expected) {
ForeignExchange foreignExchange = actual.getForeignExchanges().get(0);
assertThat(foreignExchange.getSourceAmount(), is(equalTo(100.00)));
assertThat(foreignExchange.getSourceCurrency(), is(equalTo("USD")));
assertThat(foreignExchange.getDestinationAmount(), is(equalTo(63.49)));
assertThat(foreignExchange.getDestinationCurrency(), is(equalTo("CAD")));
assertThat(foreignExchange.getRate(), is(equalTo(0.79)));
}
use of com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange in project java-sdk by hyperwallet.
the class HyperwalletTransferRefundTest method createBaseModel.
@Override
protected HyperwalletTransferRefund createBaseModel() {
List<HyperwalletLink> hyperwalletLinkList = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLinkList.add(hyperwalletLink);
ForeignExchange foreignExchange = new ForeignExchange();
foreignExchange.setSourceAmount(200.0);
foreignExchange.setSourceCurrency("USD");
foreignExchange.setDestinationAmount(100.0);
foreignExchange.setDestinationCurrency("CAD");
foreignExchange.setRate(2.3);
HyperwalletTransferRefund transferRefund = new HyperwalletTransferRefund().token("token").status(Status.COMPLETED).clientRefundId("clientRefundId").sourceToken("sourceToken").sourceAmount(20.00).sourceCurrency("USD").destinationToken("destinationToken").destinationAmount(20.00).destinationCurrency("USD").createdOn(new Date()).notes("notes").memo("memo").links(hyperwalletLinkList).foreignExchanges(Collections.singletonList(foreignExchange));
return transferRefund;
}
use of com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange in project java-sdk by hyperwallet.
the class HyperwalletIT method testGetTransfer.
@Test
public void testGetTransfer() throws Exception {
String functionality = "getTransfer";
initMockServer(functionality);
HyperwalletTransfer returnValue;
try {
returnValue = client.getTransfer("usr-c4292f1a-866f-4310-a289-b916853939de");
} catch (Exception e) {
mockServer.verify(parseRequest(functionality));
throw e;
}
List<HyperwalletLink> hyperwalletLinks = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLink.setHref("https://api.sandbox.hyperwallet.com/rest/v4/transfers/trf-59f67c62-fd06-497e-a9ea-99d6eb38b12b");
Map<String, String> mapParams = new HashMap<>();
mapParams.put("rel", "self");
hyperwalletLink.setParams(mapParams);
hyperwalletLinks.add(hyperwalletLink);
assertThat(returnValue.getToken(), is(equalTo("trm-59f67c62-fd06-497e-a9ea-99d6eb38b12b")));
assertThat(returnValue.getStatus(), is(equalTo(HyperwalletTransfer.Status.QUOTED)));
assertThat(returnValue.getCreatedOn(), is(equalTo(dateFormat.parse("2017-10-31T22:32:57 UTC"))));
assertThat(returnValue.getClientTransferId(), is(equalTo("clientTransferId")));
assertThat(returnValue.getSourceToken(), is(equalTo("usr-c4292f1a-866f-4310-a289-b916853939de")));
assertThat(returnValue.getSourceAmount(), is(equalTo("200.4")));
assertThat(returnValue.getSourceFeeAmount(), is(equalTo("20.3")));
assertThat(returnValue.getSourceCurrency(), is(equalTo("USD")));
assertThat(returnValue.getDestinationToken(), is(equalTo("usr-c4292f1a-866f-4310-a289-b916853939de")));
assertThat(returnValue.getDestinationAmount(), is(equalTo("100.2")));
assertThat(returnValue.getDestinationFeeAmount(), is(equalTo("30.5")));
assertThat(returnValue.getDestinationCurrency(), is(equalTo("USD")));
assertThat(returnValue.getNotes(), is(equalTo("notes")));
assertThat(returnValue.getMemo(), is(equalTo("memo")));
assertThat(returnValue.getExpiresOn(), is(equalTo(dateFormat.parse("2017-10-31T22:32:57 UTC"))));
ForeignExchange foreignExchange = returnValue.getForeignExchanges().get(0);
assertThat(foreignExchange.getSourceAmount(), is(equalTo(100.00)));
assertThat(foreignExchange.getSourceCurrency(), is(equalTo("USD")));
assertThat(foreignExchange.getDestinationAmount(), is(equalTo(63.49)));
assertThat(foreignExchange.getDestinationCurrency(), is(equalTo("CAD")));
assertThat(foreignExchange.getRate(), is(equalTo(0.79)));
HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0);
HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0);
assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref())));
assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams());
}
Aggregations