Propagate another subscription processor error to clients

This commit is contained in:
Chris Eager 2023-12-14 14:40:08 -06:00 committed by GitHub
parent 3548c3df15
commit bb347999ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 34 deletions

View File

@ -285,14 +285,8 @@ public class StripeManager implements SubscriptionProcessorManager {
} catch (StripeException e) { } catch (StripeException e) {
if (e instanceof CardException ce) { if (e instanceof CardException ce) {
throw new CompletionException(new SubscriptionProcessorException(getProcessor(), throw new CompletionException(
new ChargeFailure( new SubscriptionProcessorException(getProcessor(), createChargeFailureFromCardException(e, ce)));
StringUtils.defaultIfBlank(ce.getDeclineCode(), ce.getCode()),
e.getStripeError().getMessage(),
null,
null,
null
)));
} }
throw new CompletionException(e); throw new CompletionException(e);
@ -337,8 +331,14 @@ public class StripeManager implements SubscriptionProcessorManager {
commonOptions( commonOptions(
generateIdempotencyKeyForSubscriptionUpdate(subscription.getCustomer(), idempotencyKey))); generateIdempotencyKeyForSubscriptionUpdate(subscription.getCustomer(), idempotencyKey)));
} catch (StripeException e) { } catch (StripeException e) {
if (e instanceof CardException ce) {
throw new CompletionException(
new SubscriptionProcessorException(getProcessor(), createChargeFailureFromCardException(e, ce)));
}
throw new CompletionException(e); throw new CompletionException(e);
} }
}, executor) }, executor)
.thenApply(subscription1 -> new SubscriptionId(subscription1.getId())); .thenApply(subscription1 -> new SubscriptionId(subscription1.getId()));
} }
@ -504,6 +504,16 @@ public class StripeManager implements SubscriptionProcessorManager {
outcome != null ? outcome.getType() : null); outcome != null ? outcome.getType() : null);
} }
private static ChargeFailure createChargeFailureFromCardException(StripeException e, CardException ce) {
return new ChargeFailure(
StringUtils.defaultIfBlank(ce.getDeclineCode(), ce.getCode()),
e.getStripeError().getMessage(),
null,
null,
null
);
}
@Override @Override
public CompletableFuture<SubscriptionInformation> getSubscriptionInformation(Object subscriptionObj) { public CompletableFuture<SubscriptionInformation> getSubscriptionInformation(Object subscriptionObj) {