|
|
|
|
@ -580,11 +580,6 @@ public class SubscriberService(
@@ -580,11 +580,6 @@ public class SubscriberService(
|
|
|
|
|
PaymentMethod = token |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var getExistingSetupIntentsForCustomer = stripeAdapter.SetupIntentList(new SetupIntentListOptions |
|
|
|
|
{ |
|
|
|
|
Customer = subscriber.GatewayCustomerId |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Find the setup intent for the incoming payment method token. |
|
|
|
|
var setupIntentsForUpdatedPaymentMethod = await getSetupIntentsForUpdatedPaymentMethod; |
|
|
|
|
|
|
|
|
|
@ -597,24 +592,15 @@ public class SubscriberService(
@@ -597,24 +592,15 @@ public class SubscriberService(
|
|
|
|
|
|
|
|
|
|
var matchingSetupIntent = setupIntentsForUpdatedPaymentMethod.First(); |
|
|
|
|
|
|
|
|
|
// Find the customer's existing setup intents that should be canceled. |
|
|
|
|
var existingSetupIntentsForCustomer = (await getExistingSetupIntentsForCustomer) |
|
|
|
|
.Where(si => |
|
|
|
|
si.Status is "requires_payment_method" or "requires_confirmation" or "requires_action"); |
|
|
|
|
|
|
|
|
|
// Store the incoming payment method's setup intent ID in the cache for the subscriber so it can be verified later. |
|
|
|
|
await setupIntentCache.Set(subscriber.Id, matchingSetupIntent.Id); |
|
|
|
|
|
|
|
|
|
// Cancel the customer's other open setup intents. |
|
|
|
|
var postProcessing = existingSetupIntentsForCustomer.Select(si => |
|
|
|
|
stripeAdapter.SetupIntentCancel(si.Id, |
|
|
|
|
new SetupIntentCancelOptions { CancellationReason = "abandoned" })).ToList(); |
|
|
|
|
|
|
|
|
|
// Remove the customer's other attached Stripe payment methods. |
|
|
|
|
postProcessing.Add(RemoveStripePaymentMethodsAsync(customer)); |
|
|
|
|
|
|
|
|
|
// Remove the customer's Braintree customer ID. |
|
|
|
|
postProcessing.Add(RemoveBraintreeCustomerIdAsync(customer)); |
|
|
|
|
var postProcessing = new List<Task> |
|
|
|
|
{ |
|
|
|
|
RemoveStripePaymentMethodsAsync(customer), |
|
|
|
|
RemoveBraintreeCustomerIdAsync(customer) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
await Task.WhenAll(postProcessing); |
|
|
|
|
|
|
|
|
|
@ -622,11 +608,6 @@ public class SubscriberService(
@@ -622,11 +608,6 @@ public class SubscriberService(
|
|
|
|
|
} |
|
|
|
|
case PaymentMethodType.Card: |
|
|
|
|
{ |
|
|
|
|
var getExistingSetupIntentsForCustomer = stripeAdapter.SetupIntentList(new SetupIntentListOptions |
|
|
|
|
{ |
|
|
|
|
Customer = subscriber.GatewayCustomerId |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Remove the customer's other attached Stripe payment methods. |
|
|
|
|
await RemoveStripePaymentMethodsAsync(customer); |
|
|
|
|
|
|
|
|
|
@ -634,16 +615,6 @@ public class SubscriberService(
@@ -634,16 +615,6 @@ public class SubscriberService(
|
|
|
|
|
await stripeAdapter.PaymentMethodAttachAsync(token, |
|
|
|
|
new PaymentMethodAttachOptions { Customer = subscriber.GatewayCustomerId }); |
|
|
|
|
|
|
|
|
|
// Find the customer's existing setup intents that should be canceled. |
|
|
|
|
var existingSetupIntentsForCustomer = (await getExistingSetupIntentsForCustomer) |
|
|
|
|
.Where(si => |
|
|
|
|
si.Status is "requires_payment_method" or "requires_confirmation" or "requires_action"); |
|
|
|
|
|
|
|
|
|
// Cancel the customer's other open setup intents. |
|
|
|
|
var postProcessing = existingSetupIntentsForCustomer.Select(si => |
|
|
|
|
stripeAdapter.SetupIntentCancel(si.Id, |
|
|
|
|
new SetupIntentCancelOptions { CancellationReason = "abandoned" })).ToList(); |
|
|
|
|
|
|
|
|
|
var metadata = customer.Metadata; |
|
|
|
|
|
|
|
|
|
if (metadata.TryGetValue(BraintreeCustomerIdKey, out var value)) |
|
|
|
|
@ -653,16 +624,14 @@ public class SubscriberService(
@@ -653,16 +624,14 @@ public class SubscriberService(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set the customer's default payment method in Stripe and remove their Braintree customer ID. |
|
|
|
|
postProcessing.Add(stripeAdapter.CustomerUpdateAsync(subscriber.GatewayCustomerId, new CustomerUpdateOptions |
|
|
|
|
await stripeAdapter.CustomerUpdateAsync(subscriber.GatewayCustomerId, new CustomerUpdateOptions |
|
|
|
|
{ |
|
|
|
|
InvoiceSettings = new CustomerInvoiceSettingsOptions |
|
|
|
|
{ |
|
|
|
|
DefaultPaymentMethod = token |
|
|
|
|
}, |
|
|
|
|
Metadata = metadata |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
await Task.WhenAll(postProcessing); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|