Using subscriptions
How to enable and configure subscriptions
You can enable subscriptions for any Adobe Commerce product from the product configuration page. When creating or editing a product, scroll down until you see the Stripe Subscriptions section:
Here, you have the following options:
- Subscription Enabled: Turn this on to convert this product into a subscription.
- Frequency: Select Days, Weeks, Months, or Years. The customer frontend displays whatever you select here for the frequency. If you prefer to display 30 Days instead of 1 Month, set this to Days instead. If you select Days, the subscription is also created in days in your Stripe account.
- Repeat Every: This number determines the length of the billing cycle for a subscription using the frequency defined above. For example, if you selected Days for the Frequency setting, billing occurs every 30 days.
- Trial Days: Enter the number of days before the first charge for the subscription (that is, the number of free days).
- Initial Fee: Enter an amount to charge in addition to the subscription price.
You don’t need to create a subscription plan in your Stripe account. A subscription plan is automatically created for this product when your customers check out.
Additional configuration
You can configure additional settings in the Payment Methods section of the Adobe Commerce admin panel.
Shipping Cost: You can configure the shipping cost to create only one charge (when the customer places the order), or on a recurring basis. If you charge on a recurring basis, it’s added to the subscription invoice for every billing period, as shown below:
Viewing or canceling subscriptions
When customers navigate to their account, they can view their purchased subscriptions by clicking the My Subscriptions link on the sidebar:
Customers can view or cancel their subscriptions and edit their shipping address from here. When they edit their shipping address, it doesn’t affect the original order, it only affects the metadata on the actual subscription.
Creating recurring subscription orders using Stripe webhooks
When you create a subscription, Stripe attempts to charge the customer automatically on every billing cycle. On payment success, your website receives a webhook notification from Stripe. The module automatically creates a new order in your Adobe Commerce admin panel for each subscription invoice. These recurring orders don’t include the initial subscription fees, and the module recalculates the shipping and tax amounts for each individual recurring subscription product.
Changing a customer’s subscription
You can increase or reduce the subscription price for a specific product, or change the shipping cost, product name, or tax rates of an order. To do so, you must migrate existing subscriptions from an old plan to a new one using a CLI command within the Stripe module.
php bin/magento stripe:subscriptions:migrate-subscription-price <original_product_id> <new_product_id> [<starting_order_id> [<ending_order_id>]]
This creates a new order for new_product_id
as if the customer placed the order during checkout. The billing and shipping details are the same as the initial order, and it uses the same payment method for the subscription.
The module recalculates the order totals based on the new tax rules, shipping method, price changes, and so on. If the original order had any discounts, they also apply to the new order. The total doesn’t include any of the initial fees.
Successfully placing the order cancels the original order, including the original_product_id
. The module adds a comment to the original order mentioning the migration to a new order, and the cancellation of the associated subscription in Stripe. The customer also receives a new order email that tells them their subscription billing details have changed. They can review the new totals in the same email.
If the module can’t place the order for any reason, the built-in rollback system cancels the new order creation and leaves the original order intact.
You can use the original_product_id
as the new_product_id
, which means that the module only recalculates the order totals. It’s possible to migrate from simple subscription products (physical products with a single SKU) to virtual subscription products, but not the other way around. This limitation is because physical products require a shipping address but virtual products don’t.
The order ID parameters are optional. If they’re not specified, the script processes all orders in your website from all store views and all Stripe modes. If you have multiple Stripe accounts configured, the script migrates subscriptions from all Stripe accounts.
Migrate Stripe Subscriptions from another platform to Adobe Commerce
To migrate subscriptions from another platform, you need to perform the following tasks:
- Create a mapping between your Adobe Commerce customer IDs and the Stripe customer IDs in the “stripe_customers” database table of Adobe Commerce. You can do this with the following SQL statement in your database:
INSERT INTO stripe_customers(customer_id, stripe_id, customer_email) VALUES ('2', 'cus_xxxxxxxxxx', 'janedoe@example.com');
- Create and configure all subscription products for old orders from the Subscriptions by Stripe tab under each product’s configuration page:
- Migrate the orders from your old platform to Adobe Commerce. If you plan on creating these manually from the Adobe Commerce admin area, you can use the Check / Money Order payment method so it doesn’t collect a live payment. After you finish the order migration, you can then replace this payment method with Stripe using the following SQL command:
UPDATE sales_order_payment SET method='stripe_payments' WHERE method='checkmo';
- After creating the orders and products successfully in Adobe Commerce, update the existing Subscriptions in your Stripe account to set the following metadata:
A helper is available to perform this update for you. From your Adobe Commerce directory:
php bin/magento stripe:subscriptions:migrate-stripe-subscriptions
- Test the creation of recurring orders based on subscription renewals:
- Check that you have at least one configured webhook in your Stripe dashboard under Developers > Webhooks.
- From your Stripe Events section, locate an event that you want to test. The event type must be
invoice.payment_succeeded
and the Invoice must belong to a Subscription. - From your Magento root directory, trigger the event with the following command:
bin/magento stripe:webhooks:process-event <event_id>
. - Make sure there were no errors in the console and that the module created a recurring subscription order in Adobe Commerce.