Sell products as recurring subscriptions with Stripe
npm install @pinelab/vendure-plugin-stripe-subscription
A channel aware plugin that allows you to sell subscription based services or products through Vendure. This plugin was made in collaboration with the great people at isoutfitters.com.
The default strategy defines subscriptions in the following manner:
You can easily define your own subscriptions with a custom subscription strategy.
vendure-config.ts
plugins and admin UI compilation:Stripe Subscription
as handlerAPI key
. Publishable key
and Webhook secret
can be left empty at first.Webhook secret
field should now have a value. This means webhooks have been created in your Stripe account. If not, check the server logs.previewStripeSubscriptionsForProduct
AddItemToOrder
mutation.createStripeSubscriptionIntent
to receive a client secret.PaymentIntent
or a SetupIntent
.It's important to inform your customers what you will be billing them in the future: https://stripe.com/docs/payments/setup-intents#mandates
You can optionally supply your publishable key in your payment method handler, so that you can retrieve it using the eligiblePaymentMethods
query:
You can define your own subscriptions by implementing the StripeSubscriptionStrategy
:
You can then pass the strategy into the plugin during initialization in vendure-config.ts
:
You can pass custom inputs to your strategy, to change how a subscription is defined, for example by having a selectable start date:
subscriptionStartDate
subscriptionStartDate
to your strategy:subscriptionStartDate
on the order line, so that you can access it in the defineSubscription
method of your strategy:It's possible to define multiple subscriptions per product. For example when you want to support down payments or yearly contributions.
Example: A customer pays $90 a month, but is also required to pay a yearly fee of $150:
OrderItemCalculationStrategy
. The strategy in this plugin is used for calculating the
amount due for a subscription, if the variant is a subscription. For non-subscription variants, Vendure's default
order line calculation is used. Only 1 strategy can be used per Vendure instance, so any other
OrderItemCalculationStrategies are overwritten by this plugin.You can cancel a subscription by canceling the corresponding order line of an order. The subscription will be canceled before the next billing cycle using Stripe's cancel_at_period_end
parameter.
Only initial payments of subscriptions can be refunded. Any future payments should be refunded via the Stripe dashboard.
You can use the payment eligibility checker has-stripe-subscription-products-checker
if you to use a different payment method for orders without subscriptions. The has-stripe-subscription-products-checker
makes your payment method not eligible if it does not contain any subscription products.
The checker is added automatically, you can just select it via the Admin UI when creating or updating a payment method.
You can locally test this plugin by checking out the source.
yarn start
http://localhost:3050/checkout
to view the Stripe checkoutPaymentSettled
in the admin.