From 516c481e949e67e1844bad01536c71a084672344 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Mon, 22 Apr 2024 17:51:40 -0400 Subject: [PATCH] Pass a `CurrencyConversionManager` to `BraintreeManager` --- .../textsecuregcm/WhisperServerService.java | 18 +++++++++--------- .../subscriptions/BraintreeManager.java | 7 ++++++- .../subscriptions/BraintreeManagerTest.java | 2 ++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index 7668f1e7c..35a4ad8ef 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -523,15 +523,6 @@ public class WhisperServerService extends Application dynamicConfigurationManager.getConfiguration().getVirtualThreads().allowedPinEvents(), config.getVirtualThreadConfiguration().pinEventThreshold()); + StripeManager stripeManager = new StripeManager(config.getStripe().apiKey().value(), subscriptionProcessorExecutor, + config.getStripe().idempotencyKeyGenerator().value(), config.getStripe().boostDescription(), config.getStripe().supportedCurrenciesByPaymentMethod()); + BraintreeManager braintreeManager = new BraintreeManager(config.getBraintree().merchantId(), + config.getBraintree().publicKey(), config.getBraintree().privateKey().value(), + config.getBraintree().environment(), + config.getBraintree().supportedCurrenciesByPaymentMethod(), config.getBraintree().merchantAccounts(), + config.getBraintree().graphqlUrl(), currencyManager, config.getBraintree().circuitBreaker(), subscriptionProcessorExecutor, + subscriptionProcessorRetryExecutor); + environment.lifecycle().manage(apnSender); environment.lifecycle().manage(apnPushNotificationScheduler); environment.lifecycle().manage(provisioningManager); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/BraintreeManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/BraintreeManager.java index 54dfcc440..b30c537ec 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/BraintreeManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/subscriptions/BraintreeManager.java @@ -42,6 +42,7 @@ import javax.ws.rs.core.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration; +import org.whispersystems.textsecuregcm.currency.CurrencyConversionManager; import org.whispersystems.textsecuregcm.http.FaultTolerantHttpClient; import org.whispersystems.textsecuregcm.util.SystemMapper; import org.whispersystems.textsecuregcm.util.ua.ClientPlatform; @@ -55,6 +56,7 @@ public class BraintreeManager implements SubscriptionProcessorManager { private static final String PAYPAL_PAYMENT_ALREADY_COMPLETED_PROCESSOR_CODE = "2094"; private final BraintreeGateway braintreeGateway; private final BraintreeGraphqlClient braintreeGraphqlClient; + private final CurrencyConversionManager currencyConversionManager; private final Executor executor; private final Map> supportedCurrenciesByPaymentMethod; private final Map currenciesToMerchantAccounts; @@ -65,6 +67,7 @@ public class BraintreeManager implements SubscriptionProcessorManager { final Map> supportedCurrenciesByPaymentMethod, final Map currenciesToMerchantAccounts, final String graphqlUri, + final CurrencyConversionManager currencyConversionManager, final CircuitBreakerConfiguration circuitBreakerConfiguration, final Executor executor, final ScheduledExecutorService retryExecutor) { @@ -83,6 +86,7 @@ public class BraintreeManager implements SubscriptionProcessorManager { // https://developer.paypal.com/braintree/docs/reference/general/best-practices/java#timeouts .withRequestTimeout(Duration.ofSeconds(70)) .build(), graphqlUri, braintreePublicKey, braintreePrivateKey), + currencyConversionManager, executor); } @@ -90,11 +94,12 @@ public class BraintreeManager implements SubscriptionProcessorManager { BraintreeManager(final BraintreeGateway braintreeGateway, final Map> supportedCurrenciesByPaymentMethod, final Map currenciesToMerchantAccounts, final BraintreeGraphqlClient braintreeGraphqlClient, - final Executor executor) { + final CurrencyConversionManager currencyConversionManager, final Executor executor) { this.braintreeGateway = braintreeGateway; this.supportedCurrenciesByPaymentMethod = supportedCurrenciesByPaymentMethod; this.currenciesToMerchantAccounts = currenciesToMerchantAccounts; this.braintreeGraphqlClient = braintreeGraphqlClient; + this.currencyConversionManager = currencyConversionManager; this.executor = executor; } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/BraintreeManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/BraintreeManagerTest.java index fff9204ff..52f93f68d 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/BraintreeManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/subscriptions/BraintreeManagerTest.java @@ -19,6 +19,7 @@ import java.util.Set; import java.util.concurrent.Executors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.whispersystems.textsecuregcm.currency.CurrencyConversionManager; class BraintreeManagerTest { @@ -32,6 +33,7 @@ class BraintreeManagerTest { Map.of(PaymentMethod.CARD, Set.of("usd")), Map.of("usd", "usdMerchant"), mock(BraintreeGraphqlClient.class), + mock(CurrencyConversionManager.class), Executors.newSingleThreadExecutor()); }