#Hugues
1 messages ยท Page 1 of 1 (latest)
So in the API you can either set a payment method to be the default for the Customer or on specific subscriptions
https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method
https://stripe.com/docs/billing/subscriptions/payment-methods-setting
In the doc that you linked to, they demonstrate reusing the PaymentMethod that the SetupIntent generates (the ID that looks like pm_123), those settings that I just linked to use that same payment method object
So you just need to set the payment method as the default payment method for the customer or subscription when creating your subscriptions
Let me check that...
You states the ways to attach a payment method: either to the customer or to a subscription. My question is, how to use a payment method to collect futur recurrent payments?
Are you planning to write your own scheduling system for these payments? Or are you looking to use Stripe's subscriptions?
I'm planning to use Stripe's subscriptions and I need to start from a setup intent.
Have you read our docs on creating subscriptions?
If you are confirming the SetupIntent, then you have what you need for the initial setup.
Any example on how to build a subscription from a succeded setup_intent?
Something like https://stripe.com/docs/billing/subscriptions/acss-debit#collect-payment-and-mandate ?
You don't use the SetupIntent
You use the PaymentMethod that the SetupIntent created
And you use it just like any other PaymentMethod object
Putting that aside for a moment, do you know how to create a subscription with a PaymentMethod once you have one?
SetupIntent setupIntent = ApiResource.GSON.fromJson(deserializer.getRawJson(), SetupIntent.class);
PaymentMethod paymentMethod = PaymentMethod.retrieve(setupIntent.getPaymentMethod());
Customer customer = Customer.retrieve( setupIntent.getCustomer());
SubscriptionCreateParams subscriptionCreateParams = SubscriptionCreateParams
.builder()
.setCustomer(customer.getId())
.addItem(
SubscriptionCreateParams.Item.builder().setPrice(monthlyPmt.getId()).build()
)
.setPaymentBehavior(
SubscriptionCreateParams.PaymentBehavior.DEFAULT_INCOMPLETE
)
.setPaymentSettings(
SubscriptionCreateParams.PaymentSettings
.builder()
// ???????????????????? How would you resuse the above payment method ????????????????????
.addPaymentMethodType(
SubscriptionCreateParams.PaymentSettings.PaymentMethodType.ACSS_DEBIT
)
.build()
)
.setBillingCycleAnchor(unixFrstOfNxtMonth)
.addExpand("latest_invoice.payment_intent")
.build();
Subscription subscription = Subscription.create(subscriptionCreateParams);
Hi ๐
I'm stepping in as @mossy parcel needs to go
So you are asking how you pass the Payment Method you retrieved from the Setup Intent when bulding your subscription params?
Hi Snufkin, yes, that's it.
If you check my code above, would it be sufficient to say: .setDefaultPaymentMethod(paymentMethod.getId()) ?
Yes, that would use the Payment Method you created and set it as the default for this subscription
I was looking for the specific line here: https://github.com/stripe/stripe-java/blob/master/src/main/java/com/stripe/param/SubscriptionCreateParams.java#L292 but it's a bigger file than I thought ๐
Note that the above code snippet came partially from https://stripe.com/docs/billing/subscriptions/acss-debit#collect-payment-and-mandate. I'll try to apply your suggestion. Thanks