How to handle next steps/card authentication when working with subscriptions? - stripe-payments

Note: I'm using the Node.js SDK, but I assume all Stripe SDKs are thin wrappers around their REST API.
How can I handle card authentication/3D-Secure/next steps when working with subscriptions and receiving a status == incomplete after creating a new subscription?
The documentation isn't very clear about it. It seems that Subscription objects are a higher-order abstraction over PaymentIntent objects, with recurring charges, free trial days, things like this.
However, it seems to be impossible to actually work with a PaymentIntent once you've created a subscription. And the only way to retrieve a PaymentIntent seems to be by using its associated pi_ ID.
Thanks in advance.

Have you seen the Build a subscription guide on Stripe's documentation? Specifically this section, where you collect payment details and confirm the Payment Intent returned on the Subscription object in your applications front-end.

Related

Integrate Paypal subscription in node app

After reading some source code I saw that neither checkout-server-sdk nor payouts-server-sdk contain libraries to implement easily subscriptions.
So what is the right way to proceed today?
Use deprecated paypal-rest-sdk? Implement REST api? Render Paypal Smart Button and use webhooks or anything else?
The Subscriptions documentation explains how to integrate it. Any API calls you implement require a direct HTTP integration, as there is no SDK for subscriptions.
Do not use a deprecated SDK -- apart from the fact that it is deprecated and should not be used for anything, it is also not compatible with the current version of PayPal Subscriptions.
Webhooks are necessary for notification of future events. Webhook event names for subscriptions are listed here, but essentially you can just listen for PAYMENT.SALE.COMPLETED and have all logic be driven based on initial receipt and noting when you expect the next one for the subscription to continue.
For reconciliation, the parameter custom_id can be set when a subscription is created; its value will be returned in future webhooks and other queries of the subscription's status.

Implementing Stripe Subscription flow with free trial period with SCA

I am building a stripe integration for a client. The subscription has a 7-day free trial, following which the customer will be charged a fixed-amount every month.
I am familiar with the Stripe Subscription flow with SCA for subscriptions where the first invoice is paid immediately (and therefore SCA can be triggered on the client end for the current PaymentIntent during the customer sign-up flow), but I am unsure which is the best way to implement a solution where the first payment is not taken immediately.
The Stripe docs suggest setting up a SetupIntent instead, and then making a Merchant-Induced-Transaction (MIT), but this seems to be frowned upon and not completely compliant, not meant for dealing with free-trials? (https://stackoverflow.com/a/62456011/11868365)
SetupIntents are exactly what you'd use for Subscriptions with trial periods. That SO question you linked to is still correct, it's exactly what Stripe Checkout does in subscription mode with free trials.

Stripe PaymentIntents + Subscription

Anyone know how to make a Stripe subscription charge a card automatically on future period payments using the new PaymentsIntent SCA approach?
Stripe's docs are in need of major pruning. I've never seen such convoluted and confusing docs as these ones.
One of the confusing parts is where they say in the docs for PaymentsIntents:
confirmation_method:
automatic
(Default) PaymentIntent can be confirmed using a publishable key. After next_actions are handled, no additional confirmation is required to complete the payment.
manual
All payment attempts must be made using a secret key. The PaymentIntent returns to the requires_confirmation state after handling next_actions, and requires your server to initiate each payment attempt with an explicit confirmation.
If I put automatic, the handleCardAction doesn't work anymore on the front end. If it has to be manual, does that mean that all future recurring payments (say Month 2, 3, etc) will need some kind of SCA confirmation by the user?
I haven't found any elements examples for paymentintents and subscriptions with SCA and varying plans and prices not pre-set on the backend as they depend on each individual's parameters.
If I use manual and handleCardAction, the subscription stays incomplete, despite the payment going through. If I use confirmCardPayment, the SCA popup never shows.
Looking further into the subscription and intent objects, I noticed that a new subscription created on the server comes with its own paymentIntent object. So does it mean one has to stop creating a separate paymentIntent with own id? If you do, it doesn't work for completing the subscription, which stays as incomplete.
However, the subscription's paymentIntent has a confirmation_method set as automatic by default -- this results in an error after SCA on the frontend: "You cannot confirm this PaymentIntent because it has already succeeded after being previously confirmed". Interesting, why did it ask for the SCA then in the status: "requires_action"?? Are we supposed to change manually the confirmation_method on a subscription to "manual"??
All this is quite confusing how to make subscription / paymentIntent work with SCA.
My logic is simple: user customises a subscription and enters card details, all of which gets sent to the server => Server creates a new plan, product, customer and subscription => Sends intent (from Subscription?) back to FE => If required, SCA is performed and the subscription is confirmed. Is this not how it's supposed to be done? I don't have pre-set plans as they can vary. I just need the ability to charge a user automatically the same amount they paid for the next period.
The examples and docs I've seen so far don't address the above use case. If anyone knows how to do it or can point to an example of how stripe elements and paymentIntents work with SCA and subscriptions that actually works and activates the subscription?
Stripe has a complete guide to fixed-price Subscriptions with Elements that sounds like it covers what you're trying to do.
When you're working with Stripe Billing (Subscriptions and Invoices) you rarely need to interact with the underlying Payment Intents; those are an implementation detail inside of each Invoice.

Implementing SCA into Stripe implementation

I've making a SaaS that allows customers to subscribe to a plan, and use coupons at the checkout stage. The coupons give the customers X% off for X months, and by default, everyone gets a 7 day trial when they subscribe.
What is confusing me is the documentation. In one section it says that you should create SetupIntents to take a payment and elsewhere it says to use tokens.
I'm in the middle of coding the payment flow, but I just wanted to check to see if my logic and understanding is correct. Could anyone validate the below?
Customer enters card number and coupon
Call Stripe, get token for card
Send token and coupon to server
Create Stripe customer with token
Create Subscription with discount and pass customer ID
What has now happened is an authorisation attempt was made. If SCA is required, then the subscription status is incomplete and the latest invoice payment intent status requires action.
At this point, I can redirect my user to the SCA Flow using handleCardPayment() to prompt 3DS, and once complete the subscription status is then active.
If the invoice payment fails for any reason, then the subscription state is incomplete and the payment intent requires has a payment action required status. At this point, I should present my customer with the React Elements form again, and call the stripe.invoices.pay endpoint with the new card token
Going forwards, all subscription charges should not need further SCA approval, however if the customer changes plan or the bank requests it, then I can point my user back through the SCA Flow process
A diagram of the flow is here: Green is UI, Orange is Server, Blue is Stripe
Is there anything I have missed or misunderstood here? I've been reading about creating SetupIntents and PaymentIntents, but I'm not sure I need this?
If you are creating subscriptions using the Stripe Billing product they handle creating the PaymentIntent(if you are taking a payment immediately) or a SetupIntent (if you are setting up a trial or metered billing). All that you really have to do different is handleCardPayment (for payments) or handleCardSetup (for setting up trials and metered billing). This section in the docs is pretty good.
If you are not using billing they have a video on their Stripe Developers Youtube channel which may help clear up any confusion.
Hope this helps :)
Welcome fellow sufferer, cards and tokens are implemented in Stripe Charges API which is not SCA compilant. If you want use Stripe for payments inside the EU you should use payment intents.
Card tokens are also allowed for creating payment intents.
But if you want reduce the number of necessary authentications you should use setup intents (with usage = "off-session") for creating payment methods and not card tokens.
I have a lot of old customers who have still registered with the Charges API. I use the following strategy:
New customers always register via Setup Intents and Payment Methods.
Old customers use the Charges API until their tokens become invalid. Then they must also use setup intents and payment methods.
Of course, the customers do not notice much of it.
In summary, I would always use payment methods and setup intents for new customers and card updates. Only with the setup intents can you ensure that your customers have to authenticate themselves as rarely as possible.
EDIT: The crucial point is off-session payments that occur with subscriptions. The Stripe procedure is described here: https://stripe.com/docs/payments/cards/saving-cards#saving-card-without-payment

Stripe Xamarin. in app, Sign up and pay subscriptions plan, Can it be done?

I been working on a app where the common user can subscribe to different plans, which give different perks.
I been trying to do this by using Stripe's payment component from xamarin component store
But for me, it seems like this component only give you the option to request a payment, but not subscript to a plan.
this leave me think, the only way i can make this happen, is to make the whole "payment and subscriptions to the plan" code on native IOS and Android, which i after bind up against my PCL
So to conclude what i'm looking for is a more simple way to create this functionality,
Thanks for your time,
So the Xamarin extension should really only be used to collect the credit card details and "tokenize" the card. The actual handling of the charge is done by your backend server (as described in the documentation for the extension under "Sending the token to your server"). Once you pass the otken to your backend, you can actually do anything you like with it-- including attach it to a Customer Record by setting the source-attribute when calling the Create a Customer API Endpoint. Once you've created the Customer record, you can then create a Subscription using your Plans.

Resources