Remove duplicate code

This commit is contained in:
Chris Eager 2023-01-19 16:38:24 -06:00 committed by Jon Chambers
parent cf738a1c14
commit c2f40b8503
1 changed files with 11 additions and 26 deletions

View File

@ -297,21 +297,7 @@ public class BraintreeManager implements SubscriptionProcessorManager {
.filter(Subscription::neverExpires) .filter(Subscription::neverExpires)
.findAny(); .findAny();
final CompletableFuture<Plan> planFuture = maybeExistingSubscription.map(sub -> return maybeExistingSubscription.map(subscription -> findPlan(subscription.getPlanId())
findPlan(sub.getPlanId()).thenApply(plan -> {
if (getLevelForPlan(plan) != level) {
// if this happens, the likely cause is retrying an apparently failed request (likely some sort of timeout or network interruption)
// with a different level.
// In this case, its safer and easier to recover by returning this subscription, rather than
// returning an error
logger.warn("existing subscription had unexpected level");
}
return plan;
})).orElseGet(() -> findPlan(planId));
return maybeExistingSubscription
.map(subscription -> {
return findPlan(subscription.getPlanId())
.thenApply(plan -> { .thenApply(plan -> {
if (getLevelForPlan(plan) != level) { if (getLevelForPlan(plan) != level) {
// if this happens, the likely cause is retrying an apparently failed request (likely some sort of timeout or network interruption) // if this happens, the likely cause is retrying an apparently failed request (likely some sort of timeout or network interruption)
@ -321,8 +307,7 @@ public class BraintreeManager implements SubscriptionProcessorManager {
logger.warn("existing subscription had unexpected level"); logger.warn("existing subscription had unexpected level");
} }
return subscription; return subscription;
}); }))
})
.orElseGet(() -> findPlan(planId).thenApplyAsync(plan -> { .orElseGet(() -> findPlan(planId).thenApplyAsync(plan -> {
final Result<Subscription> result = braintreeGateway.subscription().create(new SubscriptionRequest() final Result<Subscription> result = braintreeGateway.subscription().create(new SubscriptionRequest()
.planId(planId) .planId(planId)