Skip to content

Commit

Permalink
refactor: use constants for common strings in paths and error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lrosenfeldt committed Aug 7, 2024
1 parent 8671e8c commit 07d97a4
Showing 1 changed file with 11 additions and 9 deletions.
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 Down Expand Up @@ -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 Down Expand Up @@ -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 Down Expand Up @@ -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 Down Expand Up @@ -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 Down

0 comments on commit 07d97a4

Please sign in to comment.