Add charge failure details to /v1/subscription/boost/receipt_credential 402 response

This commit is contained in:
Katherine
2023-10-19 10:21:26 -07:00
committed by GitHub
parent bc35278684
commit 5990a100db
5 changed files with 86 additions and 17 deletions

View File

@@ -117,11 +117,15 @@ public class BraintreeManager implements SubscriptionProcessorManager {
return CompletableFuture.supplyAsync(() -> {
try {
final Transaction transaction = braintreeGateway.transaction().find(paymentId);
ChargeFailure chargeFailure = null;
if (!getPaymentStatus(transaction.getStatus()).equals(PaymentStatus.SUCCEEDED)) {
chargeFailure = createChargeFailure(transaction);
}
return new PaymentDetails(transaction.getGraphQLId(),
transaction.getCustomFields(),
getPaymentStatus(transaction.getStatus()),
transaction.getCreatedAt().toInstant());
transaction.getCreatedAt().toInstant(),
chargeFailure);
} catch (final NotFoundException e) {
return null;
@@ -433,7 +437,7 @@ public class BraintreeManager implements SubscriptionProcessorManager {
if (latestTransaction.isPresent()){
paymentProcessing = isPaymentProcessing(latestTransaction.get().getStatus());
if (!getPaymentStatus(latestTransaction.get().getStatus()).equals(PaymentStatus.SUCCEEDED)) {
if (getPaymentStatus(latestTransaction.get().getStatus()) != PaymentStatus.SUCCEEDED) {
chargeFailure = createChargeFailure(latestTransaction.get());
}
}
@@ -470,7 +474,10 @@ public class BraintreeManager implements SubscriptionProcessorManager {
final String code;
final String message;
if (transaction.getProcessorResponseCode() != null) {
if (transaction.getStatus() == Transaction.Status.VOIDED) {
code = "voided";
message = "voided";
} else if (transaction.getProcessorResponseCode() != null) {
code = transaction.getProcessorResponseCode();
message = transaction.getProcessorResponseText();
} else if (transaction.getGatewayRejectionReason() != null) {

View File

@@ -28,6 +28,7 @@ import com.stripe.param.CustomerUpdateParams;
import com.stripe.param.CustomerUpdateParams.InvoiceSettings;
import com.stripe.param.InvoiceListParams;
import com.stripe.param.PaymentIntentCreateParams;
import com.stripe.param.PaymentIntentRetrieveParams;
import com.stripe.param.PriceRetrieveParams;
import com.stripe.param.SetupIntentCreateParams;
import com.stripe.param.SubscriptionCancelParams;
@@ -216,12 +217,23 @@ public class StripeManager implements SubscriptionProcessorManager {
public CompletableFuture<PaymentDetails> getPaymentDetails(String paymentIntentId) {
return CompletableFuture.supplyAsync(() -> {
try {
final PaymentIntent paymentIntent = stripeClient.paymentIntents().retrieve(paymentIntentId, commonOptions());
final PaymentIntentRetrieveParams params = PaymentIntentRetrieveParams.builder()
.addExpand("latest_charge").build();
final PaymentIntent paymentIntent = stripeClient.paymentIntents().retrieve(paymentIntentId, params, commonOptions());
ChargeFailure chargeFailure = null;
if (paymentIntent.getLatestChargeObject() != null) {
final Charge charge = paymentIntent.getLatestChargeObject();
if (charge.getFailureCode() != null || charge.getFailureMessage() != null) {
chargeFailure = createChargeFailure(charge);
}
}
return new PaymentDetails(paymentIntent.getId(),
paymentIntent.getMetadata() == null ? Collections.emptyMap() : paymentIntent.getMetadata(),
getPaymentStatusForStatus(paymentIntent.getStatus()),
Instant.ofEpochSecond(paymentIntent.getCreated()));
Instant.ofEpochSecond(paymentIntent.getCreated()),
chargeFailure);
} catch (StripeException e) {
if (e.getStatusCode() == 404) {
return null;
@@ -479,6 +491,16 @@ public class StripeManager implements SubscriptionProcessorManager {
}, executor);
}
private static ChargeFailure createChargeFailure(final Charge charge) {
Charge.Outcome outcome = charge.getOutcome();
return new ChargeFailure(
charge.getFailureCode(),
charge.getFailureMessage(),
outcome != null ? outcome.getNetworkStatus() : null,
outcome != null ? outcome.getReason() : null,
outcome != null ? outcome.getType() : null);
}
@Override
public CompletableFuture<SubscriptionInformation> getSubscriptionInformation(Object subscriptionObj) {
@@ -497,13 +519,7 @@ public class StripeManager implements SubscriptionProcessorManager {
if (invoice.getChargeObject() != null) {
final Charge charge = invoice.getChargeObject();
if (charge.getFailureCode() != null || charge.getFailureMessage() != null) {
Charge.Outcome outcome = charge.getOutcome();
chargeFailure = new ChargeFailure(
charge.getFailureCode(),
charge.getFailureMessage(),
outcome != null ? outcome.getNetworkStatus() : null,
outcome != null ? outcome.getReason() : null,
outcome != null ? outcome.getType() : null);
chargeFailure = createChargeFailure(charge);
}
if (charge.getPaymentMethodDetails() != null

View File

@@ -60,7 +60,8 @@ public interface SubscriptionProcessorManager {
record PaymentDetails(String id,
Map<String, String> customMetadata,
PaymentStatus status,
Instant created) {
Instant created,
@Nullable ChargeFailure chargeFailure) {
}