Skip to content

Commit

Permalink
Merge pull request #14 from PAYONE-GmbH/refactor/initial-sonarcloud-a…
Browse files Browse the repository at this point in the history
…nalysis-2

refactor: remaining sonarcloud analysis issues
  • Loading branch information
lrosenfeldt authored Aug 7, 2024
2 parents a3954c0 + 07d97a4 commit 386de7c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class BaseApiClient {
protected static final String PCP_PATH_SEGMENT_COMMERCE_CASES = "commerce-cases";
protected static final String PCP_PATH_SEGMENT_CHECKOUTS = "checkouts";

protected static final String CONTENT_TYPE_HEADER_NAME = "Content-Type";

protected static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

private final OkHttpClient client = new OkHttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public CreateCheckoutResponse createCheckoutRequest(String merchantId, String co
Request request = new Request.Builder()
.url(url)
.post(RequestBody.create(jsonString, JSON))
.header("Content-Type", JSON.toString())
.header(CONTENT_TYPE_HEADER_NAME, JSON.toString())
.build();

return this.makeApiCall(request, CreateCheckoutResponse.class);
Expand Down Expand Up @@ -164,7 +164,7 @@ public void updateCheckoutRequest(String merchantId, String commerceCaseId, Stri
Request request = new Request.Builder()
.url(url)
.patch(RequestBody.create(jsonString, JSON))
.header("Content-Type", JSON.toString())
.header(CONTENT_TYPE_HEADER_NAME, JSON.toString())
.build();

this.makeApiCall(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public CreateCommerceCaseResponse createCommerceCaseRequest(String merchantId, C
Request request = new Request.Builder()
.url(url)
.post(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

return this.makeApiCall(request, CreateCommerceCaseResponse.class);
Expand Down Expand Up @@ -154,7 +154,7 @@ public void updateCommerceCaseRequest(String merchantId, String commerceCaseId,
Request request = new Request.Builder()
.url(url)
.patch(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

this.makeApiCall(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public CancelResponse cancelOrder(String merchantId, String commerceCaseId,
Request request = new Request.Builder()
.url(url)
.post(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

return this.makeApiCall(request, CancelResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import okhttp3.RequestBody;

public class PaymentExecutionApiClient extends BaseApiClient {
private static final String PAYMENT_EXECUTION_ID_REQUIRED_ERROR = "Payment Execution ID is required";
private static final String PCP_PATH_SEGMENT_PAYMENT_EXECUTIONS = "payment-executions";

public PaymentExecutionApiClient(CommunicatorConfiguration config) throws InvalidKeyException {
super(config);
Expand Down Expand Up @@ -53,7 +55,7 @@ public CreatePaymentResponse createPayment(String merchantId, String commerceCas
.addPathSegment(commerceCaseId)
.addPathSegment(PCP_PATH_SEGMENT_CHECKOUTS)
.addPathSegment(checkoutId)
.addPathSegment("payment-executions")
.addPathSegment(PCP_PATH_SEGMENT_PAYMENT_EXECUTIONS)
.build();

String jsonString = JsonSerializer.serializeToJson(payload);
Expand All @@ -63,7 +65,7 @@ public CreatePaymentResponse createPayment(String merchantId, String commerceCas
Request request = new Request.Builder()
.url(url)
.post(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

return this.makeApiCall(request, CreatePaymentResponse.class);
Expand All @@ -83,7 +85,7 @@ public CapturePaymentResponse capturePayment(String merchantId, String commerceC
throw new IllegalArgumentException(CHECKOUT_ID_REQUIRED_ERROR);
}
if (paymentExecutionId == null) {
throw new IllegalArgumentException("Payment Execution ID is required");
throw new IllegalArgumentException(PAYMENT_EXECUTION_ID_REQUIRED_ERROR);
}
if (payload == null) {
throw new IllegalArgumentException(PAYLOAD_REQUIRED_ERROR);
Expand All @@ -98,7 +100,7 @@ public CapturePaymentResponse capturePayment(String merchantId, String commerceC
.addPathSegment(commerceCaseId)
.addPathSegment(PCP_PATH_SEGMENT_CHECKOUTS)
.addPathSegment(checkoutId)
.addPathSegment("payment-executions")
.addPathSegment(PCP_PATH_SEGMENT_PAYMENT_EXECUTIONS)
.addPathSegment(paymentExecutionId)
.addPathSegment("capture")
.build();
Expand All @@ -110,7 +112,7 @@ public CapturePaymentResponse capturePayment(String merchantId, String commerceC
Request request = new Request.Builder()
.url(url)
.post(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

return this.makeApiCall(request, CapturePaymentResponse.class);
Expand All @@ -130,7 +132,7 @@ public CancelPaymentResponse cancelPayment(String merchantId, String commerceCas
throw new IllegalArgumentException(CHECKOUT_ID_REQUIRED_ERROR);
}
if (paymentExecutionId == null) {
throw new IllegalArgumentException("Payment Execution ID is required");
throw new IllegalArgumentException(PAYMENT_EXECUTION_ID_REQUIRED_ERROR);
}
if (payload == null) {
throw new IllegalArgumentException(PAYLOAD_REQUIRED_ERROR);
Expand All @@ -145,7 +147,7 @@ public CancelPaymentResponse cancelPayment(String merchantId, String commerceCas
.addPathSegment(commerceCaseId)
.addPathSegment(PCP_PATH_SEGMENT_CHECKOUTS)
.addPathSegment(checkoutId)
.addPathSegment("payment-executions")
.addPathSegment(PCP_PATH_SEGMENT_PAYMENT_EXECUTIONS)
.addPathSegment(paymentExecutionId)
.addPathSegment("cancel")
.build();
Expand All @@ -157,7 +159,7 @@ public CancelPaymentResponse cancelPayment(String merchantId, String commerceCas
Request request = new Request.Builder()
.url(url)
.post(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

return this.makeApiCall(request, CancelPaymentResponse.class);
Expand All @@ -177,7 +179,7 @@ public RefundPaymentResponse refundPayment(String merchantId, String commerceCas
throw new IllegalArgumentException(CHECKOUT_ID_REQUIRED_ERROR);
}
if (paymentExecutionId == null) {
throw new IllegalArgumentException("Payment Execution ID is required");
throw new IllegalArgumentException(PAYMENT_EXECUTION_ID_REQUIRED_ERROR);
}
if (payload == null) {
throw new IllegalArgumentException(PAYLOAD_REQUIRED_ERROR);
Expand All @@ -192,7 +194,7 @@ public RefundPaymentResponse refundPayment(String merchantId, String commerceCas
.addPathSegment(commerceCaseId)
.addPathSegment(PCP_PATH_SEGMENT_CHECKOUTS)
.addPathSegment(checkoutId)
.addPathSegment("payment-executions")
.addPathSegment(PCP_PATH_SEGMENT_PAYMENT_EXECUTIONS)
.addPathSegment(paymentExecutionId)
.addPathSegment("refund")
.build();
Expand All @@ -204,7 +206,7 @@ public RefundPaymentResponse refundPayment(String merchantId, String commerceCas
Request request = new Request.Builder()
.url(url)
.post(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

return this.makeApiCall(request, RefundPaymentResponse.class);
Expand All @@ -224,7 +226,7 @@ public CompletePaymentResponse completePayment(String merchantId, String commerc
throw new IllegalArgumentException(CHECKOUT_ID_REQUIRED_ERROR);
}
if (paymentExecutionId == null) {
throw new IllegalArgumentException("Payment Execution ID is required");
throw new IllegalArgumentException(PAYMENT_EXECUTION_ID_REQUIRED_ERROR);
}
if (payload == null) {
throw new IllegalArgumentException(PAYLOAD_REQUIRED_ERROR);
Expand All @@ -239,7 +241,7 @@ public CompletePaymentResponse completePayment(String merchantId, String commerc
.addPathSegment(commerceCaseId)
.addPathSegment(PCP_PATH_SEGMENT_CHECKOUTS)
.addPathSegment(checkoutId)
.addPathSegment("payment-executions")
.addPathSegment(PCP_PATH_SEGMENT_PAYMENT_EXECUTIONS)
.addPathSegment(paymentExecutionId)
.addPathSegment("complete")
.build();
Expand All @@ -251,7 +253,7 @@ public CompletePaymentResponse completePayment(String merchantId, String commerc
Request request = new Request.Builder()
.url(url)
.post(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

return this.makeApiCall(request, CompletePaymentResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public PaymentInformationResponse createPaymentInformation(String merchantId, St
Request request = new Request.Builder()
.url(url)
.post(formBody)
.header("Content-Type", formBody.contentType().toString())
.header(CONTENT_TYPE_HEADER_NAME, formBody.contentType().toString())
.build();

return this.makeApiCall(request, PaymentInformationResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
})
public class ServerMetaInfo implements Serializable {
public static ServerMetaInfo withDefaults(String integrator) {
ServerMetaInfo serverMetaInfo = new ServerMetaInfo()
return new ServerMetaInfo()
.platformIdentifier(String.format("%s, java version is: %s", System.getProperty("os.name"),
System.getProperty("java.version")))
.sdkIdentifier("JavaServerSDK/v0.0.2")
.sdkCreator("PAYONE GmbH")
.integrator(integrator);
return serverMetaInfo;
}

public static ServerMetaInfo withDefaults() {
Expand All @@ -41,6 +40,8 @@ public static ServerMetaInfo withDefaults() {
private String integrator;

public ServerMetaInfo() {
// empty constructor
// required for Jackson deserialization
}

public ServerMetaInfo platformIdentifier(String platformIdentifier) {
Expand Down

0 comments on commit 386de7c

Please sign in to comment.