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
7 changes: 7 additions & 0 deletions src/main/java/com/checkout/GsonSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.checkout.payments.previous.PaymentAction;
import com.checkout.payments.sender.Sender;
import com.checkout.payments.sender.SenderType;
import com.checkout.handlepaymentsandpayouts.flow.entities.PaymentSessionStatus;
import com.checkout.handlepaymentsandpayouts.flow.responses.PaymentSubmissionResponse;
import com.checkout.webhooks.previous.WebhookResponse;
import com.checkout.workflows.actions.WorkflowActionType;
import com.checkout.workflows.conditions.WorkflowConditionType;
Expand Down Expand Up @@ -207,6 +209,11 @@ public class GsonSerializer implements Serializer {
.registerSubtype(com.checkout.issuing.controls.requests.controlgroup.VelocityControlGroupControl.class, identifier(ControlType.VELOCITY_LIMIT))
.registerSubtype(com.checkout.issuing.controls.requests.controlgroup.MccControlGroupControl.class, identifier(ControlType.MCC_LIMIT))
.registerSubtype(com.checkout.issuing.controls.requests.controlgroup.MidControlGroupControl.class, identifier(ControlType.MID_LIMIT)))
// Flow - PaymentSubmissionResponse
.registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(com.checkout.handlepaymentsandpayouts.flow.responses.PaymentSubmissionResponse.class, CheckoutUtils.STATUS)
.registerSubtype(com.checkout.handlepaymentsandpayouts.flow.responses.ApprovedPaymentSubmissionResponse.class, identifier(PaymentSessionStatus.APPROVED))
.registerSubtype(com.checkout.handlepaymentsandpayouts.flow.responses.DeclinedPaymentSubmissionResponse.class, identifier(PaymentSessionStatus.DECLINED))
.registerSubtype(com.checkout.handlepaymentsandpayouts.flow.responses.ActionRequiredPaymentSubmissionResponse.class, identifier(PaymentSessionStatus.ACTION_REQUIRED)))
// Adapters when API returns an array
.registerTypeAdapter(EVENT_TYPES_TYPE, eventTypesResponseDeserializer())
.registerTypeAdapter(WORKFLOWS_EVENT_TYPES_TYPE, workflowEventTypesResponseDeserializer())
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/checkout/common/CheckoutUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public final class CheckoutUtils {
public static final String PROJECT_NAME = "checkout-sdk-java";
public static final String TYPE = "type";
public static final String FREQUENCY = "frequency";
public static final String STATUS = "status";
public static final String DAILY = "Daily";
public static final String WEEKLY = "Weekly";
public static final String MONTHLY = "Monthly";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
package com.checkout.handlepaymentsandpayouts.flow;

import com.checkout.handlepaymentsandpayouts.flow.paymentsessions.requests.PaymentSessionRequest;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessions.responses.PaymentSessionResponse;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessionscomplete.requests.PaymentSessionWithPaymentRequest;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessionscomplete.responses.PaymentSessionWithPaymentResponse;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessionssubmit.requests.SubmitPaymentSessionRequest;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessionssubmit.responses.SubmitPaymentSessionResponse;
import com.checkout.handlepaymentsandpayouts.flow.requests.PaymentSessionCreateRequest;
import com.checkout.handlepaymentsandpayouts.flow.requests.PaymentSessionSubmitRequest;
import com.checkout.handlepaymentsandpayouts.flow.requests.PaymentSessionCompleteRequest;
import com.checkout.handlepaymentsandpayouts.flow.responses.PaymentSessionResponse;
import com.checkout.handlepaymentsandpayouts.flow.responses.PaymentSubmissionResponse;

import java.util.concurrent.CompletableFuture;

/**
* Flow - Create payment sessions and submit payment attempts
*/
public interface FlowClient {

CompletableFuture<PaymentSessionResponse> requestPaymentSession(PaymentSessionRequest paymentSessionRequest);

CompletableFuture<SubmitPaymentSessionResponse> submitPaymentSessions(
String paymentId,
SubmitPaymentSessionRequest submitPaymentSessionRequest
);

CompletableFuture<PaymentSessionWithPaymentResponse> requestPaymentSessionWithPayment(
PaymentSessionWithPaymentRequest paymentSessionRequest
);
/**
* Request a Payment Session
* Creates a payment session.
* The values you provide in the request will be used to determine the payment methods available to Flow.
* Some payment methods may require you to provide specific values for certain fields.
* You must supply the unmodified response body when you initialize Flow.
*/
CompletableFuture<PaymentSessionResponse> requestPaymentSession(PaymentSessionCreateRequest request);

/**
* Submit a Payment Session
* Submit a payment attempt for a payment session.
* This request works with the Flow handleSubmit callback, where you can perform a customized payment submission.
* You must send the unmodified response body as the response of the handleSubmit callback.
*/
CompletableFuture<PaymentSubmissionResponse> submitPaymentSession(String sessionId, PaymentSessionSubmitRequest request);

/**
* Request a Payment Session with Payment
* Create a payment session and submit a payment attempt for it.
* The values you provide in the request will be used to determine the payment methods available to Flow.
* This request works with the advanced Flow integration, where you do not need to create a payment session for initializing Flow.
* You must send the unmodified response body as the response of the handleSubmit callback.
*/
CompletableFuture<PaymentSubmissionResponse> requestPaymentSessionWithPayment(PaymentSessionCompleteRequest request);

// Synchronous methods
PaymentSessionResponse requestPaymentSessionSync(PaymentSessionRequest paymentSessionRequest);

SubmitPaymentSessionResponse submitPaymentSessionsSync(
String paymentId,
SubmitPaymentSessionRequest submitPaymentSessionRequest
);

PaymentSessionWithPaymentResponse requestPaymentSessionWithPaymentSync(
PaymentSessionWithPaymentRequest paymentSessionRequest
);
PaymentSessionResponse requestPaymentSessionSync(PaymentSessionCreateRequest request);

PaymentSubmissionResponse submitPaymentSessionSync(String sessionId, PaymentSessionSubmitRequest request);

PaymentSubmissionResponse requestPaymentSessionWithPaymentSync(PaymentSessionCompleteRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import com.checkout.ApiClient;
import com.checkout.CheckoutConfiguration;
import com.checkout.SdkAuthorizationType;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessions.requests.PaymentSessionRequest;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessions.responses.PaymentSessionResponse;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessionscomplete.requests.PaymentSessionWithPaymentRequest;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessionscomplete.responses.PaymentSessionWithPaymentResponse;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessionssubmit.requests.SubmitPaymentSessionRequest;
import com.checkout.handlepaymentsandpayouts.flow.paymentsessionssubmit.responses.SubmitPaymentSessionResponse;
import com.checkout.handlepaymentsandpayouts.flow.requests.PaymentSessionCreateRequest;
import com.checkout.handlepaymentsandpayouts.flow.requests.PaymentSessionSubmitRequest;
import com.checkout.handlepaymentsandpayouts.flow.requests.PaymentSessionCompleteRequest;
import com.checkout.handlepaymentsandpayouts.flow.responses.PaymentSessionResponse;
import com.checkout.handlepaymentsandpayouts.flow.responses.PaymentSubmissionResponse;

import java.util.concurrent.CompletableFuture;

Expand All @@ -18,129 +17,84 @@
public class FlowClientImpl extends AbstractClient implements FlowClient {

private static final String PAYMENT_SESSIONS_PATH = "payment-sessions";
private static final String COMPLETE_PATH = "complete";
private static final String SUBMIT_PATH = "submit";
private static final String COMPLETE_PATH = "complete";

public FlowClientImpl(final ApiClient apiClient, final CheckoutConfiguration configuration) {
super(apiClient, configuration, SdkAuthorizationType.SECRET_KEY_OR_OAUTH);
}

@Override
public CompletableFuture<PaymentSessionResponse> requestPaymentSession(
final PaymentSessionRequest paymentSessionRequest
) {

validatePaymentSessionRequest(paymentSessionRequest);

return apiClient.postAsync(
PAYMENT_SESSIONS_PATH,
sdkAuthorization(),
PaymentSessionResponse.class,
paymentSessionRequest,
null
);

public CompletableFuture<PaymentSessionResponse> requestPaymentSession(final PaymentSessionCreateRequest request) {
validatePaymentSessionCreateRequest(request);
return apiClient.postAsync(PAYMENT_SESSIONS_PATH,
sdkAuthorization(),
PaymentSessionResponse.class,
request,
null);
}

@Override
public CompletableFuture<SubmitPaymentSessionResponse> submitPaymentSessions(
final String paymentId,
final SubmitPaymentSessionRequest submitPaymentSessionRequest
) {

validateSubmitPaymentSessionRequest(paymentId, submitPaymentSessionRequest);

return apiClient.postAsync(
buildPath(PAYMENT_SESSIONS_PATH, paymentId, SUBMIT_PATH),
sdkAuthorization(),
SubmitPaymentSessionResponse.class,
submitPaymentSessionRequest,
null
);
public CompletableFuture<PaymentSubmissionResponse> submitPaymentSession(final String sessionId, final PaymentSessionSubmitRequest request) {
validatePaymentSessionSubmitParameters(sessionId, request);
return apiClient.postAsync(buildPath(PAYMENT_SESSIONS_PATH, sessionId, SUBMIT_PATH),
sdkAuthorization(),
PaymentSubmissionResponse.class,
request,
null);
}

@Override
public CompletableFuture<PaymentSessionWithPaymentResponse> requestPaymentSessionWithPayment(
final PaymentSessionWithPaymentRequest paymentSessionWithPaymentRequest
) {

validatePaymentSessionWithPaymentRequest(paymentSessionWithPaymentRequest);

return apiClient.postAsync(
buildPath(PAYMENT_SESSIONS_PATH, COMPLETE_PATH),
sdkAuthorization(),
PaymentSessionWithPaymentResponse.class,
paymentSessionWithPaymentRequest,
null
);

public CompletableFuture<PaymentSubmissionResponse> requestPaymentSessionWithPayment(final PaymentSessionCompleteRequest request) {
validatePaymentSessionCompleteRequest(request);
return apiClient.postAsync(buildPath(PAYMENT_SESSIONS_PATH, COMPLETE_PATH),
sdkAuthorization(),
PaymentSubmissionResponse.class,
request,
null);
}

// Synchronous methods
@Override
public PaymentSessionResponse requestPaymentSessionSync(
final PaymentSessionRequest paymentSessionRequest
) {

validatePaymentSessionRequest(paymentSessionRequest);

return apiClient.post(
PAYMENT_SESSIONS_PATH,
sdkAuthorization(),
PaymentSessionResponse.class,
paymentSessionRequest,
null
);

public PaymentSessionResponse requestPaymentSessionSync(final PaymentSessionCreateRequest request) {
validatePaymentSessionCreateRequest(request);
return apiClient.post(PAYMENT_SESSIONS_PATH,
sdkAuthorization(),
PaymentSessionResponse.class,
request,
null);
}

@Override
public SubmitPaymentSessionResponse submitPaymentSessionsSync(
final String paymentId,
final SubmitPaymentSessionRequest submitPaymentSessionRequest
) {

validateSubmitPaymentSessionRequest(paymentId, submitPaymentSessionRequest);

return apiClient.post(
buildPath(PAYMENT_SESSIONS_PATH, paymentId, SUBMIT_PATH),
sdkAuthorization(),
SubmitPaymentSessionResponse.class,
submitPaymentSessionRequest,
null
);
public PaymentSubmissionResponse submitPaymentSessionSync(final String sessionId, final PaymentSessionSubmitRequest request) {
validatePaymentSessionSubmitParameters(sessionId, request);
return apiClient.post(buildPath(PAYMENT_SESSIONS_PATH, sessionId, SUBMIT_PATH),
sdkAuthorization(),
PaymentSubmissionResponse.class,
request,
null);
}

@Override
public PaymentSessionWithPaymentResponse requestPaymentSessionWithPaymentSync(
final PaymentSessionWithPaymentRequest paymentSessionWithPaymentRequest
) {

validatePaymentSessionWithPaymentRequest(paymentSessionWithPaymentRequest);

return apiClient.post(
buildPath(PAYMENT_SESSIONS_PATH, COMPLETE_PATH),
sdkAuthorization(),
PaymentSessionWithPaymentResponse.class,
paymentSessionWithPaymentRequest,
null
);

public PaymentSubmissionResponse requestPaymentSessionWithPaymentSync(final PaymentSessionCompleteRequest request) {
validatePaymentSessionCompleteRequest(request);
return apiClient.post(buildPath(PAYMENT_SESSIONS_PATH, COMPLETE_PATH),
sdkAuthorization(),
PaymentSubmissionResponse.class,
request,
null);
}

// Common methods
void validatePaymentSessionRequest(final PaymentSessionRequest paymentSessionRequest)
{
validateParams("paymentSessionRequest", paymentSessionRequest);
private void validatePaymentSessionCreateRequest(final PaymentSessionCreateRequest request) {
validateParams("request", request);

Check failure on line 90 in src/main/java/com/checkout/handlepaymentsandpayouts/flow/FlowClientImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "request" 3 times.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-java&issues=AZz3F1MYieU36SGJFFLy&open=AZz3F1MYieU36SGJFFLy&pullRequest=553
}

void validateSubmitPaymentSessionRequest(final String paymentId, final SubmitPaymentSessionRequest submitPaymentSessionRequest)
{
validateParams("paymentId", paymentId,"submitPaymentSessionRequest", submitPaymentSessionRequest);
private void validatePaymentSessionSubmitParameters(final String sessionId, final PaymentSessionSubmitRequest request) {
validateParams("sessionId", sessionId, "request", request);
}

void validatePaymentSessionWithPaymentRequest(final PaymentSessionWithPaymentRequest paymentSessionWithPaymentRequest)
{
validateParams("paymentSessionWithPaymentRequest", paymentSessionWithPaymentRequest);
private void validatePaymentSessionCompleteRequest(final PaymentSessionCompleteRequest request) {
validateParams("request", request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.checkout.handlepaymentsandpayouts.flow.entities;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
* Configuration options specific to Apple Pay payments.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ApplePayConfiguration extends PaymentMethodConfigurationBase {

/**
* The type of the Apple Pay payment total line item. Default: "final"
*/
@Builder.Default
private TotalType totalType = TotalType.FINAL;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.checkout.handlepaymentsandpayouts.flow.entities;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* Configuration options specific to card payments
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CardConfiguration extends PaymentMethodConfigurationBase {
// Empty class - inherits all properties from base
}
Loading
Loading