#Hugues

1 messages ยท Page 1 of 1 (latest)

junior escarpBOT
mossy parcel
#

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

worn helm
#

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?

mossy parcel
#

Are you planning to write your own scheduling system for these payments? Or are you looking to use Stripe's subscriptions?

worn helm
#

I'm planning to use Stripe's subscriptions and I need to start from a setup intent.

mossy parcel
#

Have you read our docs on creating subscriptions?

#

If you are confirming the SetupIntent, then you have what you need for the initial setup.

worn helm
#

Any example on how to build a subscription from a succeded setup_intent?

mossy parcel
#

You don't use the SetupIntent

junior escarpBOT
mossy parcel
#

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?

worn helm
#

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);
fierce dust
#

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?

worn helm
#

Hi Snufkin, yes, that's it.

#

If you check my code above, would it be sufficient to say: .setDefaultPaymentMethod(paymentMethod.getId()) ?

fierce dust
#

Yes, that would use the Payment Method you created and set it as the default for this subscription

worn helm