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
14 changes: 8 additions & 6 deletions src/main/java/com/adyen/Util/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public final class DateUtil {
private DateUtil() {
Expand All @@ -33,15 +35,15 @@ public static Date parseDateToFormat(String dateString, String format) {
return null;
}

Date date;
SimpleDateFormat fmt = new SimpleDateFormat(format);
SimpleDateFormat fmt = new SimpleDateFormat(format, Locale.ENGLISH);
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));

try {
date = fmt.parse(dateString);
} catch (ParseException e) {
return null;
return fmt.parse(dateString);
} catch (ParseException ignored) {
}

return date;
return null;
}

public static Date parseYmdDate(String dateString) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/adyen/Util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import com.adyen.model.Amount;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

public final class Util {
private Util() {
Expand Down Expand Up @@ -149,6 +152,9 @@ public static String calculateSessionValidity() {
calendar.add(Calendar.DATE, 1);
Date sessionDate = calendar.getTime();

return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(sessionDate);
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ENGLISH);
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));

return fmt.format(sessionDate);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/adyen/model/checkout/PaymentsRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.adyen.model.ForexQuote;
import com.adyen.model.Installments;
import com.adyen.model.Name;
import com.adyen.serializer.DateSerializer;
import com.adyen.serializer.DateTimeGMTSerializer;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
Expand Down Expand Up @@ -65,12 +67,14 @@ public class PaymentsRequest {
@SerializedName("countryCode")
private String countryCode = null;
@SerializedName("dateOfBirth")
@JsonAdapter(DateSerializer.class)
private Date dateOfBirth = null;
@SerializedName("dccQuote")
private ForexQuote dccQuote = null;
@SerializedName("deliveryAddress")
private Address deliveryAddress = null;
@SerializedName("deliveryDate")
@JsonAdapter(DateTimeGMTSerializer.class)
private Date deliveryDate = null;
@SerializedName("enableOneClick")
private Boolean enableOneClick = null;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/adyen/serializer/DateSerializer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
Expand All @@ -23,6 +23,7 @@
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
Expand All @@ -34,7 +35,7 @@ public class DateSerializer implements JsonSerializer<Date> {

@Override
public JsonElement serialize(Date date, Type typeOfSrc, JsonSerializationContext context) {
SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
return new JsonPrimitive(formatter.format(date));
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/adyen/serializer/DateTimeGMTSerializer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
Expand All @@ -23,6 +23,7 @@
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
Expand All @@ -37,7 +38,7 @@ public class DateTimeGMTSerializer implements JsonSerializer<Date> {
*/
@Override
public JsonElement serialize(Date date, Type typeOfSrc, JsonSerializationContext context) {
SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
return new JsonPrimitive(formatter.format(date));
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/adyen/service/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
package com.adyen.service;

import java.io.IOException;
import java.util.List;
import com.adyen.Config;
import com.adyen.Service;
import com.adyen.httpclient.ClientInterface;
Expand All @@ -31,9 +33,6 @@
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.util.List;

public class Resource {

protected static final Gson GSON = new Gson();
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/adyen/CheckoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
package com.adyen;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import org.junit.Test;
import com.adyen.model.Amount;
import com.adyen.model.checkout.PaymentMethodDetails;
Expand Down Expand Up @@ -223,6 +228,20 @@ public void TestPaymentMethodDetails() {
jsonRequest);
}

@Test
public void TestDateSerializers() throws ParseException {
PaymentsRequest paymentsRequest = new PaymentsRequest();

SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));

Date d = fmt.parse("2018-10-31");
paymentsRequest.setDateOfBirth(d);
paymentsRequest.setDeliveryDate(d);
String jsonRequest = GSON.toJson(paymentsRequest);
assertEquals("{\"dateOfBirth\":\"2018-10-31\",\"deliveryDate\":\"2018-10-31T00:00:00.000Z\"}", jsonRequest);
}

/**
* Returns a sample PaymentSessionRequest opbject with test data
*/
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/com/adyen/MarketPayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import org.junit.Test;
import com.adyen.model.Address;
import com.adyen.model.Amount;
Expand Down Expand Up @@ -146,7 +148,9 @@ public void TestCreateSplitPayment() throws Exception {

assertTrue(paymentResult.isAuthorised());

SimpleDateFormat format = new SimpleDateFormat("M/yyyy");
SimpleDateFormat format = new SimpleDateFormat("M/yyyy", Locale.ENGLISH);
format.setTimeZone(TimeZone.getTimeZone("GMT"));

assertEquals("8/2018", format.format(paymentResult.getExpiryDate()));

assertEquals("411111", paymentResult.getCardBin());
Expand Down
16 changes: 12 additions & 4 deletions src/test/java/com/adyen/PaymentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
*/
package com.adyen;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import org.junit.Test;
import com.adyen.constants.ApiConstants.AdditionalData;
import com.adyen.constants.ApiConstants.RefusalReason;
Expand Down Expand Up @@ -70,7 +73,9 @@ public void TestAuthoriseSuccessMocked() throws Exception {

assertTrue(paymentResult.isAuthorised());

SimpleDateFormat format = new SimpleDateFormat("M/yyyy");
SimpleDateFormat format = new SimpleDateFormat("M/yyyy", Locale.ENGLISH);
format.setTimeZone(TimeZone.getTimeZone("GMT"));

assertEquals("8/2018", format.format(paymentResult.getExpiryDate()));

assertEquals("411111", paymentResult.getCardBin());
Expand Down Expand Up @@ -206,7 +211,7 @@ public void TestError401Mocked() throws Exception {
HTTPClientException httpClientException = new HTTPClientException(401, "An error occured", new HashMap<String, List<String>>(), null);

when(httpURLConnectionClient.request(any(String.class), any(String.class), any(Config.class), anyBoolean(), any(RequestOptions.class))).thenThrow(httpClientException);
when(httpURLConnectionClient.request(any(String.class), any(String.class), any(Config.class), anyBoolean(), (RequestOptions)isNull())).thenThrow(httpClientException);
when(httpURLConnectionClient.request(any(String.class), any(String.class), any(Config.class), anyBoolean(), (RequestOptions) isNull())).thenThrow(httpClientException);

Client client = new Client();
client.setHttpClient(httpURLConnectionClient);
Expand Down Expand Up @@ -272,11 +277,14 @@ public void TestBoletoSuccess() throws Exception {
"BQABAQB8k7t5uD2wSpo185nNeQ9CU50Zf6z/z9EdC5yFH3+1o/DQH3v3dtTxqXD2DrEdVH0Ro3r/+G9bdUzrCUjfMFh7YB32VL2oPqye9Ly/MWzj7bOaRrpGH5PaB8gE9LkIgo8WKqHix1cwsFm3aHiLBECjItOpUR/CBuiJBGPvseN7yrSdG5vQAUM9AQixpPkyCNokbnDZoa1y3+qihZa7vvzV/XylTXdgirxboVKpk07Wfvpad8Owg/K/ofDqUfrZ3SUovkJzpZ5wP2NtOz84zBV8dJ+9vZs+aor/E//s+EjKgNJt2s2uX0OfdE3h1n41RW2MlfQBtXLbgbxKVVSH5qfPELsZhr10A9y9VpCd9DOP6lEAAFchf10tGLvIKj2j4ktIErp0uLCbLqa1/AvmfQ9a6e0TClmsbtwKoZ9LvAPpzHqRcmidgyUM1Igk5YsHBD7L8pzoJS5hL+DKXMeUav6oP20v9huLS3Ps6EiK4fyg5kgptZPhSQ5UN3GrGSoefja1Ylw32EBovEiaK9rdKkT/eVf+wncwLTLUiMD26R7qRxbvwAg4G8VIv6dxvOsKf2RutfOoCBNH6VhgwXfIoe0bHqmpx4dGwrjkVThspdsZYhHFrZK58grIb4OyKORibOYxvsmYmRdWMDX9Y1X8uva8OYs=",
paymentResult.getBoletoData());

assertEquals("2017-05-22", new SimpleDateFormat("yyyy-MM-dd").format(paymentResult.getBoletoDueDate()));
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));

assertEquals("2017-05-22", fmt.format(paymentResult.getBoletoDueDate()));
assertEquals(
"https://test.adyen.com/hpp/generationBoleto.shtml?data=BQABAQB8k7t5uD2wSpo185nNeQ9CU50Zf6z%2Fz9EdC5yFH3%2B1o%2FDQH3v3dtTxqXD2DrEdVH0Ro3r%2F%2BG9bdUzrCUjfMFh7YB32VL2oPqye9Ly%2FMWzj7bOaRrpGH5PaB8gE9LkIgo8WKqHix1cwsFm3aHiLBECjItOpUR%2FCBuiJBGPvseN7yrSdG5vQAUM9AQixpPkyCNokbnDZoa1y3%2BqihZa7vvzV%2FXylTXdgirxboVKpk07Wfvpad8Owg%2FK%2FofDqUfrZ3SUovkJzpZ5wP2NtOz84zBV8dJ%2B9vZs%2Baor%2FE%2F%2Fs%2BEjKgNJt2s2uX0OfdE3h1n41RW2MlfQBtXLbgbxKVVSH5qfPELsZhr10A9y9VpCd9DOP6lEAAFchf10tGLvIKj2j4ktIErp0uLCbLqa1%2FAvmfQ9a6e0TClmsbtwKoZ9LvAPpzHqRcmidgyUM1Igk5YsHBD7L8pzoJS5hL%2BDKXMeUav6oP20v9huLS3Ps6EiK4fyg5kgptZPhSQ5UN3GrGSoefja1Ylw32EBovEiaK9rdKkT%2FeVf%2BwncwLTLUiMD26R7qRxbvwAg4G8VIv6dxvOsKf2RutfOoCBNH6VhgwXfIoe0bHqmpx4dGwrjkVThspdsZYhHFrZK58grIb4OyKORibOYxvsmYmRdWMDX9Y1X8uva8OYs%3D",
paymentResult.getBoletoUrl());
assertEquals("2017-06-06", new SimpleDateFormat("yyyy-MM-dd").format(paymentResult.getBoletoExpirationDate()));
assertEquals("2017-06-06", fmt.format(paymentResult.getBoletoExpirationDate()));
assertEquals(RECEIVED, paymentResult.getResultCode());
assertEquals("8814950120218231", paymentResult.getPspReference());
}
Expand Down