Skip to content

Commit

Permalink
Api Updates
Browse files Browse the repository at this point in the history
* Add reference property to Financial Actions query
* Add support for Forex (FX) rates API
* Remove marketplace from HostedPayments & PaymentLinks
  • Loading branch information
martinseco committed Apr 6, 2023
1 parent 45d272c commit 6482d0f
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class FinancialActionsQueryFilter {
@SerializedName("action_id")
private String actionId;

private String reference;

@Size(min = 1, max = 100)
private Integer limit;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/checkout/forex/ForexClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface ForexClient {

CompletableFuture<QuoteResponse> requestQuote(QuoteRequest quoteRequest);

CompletableFuture<RatesQueryResponse> getRates(RatesQueryFilter ratesQuery);
}
6 changes: 6 additions & 0 deletions src/main/java/com/checkout/forex/ForexClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ public CompletableFuture<QuoteResponse> requestQuote(final QuoteRequest quoteReq
return apiClient.postAsync("forex/quotes", sdkAuthorization(), QuoteResponse.class, quoteRequest, null);
}

@Override
public CompletableFuture<RatesQueryResponse> getRates(RatesQueryFilter ratesQuery) {
CheckoutUtils.validateParams("ratesQuery", ratesQuery);
return apiClient.queryAsync("forex/rates", sdkAuthorization(), ratesQuery, RatesQueryResponse.class);
}

}
14 changes: 14 additions & 0 deletions src/main/java/com/checkout/forex/ForexRate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.checkout.forex;

import com.google.gson.annotations.SerializedName;
import lombok.Data;

@Data
public class ForexRate {

@SerializedName("exchange_rate")
private Double exchangeRate;

@SerializedName("currency_pair")
private String currencyPair;
}
11 changes: 11 additions & 0 deletions src/main/java/com/checkout/forex/ForexSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.checkout.forex;

import com.google.gson.annotations.SerializedName;

public enum ForexSource {

@SerializedName("visa")
VISA,
@SerializedName("mastercard")
MASTERCARD,
}
27 changes: 27 additions & 0 deletions src/main/java/com/checkout/forex/RatesQueryFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.checkout.forex;

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

@Data
@Builder
@AllArgsConstructor
public class RatesQueryFilter {

@NonNull
private String product;

@NonNull
private ForexSource source;

@NonNull
@SerializedName("currency_pairs")
private String currencyPairs;

@NonNull
@SerializedName("processing_channel_id")
private String processChannelId;
}
20 changes: 20 additions & 0 deletions src/main/java/com/checkout/forex/RatesQueryResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.checkout.forex;

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

import java.util.List;

@Data
public class RatesQueryResponse extends HttpMetadata {

private String product;

private ForexSource source;

private List<ForexRate> rates;

@SerializedName("invalid_currency_pairs")
private List<String> invalidCurrencyPairs;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.checkout.common.AmountAllocations;
import com.checkout.common.Currency;
import com.checkout.common.CustomerRequest;
import com.checkout.common.MarketplaceData;
import com.checkout.common.PaymentSourceType;
import com.checkout.common.Product;
import com.checkout.payments.BillingDescriptor;
Expand Down Expand Up @@ -88,13 +87,6 @@ public final class HostedPaymentRequest {
@SerializedName("processing_channel_id")
private String processingChannelId;

/**
* @deprecated This property will be removed in the future, and should be used
* {@link HostedPaymentRequest#amountAllocations} instead
*/
@Deprecated
private MarketplaceData marketplace;

@SerializedName("amount_allocations")
private List<AmountAllocations> amountAllocations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.checkout.common.AmountAllocations;
import com.checkout.common.Currency;
import com.checkout.common.CustomerResponse;
import com.checkout.common.MarketplaceData;
import com.checkout.common.Product;
import com.checkout.common.Resource;
import com.checkout.payments.BillingInformation;
Expand Down Expand Up @@ -43,13 +42,6 @@ public final class PaymentLinkDetailsResponse extends Resource {
@SerializedName("processing_channel_id")
private String processingChannelId;

/**
* @deprecated This property will be removed in the future, and should be used
* {@link PaymentLinkDetailsResponse#amountAllocations} instead
*/
@Deprecated
private MarketplaceData marketplace;

@SerializedName("amount_allocations")
private List<AmountAllocations> amountAllocations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.checkout.common.AmountAllocations;
import com.checkout.common.Currency;
import com.checkout.common.CustomerRequest;
import com.checkout.common.MarketplaceData;
import com.checkout.common.PaymentSourceType;
import com.checkout.common.Product;
import com.checkout.payments.BillingDescriptor;
Expand Down Expand Up @@ -85,13 +84,6 @@ public final class PaymentLinkRequest {
@SerializedName("processing_channel_id")
private String processingChannelId;

/**
* @deprecated This property will be removed in the future, and should be used
* {@link PaymentLinkRequest#amountAllocations} instead
*/
@Deprecated
private MarketplaceData marketplace;

@SerializedName("amount_allocations")
private List<AmountAllocations> amountAllocations;

Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/checkout/forex/ForexClientImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,27 @@ void shouldRequestQuote() throws ExecutionException, InterruptedException {

assertNotNull(future.get());
assertEquals(response, future.get());
}

@Test
void shouldGetRates() throws ExecutionException, InterruptedException {

final RatesQueryFilter request = RatesQueryFilter.builder()
.product("card_payouts")
.source(ForexSource.VISA)
.currencyPairs("GBPEUR,USDNOK,JPNCAD")
.processChannelId("pc_abcdefghijklmnopqrstuvwxyz")
.build();
final RatesQueryResponse response = mock(RatesQueryResponse.class);

when(apiClient.queryAsync(eq("forex/rates"), eq(authorization), eq(request),
eq(RatesQueryResponse.class)))
.thenReturn(CompletableFuture.completedFuture(response));

final CompletableFuture<RatesQueryResponse> future = client.getRates(request);

assertNotNull(future.get());
assertEquals(response, future.get());
}

}
21 changes: 21 additions & 0 deletions src/test/java/com/checkout/forex/ForexTestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.checkout.PlatformType;
import com.checkout.SandboxTestFixture;
import com.checkout.common.Currency;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -38,4 +39,24 @@ void shouldRequestQuote() {
assertFalse(response.isSingleUse());
}

@Disabled("Skipping because processing_channel_id is invalid")
@Test
void shouldGetRates() {

final RatesQueryFilter request = RatesQueryFilter.builder()
.product("card_payouts")
.source(ForexSource.VISA)
.currencyPairs("GBPEUR,USDNOK,JPNCAD")
.processChannelId("pc_abcdefghijklmnopqrstuvwxyz")
.build();
final RatesQueryResponse response = blocking(() -> checkoutApi.forexClient().getRates(request));

assertNotNull(response);
assertNotNull(response.getProduct());
assertNotNull(response.getSource());
assertEquals(request.getProduct(), response.getProduct());
assertEquals(request.getSource(), response.getSource());
assertNotNull(response.getRates());
}

}

0 comments on commit 6482d0f

Please sign in to comment.