Create subscription system for PayPal course - node.js

I am trying to create a subscription system with PayPal for a user subscribe to a course. So far I have already made the billing agreement and this has no problems, but the problem is that I want each month or each time the subscription is paid, the user is automatically reenrolled, otherwise if it is not possible to charge (maximum 2 attempts) the subscription is canceled and they no longer have access to the course. This last part I have no idea how I could do it, basically I don't know how I can check the status of the agreement and cancel when it is not paid.

The current version of PayPal Subscriptions does not use "billing agreements". If you have integrated with billing agreements, that is the previous version of PayPal Subscriptions and you should discard that deprecated implementation and read the current documentation, which only uses: Products, Plans, and Subscriptions.
(Do not use Billing Agreements, and do not use the deprecated PayPal-Node-SDK. Use the Subscriptions API directly)
To receive notifications of when a Subscription is paid for or its status otherwise changes, integrate Webhooks.
Some other possibly useful information: How do you know if a user has paid for a subscription

Related

How to handle "incomplete" trial subscriptions

We are currently using Stripe to offer a subscription service with 30 days free trial. Since we don't want the customer to be able to start the free trial without authorizing one payment method we use the SetupIntent of the created Subscription to present a card input to our client. Now the issue is that even before the customer is shown the card input the subscription is already created and "paid" for because it is a free trial.
This means that we cannot listen to the initial invoice.paid Webhook to activate the account, but instead need to listen to setup_intent.succeeded. This seems a bit odd and requires us to link the SetupIntent to a Subscription. It also means that when a customer cancels the subscription process before entering their card details, that Stripe still has created an active Subscription in trial.
Is there something we can do differently, or should we just accept that the subscriptions where the SetupIntent was aborted will be inactive on the Stripe side once it tries to pay for the next (non-trial) invoices?
Stripe's docs use the Setup Intent that's created with a trialing Subscription to collect a customer's Payment Method, but for your use case it may make more sense to create your own Setup Intent up front and not create the Subscription unless the Setup Intent it successful. It'd go something like this:
Create the Setup Intent
Confirm the Setup Intent after collecting details
If successful, create the trialing Subscription
Alternatively, you could try using Checkout which does require users to submit a Payment Method even from trialing Subscriptions

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.

How to implement free plans in Stripe

To implement a free plan for a subscription, I have created a plan with a monthly charge of $0.
Is this the correct way to subscribe users to a free plan so that they don't have to pay?
Will users still get invoices when they are subscribed to a free plan? If so, how can I avoid sending invoices to those subscribed to the free plan?
Stripe Subscriptions are designed to manage billing and payments, rather than "tracking who is using a product". An "active" Subscription in Stripe is one that is being paid for, rather than one that is "being actively used".
You could conceivably set up a Subscription with an indefinite free trial, but really, you're doing a bunch of work to keep updating it to "remain free". I'd suggest taking a look at what you are actually trying to accomplish, because you're probably trying to track a user of your services, rather than track that a user doesn't pay you anything.
If you want to track a subscription with a zero plan on Stripe it will of course work. I use zero plans all the time.
All the invoices will be generated each month but will have a zero value which means they will automatically be marked as paid.
Invoice was finalized and automatically marked as paid because the amount due was 0.00kr
I am using custom accounts with custom integration so there is no automatic email going out from stripe for me, but I do receive the entire stack of events like I would any normal invoice which i have to deal with.
The event progression is: Invoice created -> finalized -> paid -> changed. Although instant the webhook events all come in.
There is no issue with zero plans, everything shows up in the Stripe admin and works just like any subscription. You can start out with a free plan and upgrade them later - the payment information is gathered and can be charged later so it is all good.

How should we handle failed credit card payments?

We're just a few weeks away from releasing our custom built SaaS app for Freight Brokers and (eventually) Carriers. We're deciding how to handle failed credit card payments. The options have so far been:
Immediately restrict their account and require a payment. Send them an email saying an Admin can login and restore account access
or
Give them 7 full days to pay(including weekends), send them an email when the payment fails, a day after and 2 days after the second email. Then send them an email when their account access has been restricted. When they login, they can pay, but the payment would include the days used without payment.
I'm leaning towards the second one, because if I were a business owner, i would not want to come in and my employees are sitting because none of them have a company credit card to pay for the software.
Thoughts?
EDIT: Lmao I spelt "handle" wrong in the title... Fixed.
You can configure Stripe Dunning process which facilitates you to handle failed payments in a better way for subscription base billing.
Its basically enabling retry schedule with customize timeframe. you can cancel the subscription or mark the subscription as unpaid after all retry attempts have been exhausted. There is a webhook which indicates the transaction details, using that you can handle your business logic like hold the tenant or delete the tenant.

Migrating stripe subscription to be SCA compliant

I have a subscription, I collect card details on signup with a 7 day trial, after which the subscription bills monthly.
From what I understand the subscription API is not SCA compliant. Instead
An off_session payment Intent must first be setup when collecting card details.
At the end of each month a scheduler must be triggered to attempt to charge the registered card.
Is this the case? Am I now responsible for scheduling payments?
Update
For those who want some starter code, I created a working playground here with subscriptions, frontend (react) and backend (express) on glitch.
It's not true that Stripe's Subscription API is not SCA-ready, it is, and you don't have to set up your own scheduling like that. The docs you linked to are generally aimed at processing one-off payments(like saving a customer's details and then allowing them to use them again when they re-visit your site to purchase something new, for example) as opposed to recurring ones.
https://stripe.com/docs/billing/subscriptions/payment describes how to set up a subscription in a way that is SCA-ready. While the customer is on-session on your payment page, you collect card details and create a subscription for the customer, which will generally attempt a payment for the first billing period. You then check the status of the subscription after it's created, and handle the outcomes:
the subscription is active and the payment was successful, so you can proceed with provisioning your service to the customer.
the subscription is incomplete — for SCA purposes, let's say this is because 3D Secure authentication was required for that first payment. In this case, the latest_invoice of the subscription exposes a PaymentIntent property, and you use that PaymentIntent in conjunction with your frontend code using stripe.js to walk the customer through authenticating the payment, and that activates the subscription.
the subscription is trialing — if the subscription doesn't involve an initial payment, like when using a trial period for example, you can also check if the subscription has a pending_setup_intent. You can use this on your frontend to have the customer complete a 3D Secure authentication, so that future payments(like the first one after the trial) are more likely to successfully claim an exemption and not require having the user authenticate at that point.
You can also instead use Stripe Checkout to easily collect payment details and set up a customer and subscription for you, while also handling any initial authentication that's needed : https://stripe.com/docs/payments/checkout/server#create-subscriptions
As for the recurring payments, Billing can handle that for you. You can configure you settings to automatically email the customer to complete 3D Secure if it's encountered on a recurring payment. So you can absolutely build an SCA-ready solution with the subscriptions API on Stripe.

Resources