Skip to content
Merged
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
9 changes: 1 addition & 8 deletions src/main/java/com/adyen/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public Client(String username, String password, Environment environment, String
}

public Client(String username, String password, Environment environment, String liveEndpointUrlPrefix, String applicationName) {

this.config = new Config();
this.config.setUsername(username);
this.config.setPassword(password);
Expand All @@ -81,7 +80,6 @@ public Client(String username, String password, Environment environment, String
*/
@Deprecated
public Client(String username, String password, Environment environment, int connectionTimeoutMillis) {

this(username, password, environment, null);
this.config.setConnectionTimeoutMillis(connectionTimeoutMillis);
}
Expand All @@ -97,7 +95,6 @@ public Client(String username, String password, Environment environment, int con
*/
@Deprecated
public Client(String username, String password, Environment environment, int connectionTimeoutMillis, String liveEndpointUrlPrefix) {

this(username, password, environment, liveEndpointUrlPrefix, null);
this.config.setConnectionTimeoutMillis(connectionTimeoutMillis);
}
Expand All @@ -121,7 +118,6 @@ public Client(String apiKey, Environment environment, String liveEndpointUrlPref
*/
@Deprecated
public Client(String apiKey, Environment environment, int connectionTimeoutMillis) {

this(apiKey, environment);
this.config.setConnectionTimeoutMillis(connectionTimeoutMillis);
}
Expand All @@ -136,7 +132,6 @@ public Client(String apiKey, Environment environment, int connectionTimeoutMilli
*/
@Deprecated
public Client(String apiKey, Environment environment, int connectionTimeoutMillis, String liveEndpointUrlPrefix) {

this(apiKey, environment, liveEndpointUrlPrefix);
this.config.setConnectionTimeoutMillis(connectionTimeoutMillis);
}
Expand All @@ -155,7 +150,6 @@ public void setEnvironment(Environment environment) {
* @param liveEndpointUrlPrefix Provide the unique live url prefix from the "API URLs and Response" menu in the Adyen Customer Area
*/
public void setEnvironment(Environment environment, String liveEndpointUrlPrefix) {

if (Environment.TEST.equals(environment)) {
this.config.setEnvironment(environment);
this.config.setEndpoint(ENDPOINT_TEST);
Expand All @@ -178,11 +172,10 @@ public void setEnvironment(Environment environment, String liveEndpointUrlPrefix

@Override
public String toString() {
return "Client [webServiceUser=" + this.config.username + ", webServicePassword=" + this.config.password + ", environment=" + this.config.environment + "]";
return "Client [webServiceUser=" + this.config.username + ", environment=" + this.config.environment + "]";
}

public ClientInterface getHttpClient() {

if (this.httpClient == null) {
this.httpClient = new HttpURLConnectionClient();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/adyen/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class Config {
protected Environment environment;
protected String endpoint;
protected String marketPayEndpoint;
/**
* Application name: used as HTTP client User-Agent
*/
protected String applicationName;
protected String apiKey;
protected int connectionTimeoutMillis;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/adyen/Util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ public static Amount createAmount(String amount, String currency) {
public static Amount createAmount(BigDecimal amount, String currency) {
Amount amountData = new Amount();
amountData.setCurrency(currency);
Long amountValue;

Integer scale = getDecimalPlaces(currency);
amountValue = new BigDecimal(10).pow(scale).multiply(amount.setScale(scale, RoundingMode.HALF_UP)).longValue();
int scale = getDecimalPlaces(currency);
Long amountValue = BigDecimal.TEN.pow(scale).multiply(amount.setScale(scale, RoundingMode.HALF_UP)).longValue();

amountData.setValue(amountValue);

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/adyen/model/Amount.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public class Amount {
private String currency = null;

public BigDecimal getDecimalValue() {
BigDecimal divisor = new BigDecimal(10)
.pow(Util.getDecimalPlaces(getCurrency()));

BigDecimal amountValue = new BigDecimal(getValue())
.divide(divisor);
BigDecimal amountValue = BigDecimal.valueOf(getValue(), Util.getDecimalPlaces(getCurrency()));
return amountValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ public AccountHolderDetails merchantCategoryCode(String merchantCategoryCode) {
}

/**
* merchant category code
* Merchant Category Code (MCC) is classifier of the business by the type of goods or services it provides.
* https://en.wikipedia.org/wiki/Merchant_category_code
*
* @return merchantCategoryCode
**/
Expand Down
46 changes: 18 additions & 28 deletions src/test/java/com/adyen/MarketPayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public class MarketPayTest extends BaseTest {
*/
@Test
public void TestCreateSplitPayment() throws Exception {

Client client = createMockClientFromFile("mocks/authorise-success.json");
Payment payment = new Payment(client);

Expand All @@ -117,14 +116,14 @@ public void TestCreateSplitPayment() throws Exception {
// splitPayment
SplitPayment splitPayment = new SplitPayment();
splitPayment.setApi(1);
splitPayment.setTotalAmount(new Long("6200"));
splitPayment.setTotalAmount(6200L);
splitPayment.setCurrencyCode("EUR");

List<SplitPaymentItem> splitPaymentItems = new ArrayList<SplitPaymentItem>();

// first split payment item
SplitPaymentItem splitPaymentItem = new SplitPaymentItem();
splitPaymentItem.setAmount(new Long(6000));
splitPaymentItem.setAmount(6000L);
splitPaymentItem.setType("MarketPlace");
splitPaymentItem.setAccount("151272963");
splitPaymentItem.setReference("6124145");
Expand All @@ -133,7 +132,7 @@ public void TestCreateSplitPayment() throws Exception {

// seconf split payment item
SplitPaymentItem splitPaymentItem2 = new SplitPaymentItem();
splitPaymentItem2.setAmount(new Long(200));
splitPaymentItem2.setAmount(200L);
splitPaymentItem2.setType("Commission");
splitPaymentItem2.setReference("6124146");
splitPaymentItems.add(splitPaymentItem2);
Expand Down Expand Up @@ -173,14 +172,13 @@ public void TestCreateSplitPayment() throws Exception {
*/
@Test
public void TestCreateAccountHolderSuccess() throws Exception {

// setup client
Client client = createMockClientFromFile("mocks/marketpay/account/create-account-holder-success.json");

// use Account service
Account account = new Account(client);

// Create Account Holder Reqeust
// Create Account Holder Request
CreateAccountHolderRequest createAccountHolderRequest = new CreateAccountHolderRequest();
createAccountHolderRequest.setAccountHolderCode("TestAccountHolder781664");

Expand Down Expand Up @@ -271,7 +269,6 @@ public void TestCreateAccountHolderSuccess() throws Exception {
*/
@Test
public void TestAccountHolderBalanceSuccess() throws Exception {

// setup client
Client client = createMockClientFromFile("mocks/marketpay/fund/account-holder-balance-success.json");

Expand All @@ -284,8 +281,8 @@ public void TestAccountHolderBalanceSuccess() throws Exception {
AccountHolderBalanceResponse accountHolderBalanceResponse = fund.accountHolderBalance(accountHolderBalanceRequest);


assertEquals(new Long(42058), accountHolderBalanceResponse.getTotalBalance().getPendingBalance().get(0).getValue());
assertEquals(new Long(99792), accountHolderBalanceResponse.getBalancePerAccount().get(0).getDetailBalance().getBalance().get(0).getValue());
assertEquals(42058L, accountHolderBalanceResponse.getTotalBalance().getPendingBalance().get(0).getValue().longValue());
assertEquals(99792L, accountHolderBalanceResponse.getBalancePerAccount().get(0).getDetailBalance().getBalance().get(0).getValue().longValue());
}

@Test
Expand Down Expand Up @@ -347,9 +344,7 @@ public void TestUpdateAccountHolderSuccess() throws Exception {
updateAccountHolderRequest.setAccountHolderDetails(accountHolderDetails);
UpdateAccountHolderResponse updateAccountHolderResponse = account.updateAccountHolder(updateAccountHolderRequest);

assertEquals(new Long(49999), updateAccountHolderResponse.getAccountHolderStatus().getPayoutState().getPayoutLimit().getValue());


assertEquals(49999L, updateAccountHolderResponse.getAccountHolderStatus().getPayoutState().getPayoutLimit().getValue().longValue());
}

@Test
Expand All @@ -374,7 +369,6 @@ public void TestGetIndividualAccountHolderSuccess() throws Exception {

@Test
public void TestGetBusinessAccountHolderSuccess() throws Exception {

// setup client
Client client = createMockClientFromFile("mocks/marketpay/account/get-business-account-holder-success.json");

Expand All @@ -397,7 +391,6 @@ public void TestGetBusinessAccountHolderSuccess() throws Exception {

@Test
public void TestUploadDocumentSuccess() throws Exception {

// setup client
Client client = createMockClientFromFile("mocks/marketpay/account/upload-document-success.json");

Expand All @@ -419,13 +412,12 @@ public void TestUploadDocumentSuccess() throws Exception {
uploadDocumentRequest.setDocumentDetail(documentDetail);

UploadDocumentResponse uploadDocumentResponse = account.uploadDocument(uploadDocumentRequest);
assertEquals(new Long(9999), uploadDocumentResponse.getAccountHolderStatus().getProcessingState().getProcessedTo().getValue());
assertEquals(9999L, uploadDocumentResponse.getAccountHolderStatus().getProcessingState().getProcessedTo().getValue().longValue());

}

@Test
public void TestTransferFundsSuccess() throws Exception {

// setup client
Client client = createMockClientFromFile("mocks/marketpay/fund/transfer-funds-success.json");

Expand All @@ -440,7 +432,7 @@ public void TestTransferFundsSuccess() throws Exception {
// create Amount
Amount amount = new Amount();
amount.setCurrency("EUR");
amount.setValue(new Long(2000));
amount.setValue(2000L);
transferFundsRequest.setAmount(amount);

transferFundsRequest.setTransferCode("CODE_A");
Expand Down Expand Up @@ -517,7 +509,7 @@ public void TestSuspendAccountHolderSuccess() throws Exception {
suspendAccountHolderRequest.setAccountHolderCode("TestAccountHolder192192");

SuspendAccountHolderResponse suspendAccountHolderResponse = account.suspendAccountHolder(suspendAccountHolderRequest);
assertEquals(new Long(49999), suspendAccountHolderResponse.getAccountHolderStatus().getPayoutState().getPayoutLimit().getValue());
assertEquals(49999L, suspendAccountHolderResponse.getAccountHolderStatus().getPayoutState().getPayoutLimit().getValue().longValue());

}

Expand All @@ -534,7 +526,7 @@ public void TestUnSuspendAccountHolderSuccess() throws Exception {
unSuspendAccountHolderRequest.setAccountHolderCode("TestAccountHolder192192");

UnSuspendAccountHolderResponse unSuspendAccountHolderResponse = account.unSuspendAccountHolder(unSuspendAccountHolderRequest);
assertEquals(new Long(49999), unSuspendAccountHolderResponse.getAccountHolderStatus().getPayoutState().getPayoutLimit().getValue());
assertEquals(49999L, unSuspendAccountHolderResponse.getAccountHolderStatus().getPayoutState().getPayoutLimit().getValue().longValue());
}

@Test
Expand All @@ -553,7 +545,7 @@ public void TestUpdateAccountHolderStateSuccess() throws Exception {
updateAccountHolderStateRequest.stateType(UpdateAccountHolderStateRequest.StateTypeEnum.PAYOUT);

UpdateAccountHolderStateResponse updateAccountHolderStateResponse = account.updateAccountHolderState(updateAccountHolderStateRequest);
assertEquals(new Long(74999), updateAccountHolderStateResponse.getAccountHolderStatus().getPayoutState().getPayoutLimit().getValue());
assertEquals(74999L, updateAccountHolderStateResponse.getAccountHolderStatus().getPayoutState().getPayoutLimit().getValue().longValue());
}

@Test
Expand Down Expand Up @@ -606,7 +598,7 @@ public void TestPayoutAccountHolderSuccess() throws Exception {
// create Amount
Amount amount = new Amount();
amount.setCurrency("EUR");
amount.setValue(new Long(2000));
amount.setValue(2000L);
payoutAccountHolderRequest.setAmount(amount);

PayoutAccountHolderResponse payoutAccountHolderResponse = fund.payoutAccountHolder(payoutAccountHolderRequest);
Expand Down Expand Up @@ -711,7 +703,6 @@ public void TestSetupBeneficiarySuccess() throws Exception {

@Test
public void TestGetTierConfiguration() throws Exception {

// setup client
Client client = createMockClientFromFile("mocks/marketpay/account/get-tier-configuration-success.json");

Expand All @@ -720,8 +711,7 @@ public void TestGetTierConfiguration() throws Exception {

GetTierConfigurationResponse getTierConfigurationResponse = account.getTierConfiguration();

assertEquals(new Long(10000), getTierConfigurationResponse.getTierConfiguration().get(0).getTiers().get(0).getToAmount().getValue());

assertEquals(10000L, getTierConfigurationResponse.getTierConfiguration().get(0).getTiers().get(0).getToAmount().getValue().longValue());
}

@Test
Expand All @@ -732,12 +722,12 @@ public void TestCreateAccountHolderInvalid() throws Exception {
// use Account service
Account account = new Account(client);

// Create Account Holder Reqeust
// Create Account Holder Request
CreateAccountHolderRequest createAccountHolderRequest = new CreateAccountHolderRequest();

CreateAccountHolderResponse createAccountHolderResponse = account.createAccountHolder(createAccountHolderRequest);

assertEquals(new Integer(17), createAccountHolderResponse.getInvalidFields().get(0).getErrorCode());
assertEquals(17, createAccountHolderResponse.getInvalidFields().get(0).getErrorCode().intValue());
}

@Test
Expand All @@ -748,11 +738,11 @@ public void TestUpdateAccountHolderInvalid() throws Exception {
// use Account service
Account account = new Account(client);

// Create Account Holder Reqeust
// Create Account Holder Request
UpdateAccountHolderRequest updateAccountHolderRequest = new UpdateAccountHolderRequest();

UpdateAccountHolderResponse updateAccountHolderResponse = account.updateAccountHolder(updateAccountHolderRequest);

assertEquals(new Integer(17), updateAccountHolderResponse.getInvalidFields().get(0).getErrorCode());
assertEquals(17, updateAccountHolderResponse.getInvalidFields().get(0).getErrorCode().intValue());
}
}
12 changes: 6 additions & 6 deletions src/test/java/com/adyen/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class UtilTest {
public void testAmountDecimals() {
Amount amount = new Amount();
amount.setCurrency("EUR");
amount.setValue(new Long("1000"));
amount.setValue(1001L);

assertEquals(0, new BigDecimal("10.00").compareTo(amount.getDecimalValue()));
assertEquals(new BigDecimal("10.01"), amount.getDecimalValue());
}

@Test
Expand All @@ -41,10 +41,10 @@ public void testCreateAmount() {
Amount amountMRO = Util.createAmount("123.45234", "MRO");
Amount amountBHD = Util.createAmount("1.2345234", "BHD");

assertEquals(new Long("1235"), amount.getValue());
assertEquals(new Long("1234"), amountJPY.getValue());
assertEquals(new Long("1235"), amountMRO.getValue());
assertEquals(new Long("1235"), amountBHD.getValue());
assertEquals(1235L, amount.getValue().longValue());
assertEquals(1234L, amountJPY.getValue().longValue());
assertEquals(1235L, amountMRO.getValue().longValue());
assertEquals(1235L, amountBHD.getValue().longValue());
}

@Test
Expand Down