#Dooing-subscription
1 messages · Page 1 of 1 (latest)
Hi 👋 no it is not possible to do all of that in a single request, and the creation of a Payment Method will require backend and frontend components to be SCA/3DS compatible. Will your Subscriptions be beginning with a free trial period, or will they be billing immediately?
trial - depends. might be both, want to stay flexible.
this is my approach for the subscription part:
public void createSubscription(String stripeCustomerId, String stripePriceId, Long endOfTrialTimestamp) {
try {
SubscriptionCreateParams subCreateParams = SubscriptionCreateParams.builder()
.addItem(SubscriptionCreateParams.Item.builder()
.setPrice(stripePriceId)
.build())
.setCustomer(stripeCustomerId)
.setTrialEnd(endOfTrialTimestamp)
.setPaymentSettings(SubscriptionCreateParams.PaymentSettings.builder()
.setSaveDefaultPaymentMethod(SubscriptionCreateParams.PaymentSettings.SaveDefaultPaymentMethod.ON_SUBSCRIPTION)
.build())
.addExpand("latest_invoice.payment_intent")
.addExpand("pending_setup_intent")
.build();
Subscription subscription = Subscription.create(subCreateParams);
SetupIntent pendingSetupIntentObject = subscription.getPendingSetupIntentObject();
String clientSecret;
if (pendingSetupIntentObject != null) {
clientSecret = pendingSetupIntentObject.getClientSecret();
} else {
clientSecret = subscription.getLatestInvoiceObject()
.getPaymentIntentObject()
.getClientSecret();
}
If your Subscription doesn't require an initial payment, then it will contain a pending_setup_intent. If it requires an initial payment, then instead the Subscription will generate it's first Invoice which will contain a Payment Intent.
Are you planning to collect payment method information at the beginning of the flow regardless of whether the Subscription will require an immediate payment?
Are you planning to collect payment method information at the beginning of the flow regardless of whether the Subscription will require an immediate payment?
yes
Then I would recommend following this approach for creating a Customer and an associated Payment Method that is prepared for future off-session payments.
https://stripe.com/docs/payments/save-and-reuse
Then you can either set the created Payment Method as the Customer's default for invoices and Subscriptions will use that, or you can explicitly provide the created Payment Method to the Subscription while creating the Subscription.
so you are saying, the steps are:
- Create customer
- Create payment card
- Create subscription and get a secret key to 3dSecure confirm the payment card in this call as I did above?
that would be 3 calls from the backend, andAFAIK 2 calls from the client (frontend)
client:
- Create card for customer
- Confirm card creation / 3D secure with secret key
When you create the Payment Method, that will trigger a 3DS challenge if needed. Then, for future off-session payments we will request an exemption from 3DS, but it's up to the to decide whether they will grant that exception.
So you will not need to complete 3DS for Step 3 of the server flow most of the time, though your code should be ready to handle the scenario where you do in case that is encountered.