Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment Contexts Support (CS2) #379

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
4 changes: 4 additions & 0 deletions src/main/java/com/checkout/CheckoutApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.checkout.issuing.IssuingClient;
import com.checkout.metadata.MetadataClient;
import com.checkout.payments.PaymentsClient;
import com.checkout.payments.contexts.PaymentContexts;
import com.checkout.payments.contexts.PaymentContextsClient;
import com.checkout.payments.hosted.HostedPaymentsClient;
import com.checkout.payments.links.PaymentLinksClient;
import com.checkout.reports.ReportsClient;
Expand Down Expand Up @@ -57,5 +59,7 @@ public interface CheckoutApi extends CheckoutApmApi {

IssuingClient issuingClient();

PaymentContextsClient paymentContextsClient();

}

8 changes: 8 additions & 0 deletions src/main/java/com/checkout/CheckoutApiImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.checkout.metadata.MetadataClientImpl;
import com.checkout.payments.PaymentsClient;
import com.checkout.payments.PaymentsClientImpl;
import com.checkout.payments.contexts.PaymentContexts;
import com.checkout.payments.contexts.PaymentContextsClient;
import com.checkout.payments.contexts.PaymentContextsClientImpl;
import com.checkout.payments.hosted.HostedPaymentsClient;
import com.checkout.payments.hosted.HostedPaymentsClientImpl;
import com.checkout.payments.links.PaymentLinksClient;
Expand Down Expand Up @@ -59,6 +62,7 @@ public class CheckoutApiImpl extends AbstractCheckoutApmApi implements CheckoutA
private final MetadataClient metadataClient;
private final FinancialClient financialClient;
private final IssuingClient issuingClient;
private final PaymentContextsClient paymentContextsClient;

public CheckoutApiImpl(final CheckoutConfiguration configuration) {
super(configuration);
Expand All @@ -82,6 +86,7 @@ public CheckoutApiImpl(final CheckoutConfiguration configuration) {
this.accountsClient = new AccountsClientImpl(this.apiClient,
getFilesClient(configuration),
configuration);
this.paymentContextsClient = new PaymentContextsClientImpl(this.apiClient, configuration);

}

Expand Down Expand Up @@ -171,6 +176,9 @@ public MetadataClient metadataClient() {
@Override
public IssuingClient issuingClient() { return issuingClient; }

@Override
public PaymentContextsClient paymentContextsClient() { return paymentContextsClient; }

private ApiClient getFilesClient(final CheckoutConfiguration configuration) {
return new ApiClientImpl(configuration, new FilesApiUriStrategy(configuration));
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/checkout/GsonSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public class GsonSerializer implements Serializer {
.registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(com.checkout.payments.response.source.ResponseSource.class, CheckoutUtils.TYPE, true, com.checkout.payments.response.source.AlternativePaymentSourceResponse.class)
.registerSubtype(com.checkout.payments.response.source.CardResponseSource.class, identifier(PaymentSourceType.CARD))
.registerSubtype(com.checkout.payments.response.source.CurrencyAccountResponseSource.class, identifier(PaymentSourceType.CURRENCY_ACCOUNT)))
// Payment Contexts
.registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(com.checkout.payments.response.source.contexts.ResponseSource.class, CheckoutUtils.TYPE, true, com.checkout.payments.response.source.contexts.AlternativePaymentSourceResponse.class)
.registerSubtype(com.checkout.payments.response.source.contexts.PaymentContextsPayPayResponseSource.class, identifier(PaymentSourceType.PAYPAL)))
// Payments - destination
.registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(com.checkout.payments.response.destination.PaymentResponseDestination.class, CheckoutUtils.TYPE, true, com.checkout.payments.response.destination.PaymentResponseAlternativeDestination.class)
.registerSubtype(com.checkout.payments.response.destination.PaymentResponseBankAccountDestination.class, identifier(PaymentDestinationType.BANK_ACCOUNT)))
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/checkout/OAuthScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public enum OAuthScope {
ISSUING_CLIENT("issuing:client"),
ISSUING_CARD_MGMT("issuing:card-mgmt"),
ISSUING_CONTROLS_READ("issuing:controls-read"),
ISSUING_CONTROLS_WRITE("issuing:controls-write");
ISSUING_CONTROLS_WRITE("issuing:controls-write"),
PAYMENT_CONTEXTS("Payment Contexts");

private final String scope;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/checkout/payments/ShippingDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public final class ShippingDetails {
@SerializedName("method")
private ShippingDetailsMethods method;

private Integer delay;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.checkout.payments.contexts;

import com.checkout.HttpMetadata;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@EqualsAndHashCode(callSuper = true)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
Dismissed Show dismissed Hide dismissed
Fixed Show fixed Hide fixed
@ToString(callSuper = true)
@NoArgsConstructor
public final class PaymentContextDetailsResponse extends HttpMetadata {

@SerializedName("payment_request")
private PaymentContextsResponse paymentRequest;

@SerializedName("partner_metadata")
private PaymentContextsPartnerMetadata partnerMetadata;

private Object customer;

}
45 changes: 45 additions & 0 deletions src/main/java/com/checkout/payments/contexts/PaymentContexts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.checkout.payments.contexts;

import com.checkout.common.Currency;
import com.checkout.payments.PaymentType;
import com.checkout.payments.ShippingDetails;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PaymentContexts {

public Long amount;

public Currency currency;

@SerializedName("payment_type")
public PaymentType paymentType;

public boolean capture;

public ShippingDetails shipping;

public PaymentContextsProcessing processing;

@SerializedName("processing_channel_id")
public String processingChannelId;

public String reference;

public String description;

@SerializedName("success_url")
public String successUrl;

@SerializedName("failure_url")
public String failureUrl;

public List<PaymentContextsItems> items;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.checkout.payments.contexts;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public final class PaymentContextsAirlineData {

private List<PaymentContextsTicket> ticket;

private List<PaymentContextsPassenger> passenger;

@SerializedName("flight_leg_details")
private List<PaymentContextsFlightLegDetails> flightLegDetails;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.checkout.payments.contexts;

import java.util.concurrent.CompletableFuture;

public interface PaymentContextsClient {

CompletableFuture<PaymentContextsRequestResponse> requestPaymentContexts(PaymentContextsRequest paymentContextsRequest);

CompletableFuture<PaymentContextDetailsResponse> getPaymentContextDetails(String paymentContextId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.checkout.payments.contexts;

import com.checkout.AbstractClient;
import com.checkout.ApiClient;
import com.checkout.CheckoutConfiguration;
import com.checkout.SdkAuthorizationType;

import java.util.concurrent.CompletableFuture;

import static com.checkout.common.CheckoutUtils.validateParams;

public class PaymentContextsClientImpl extends AbstractClient implements PaymentContextsClient {

private static final String PAYMENT_CONTEXTS_PATH = "payment-contexts";

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

@Override
public CompletableFuture<PaymentContextsRequestResponse> requestPaymentContexts(final PaymentContextsRequest paymentContextsRequest) {
validateParams("paymentContextsRequest", paymentContextsRequest);
return apiClient.postAsync(PAYMENT_CONTEXTS_PATH, sdkAuthorization(), PaymentContextsRequestResponse.class, paymentContextsRequest, null);
}

@Override
public CompletableFuture<PaymentContextDetailsResponse> getPaymentContextDetails(final String paymentContextId) {
validateParams("paymentContextId", paymentContextId);
return apiClient.getAsync(buildPath(PAYMENT_CONTEXTS_PATH, paymentContextId), sdkAuthorization(), PaymentContextDetailsResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.checkout.payments.contexts;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public final class PaymentContextsFlightLegDetails {

@SerializedName("flight_number")
private String flightNumber;

@SerializedName("carrier_code")
private String carrierCode;

@SerializedName("class_of_travelling")
private String classOfTravelling;

@SerializedName("departure_airport")
private String departureAirport;

@SerializedName("departure_date")
private Instant departureDate;

@SerializedName("departure_time")
private String departureTime;

@SerializedName("arrival_airport")
private String arrivalAirport;

@SerializedName("stop_over_code")
private String stopOverCode;

@SerializedName("fare_basis_code")
private String fareBasisCode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.checkout.payments.contexts;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public final class PaymentContextsItems {

private String name;

private Integer quantity;

@SerializedName("unit_price")
private Integer unitPrice;

private String reference;

@SerializedName("total_amount")
private Integer totalAmount;

@SerializedName("tax_amount")
private Integer taxAmount;

@SerializedName("discount_amount")
private Integer discountAmount;

private String url;

@SerializedName("image_url")
private String imageUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.checkout.payments.contexts;

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

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public final class PaymentContextsPartnerCustomerRiskData {

private String key;

private String value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.checkout.payments.contexts;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public final class PaymentContextsPartnerMetadata {

@SerializedName("order_id")
private String orderId;

@SerializedName("customer_id")
private String customerId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.checkout.payments.contexts;

import com.checkout.common.Address;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public final class PaymentContextsPassenger {

@SerializedName("first_name")
private String firstName;

@SerializedName("last_name")
private String lastName;

@SerializedName("date_of_birth")
private Instant dateOfBirth;

private Address address;
}
Loading
Loading