Remove duplicate code
This commit is contained in:
parent
cf738a1c14
commit
c2f40b8503
|
@ -297,32 +297,17 @@ 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 -> {
|
.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)
|
||||||
// with a different level.
|
// with a different level.
|
||||||
// In this case, it’s safer and easier to recover by returning this subscription, rather than
|
// In this case, it’s safer and easier to recover by returning this subscription, rather than
|
||||||
// returning an error
|
// returning an error
|
||||||
logger.warn("existing subscription had unexpected level");
|
logger.warn("existing subscription had unexpected level");
|
||||||
}
|
}
|
||||||
return plan;
|
return subscription;
|
||||||
})).orElseGet(() -> findPlan(planId));
|
}))
|
||||||
|
|
||||||
return maybeExistingSubscription
|
|
||||||
.map(subscription -> {
|
|
||||||
return findPlan(subscription.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, it’s safer and easier to recover by returning this subscription, rather than
|
|
||||||
// returning an error
|
|
||||||
logger.warn("existing subscription had unexpected level");
|
|
||||||
}
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue