mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 02:28:03 +01:00
Add method to set default payment method
This commit is contained in:
@@ -19,6 +19,8 @@ import com.stripe.model.SubscriptionItem;
|
||||
import com.stripe.net.RequestOptions;
|
||||
import com.stripe.param.CustomerCreateParams;
|
||||
import com.stripe.param.CustomerRetrieveParams;
|
||||
import com.stripe.param.CustomerUpdateParams;
|
||||
import com.stripe.param.CustomerUpdateParams.InvoiceSettings;
|
||||
import com.stripe.param.InvoiceListParams;
|
||||
import com.stripe.param.PriceRetrieveParams;
|
||||
import com.stripe.param.SetupIntentCreateParams;
|
||||
@@ -107,6 +109,23 @@ public class StripeManager {
|
||||
}, executor);
|
||||
}
|
||||
|
||||
public CompletableFuture<Customer> setDefaultPaymentMethodForCustomer(String customerId, String paymentMethodId) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Customer customer = new Customer();
|
||||
customer.setId(customerId);
|
||||
CustomerUpdateParams params = CustomerUpdateParams.builder()
|
||||
.setInvoiceSettings(InvoiceSettings.builder()
|
||||
.setDefaultPaymentMethod(paymentMethodId)
|
||||
.build())
|
||||
.build();
|
||||
try {
|
||||
return customer.update(params, commonOptions());
|
||||
} catch (StripeException e) {
|
||||
throw new CompletionException(e);
|
||||
}
|
||||
}, executor);
|
||||
}
|
||||
|
||||
public CompletableFuture<SetupIntent> createSetupIntent(String customerId) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
SetupIntentCreateParams params = SetupIntentCreateParams.builder()
|
||||
@@ -278,7 +297,6 @@ public class StripeManager {
|
||||
.setCreated(InvoiceListParams.Created.builder()
|
||||
.setGte(now.minus(Duration.ofDays(90)).getEpochSecond())
|
||||
.build())
|
||||
.addExpand("lines.data.price.product")
|
||||
.build();
|
||||
try {
|
||||
ArrayList<Invoice> invoices = Lists.newArrayList(Invoice.list(params, commonOptions())
|
||||
|
||||
Reference in New Issue
Block a user