Search in sources :

Example 6 with ForeignExchange

use of com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange in project java-sdk by hyperwallet.

the class HyperwalletIT method testListTransfer.

@Test
public void testListTransfer() throws Exception {
    String functionality = "listTransfers";
    initMockServer(functionality);
    HyperwalletList<HyperwalletTransfer> returnValue;
    try {
        returnValue = client.listTransfers();
    } 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?offset=0&limit=10");
    Map<String, String> mapParams = new HashMap<>();
    mapParams.put("rel", "self");
    hyperwalletLink.setParams(mapParams);
    hyperwalletLinks.add(hyperwalletLink);
    assertThat(returnValue.hasNextPage(), is(equalTo(false)));
    assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
    HyperwalletTransfer hyperwalletTransfer = returnValue.getData().get(0);
    assertThat(hyperwalletTransfer.getToken(), is(equalTo("trm-59f67c62-fd06-497e-a9ea-99d6eb38b12b")));
    assertThat(hyperwalletTransfer.getStatus(), is(equalTo(HyperwalletTransfer.Status.QUOTED)));
    assertThat(hyperwalletTransfer.getCreatedOn(), is(equalTo(dateFormat.parse("2017-10-31T22:32:57 UTC"))));
    assertThat(hyperwalletTransfer.getClientTransferId(), is(equalTo("clientTransferId")));
    assertThat(hyperwalletTransfer.getSourceToken(), is(equalTo("usr-c4292f1a-866f-4310-a289-b916853939de")));
    assertThat(hyperwalletTransfer.getSourceAmount(), is(equalTo(String.valueOf(200.4))));
    assertThat(hyperwalletTransfer.getSourceFeeAmount(), is(equalTo(String.valueOf(20.3))));
    assertThat(hyperwalletTransfer.getSourceCurrency(), is(equalTo("USD")));
    assertThat(hyperwalletTransfer.getDestinationToken(), is(equalTo("usr-c4292f1a-866f-4310-a289-b916853939de")));
    assertThat(hyperwalletTransfer.getDestinationAmount(), is(equalTo(String.valueOf(100.2))));
    assertThat(hyperwalletTransfer.getDestinationFeeAmount(), is(equalTo(String.valueOf(30.5))));
    assertThat(hyperwalletTransfer.getDestinationCurrency(), is(equalTo("USD")));
    assertThat(hyperwalletTransfer.getNotes(), is(equalTo("notes")));
    assertThat(hyperwalletTransfer.getMemo(), is(equalTo("memo")));
    assertThat(hyperwalletTransfer.getExpiresOn(), is(equalTo(dateFormat.parse("2017-10-31T22:32:57 UTC"))));
    ForeignExchange foreignExchange = hyperwalletTransfer.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());
}
Also used : ForeignExchange(com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 7 with ForeignExchange

use of com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange in project java-sdk by hyperwallet.

the class HyperwalletTest method testCreateTransferRefund_successful.

@Test
public void testCreateTransferRefund_successful() throws Exception {
    String clientRefundId = "clientRefundId";
    double sourceAmount = 20.0;
    String notes = "notes";
    String memo = "memo";
    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();
    transferRefund.setClientRefundId(clientRefundId);
    transferRefund.setSourceAmount(sourceAmount);
    transferRefund.setNotes(notes);
    transferRefund.setMemo(memo);
    transferRefund.setForeignExchanges(Collections.singletonList(foreignExchange));
    HyperwalletTransferRefund transferRefundResponse = new HyperwalletTransferRefund();
    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(transferRefundResponse);
    String transferToken = "transferToken";
    HyperwalletTransferRefund resp = client.createTransferRefund(transferToken, transferRefund);
    assertThat(resp, is(equalTo(transferRefundResponse)));
    ArgumentCaptor<HyperwalletTransferRefund> argument = ArgumentCaptor.forClass(HyperwalletTransferRefund.class);
    Mockito.verify(mockApiClient).post(ArgumentMatchers.eq("https://api.sandbox.hyperwallet.com/rest/v4/transfers/" + transferToken + "/refunds"), argument.capture(), ArgumentMatchers.eq(transferRefund.getClass()));
    HyperwalletTransferRefund apiTransfer = argument.getValue();
    assertThat(apiTransfer, is(notNullValue()));
    assertThat(apiTransfer.getClientRefundId(), is(equalTo(clientRefundId)));
    assertThat(apiTransfer.getSourceAmount(), is(equalTo(sourceAmount)));
    assertThat(apiTransfer.getNotes(), is(equalTo(notes)));
    assertThat(apiTransfer.getMemo(), is(equalTo(memo)));
    assertThat(apiTransfer.getCreatedOn(), is(nullValue()));
    assertThat(apiTransfer.getStatus(), 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)));
}
Also used : HyperwalletApiClient(com.hyperwallet.clientsdk.util.HyperwalletApiClient) ForeignExchange(com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange) Test(org.testng.annotations.Test)

Example 8 with ForeignExchange

use of com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange in project java-sdk by hyperwallet.

the class HyperwalletTest method testCreateTransfer_source_destionation_amounts_more_than_1k_successful.

@Test
public void testCreateTransfer_source_destionation_amounts_more_than_1k_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.sourceAmount("2,100");
    transfer.sourceFeeAmount("10");
    transfer.setDestinationToken("test-destination-token");
    transfer.destinationAmount("2,100");
    transfer.destinationFeeAmount("10");
    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()));
    assertThat(apiTransfer.getSourceAmount(), is(equalTo("2,100")));
    assertThat(apiTransfer.getDestinationAmount(), is(equalTo("2,100")));
    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)));
}
Also used : HyperwalletApiClient(com.hyperwallet.clientsdk.util.HyperwalletApiClient) ForeignExchange(com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange) Test(org.testng.annotations.Test)

Aggregations

ForeignExchange (com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange)8 Test (org.testng.annotations.Test)6 HyperwalletApiClient (com.hyperwallet.clientsdk.util.HyperwalletApiClient)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1