Generating the subscriptions
How to trigger the subscription generation based on the source order and the subscription model configuration
Last updated
How to trigger the subscription generation based on the source order and the subscription model configuration
Last updated
You have , setting the allowed subscription frequencies and choosing the subscription strategy. You also have containing some line items with frequency from which to start generating the subscriptions and placed it. You now want to trigger the subscription generation.
To start generating the subscription from a placed source order, send a PATCH
request to the /api/orders/:id
endpoint setting the _create_subscriptions
attribute to true
.
The following request generates the subscriptions from the source order identified by the "NgojhelVGm" ID:
For each automatically generated order subscription, some source order information is copied (e.g. addresses, customer payment source, etc.), the related order subscription items are created and associated with the order subscriptions, and the target order is placed at the scheduled time using the saved customer payment source (if still valid).
Which and how many order subscriptions and order subscription items are generated depends on the subscription strategy and source order's line items.
by_frequency
— as many order subscriptions as the different frequencies specified for the source order’s line items are generated, each with the related order subscription items (default strategy).
by_line_items
— an order subscription is generated for any source order’s line item that has a frequency, each with the related order subscription item.
by_frequency
— for each automatically generated order subscription as many order subscription items as the source order’s line items that have that specific frequency are generated.
by_line_items
— for each automatically generated order subscription a single order subscription item is generated.
Let's look at the source order we used throughout this guide:
The following request fetches the source order, requesting some basic fields and including the line items to check their frequency:
As you can see inspecting the above response it contains 4 line items of type skus
for a total of 5 SKUs:
2 SKUs with monthly
frequency (both with quantity 1
— SKU codes LENSPACKL125
and LENSPACKR075
)
1 SKU with weekly
frequency (with quantity 2
and SKU code RAZRFILLPACK4
)
1 SKU with no specified frequency (with quantity 1
and SKU code MUGXXXAUFFFFFF00000011OZ
)
Based on the subscription strategy these are the subscriptions and subscription items that will be generated (remember that line items without frequency don't generate subscriptions):
The generated recurring target orders cannot be used as source orders from which to trigger a new subscription generation.
You can check the generated order subscriptions and related order subscription items in the Subscriptions section of our admin dashboard, or via API by sending a GET
request to the /api/order_subscriptions
endpoint, filtered by the source order ID with order subscription items included (the following request is related to the by_frequency
example above):
The following request fetches all the order subscriptions associated with the customer identified by the "nDNahABVZR" ID and generated by the source order identified by the "NgojhelVGm" ID, including the related order subscription items:
The automatic order subscription generation process is triggered manually by using a specific attribute. The necessary order subscriptions are automatically generated ’s line item for which you’ve specified a frequency, accordingly to the strategy set .
The source order’s customer email is stored, that order is considered the subscription's first run, and the generated order subscriptions are activated (unless differently specified by setting the auto_activate
attribute to true
).
You can track subscriptions' renewal failures by activating a listening for the order_subscriptions.last_run_failed
event and acting accordingly (e.g. setting up an automatic notification system for the customer).
You can notify customers about upcoming recurring orders associated with subscriptions by properly setting the renewal_alert_period
attribute at the order subscription level and leveraging the order_subscriptions.renewal
event that will be fired accordingly.
See our API reference if you need more information on how to and , , , , or about how and work.