When managing subscriptions, manually handling the renewal process is daunting for an organization. What if you forget your renewal? It can definitely impact your organization resulting in service disruptions and financial penalties.
You might have already heard of several instances where organizations forget their domain renewal, resulting in service outages that cost them millions.
Automating your subscription renewal process is the only way to overcome such scenarios. An orchestration engine like Orkes Conductor can be leveraged to automate your subscription workflows. Orkes Conductor is an app-building platform built over Netflix Conductor.
In this blog, let’s look at how to build a sample subscription application for managing monthly subscriptions using Conductor and Java Spring Boot 2.
The code used to define this application is available on Github here: https://github.com/conductor-sdk/orkes-java-springboot2-subscription-example
Suppose the business logic for your monthly subscription workflow is as follows:
Let’s visualize the workflow:
You need to provide the following input parameters while running the workflow.
Let’s see how the workflow progress:
{
"name": "send-subscription-demo-email",
"taskReferenceName": "send_welcome_email",
"inputParameters": {
"emailSubject": "Welcome to the subscription!",
"emailContent": "Some email content welcoming user to subscription",
"userEmail": "${workflow.input.userEmail}",
"userId": "${workflow.input.userId}"
},
"type": "SIMPLE",
},
The second fork waits for the signal if the user cancels. To pass the signal, we have leveraged Webhook in this example. A webhook is configured with the following parameters:
For this example, we have already created a webhook in Developer Edition.
In the WAIT_FOR_WEBHOOK task in the workflow definition, the input matches are defined as:
"inputParameters": {
"matches": {
"$['event']['userId']": "${workflow.input.userId}"
}
},
Hence the sample webhook invocation using cURL looks like this:
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-H 'subscriptionflow: subscription-flow-header-unique-value' \
-X POST 'https://developer.orkescloud.com/webhook/ba70ba33-1a19-449e-98c2-d4581fcd9aad' \
-d '{"event": {"userId" : "user-id-1"}}'
It includes the headers keys and value (same as configured in the webhook), the webhook URL & the input parameter “userId”, which should be the same as the workflow input you’ve provided.
You can use the webhook we created in Developer Edition to run this example. In case you are using another custom webhook, be sure to replace the webhook URL while invoking. Under application.properties in your spring boot project, too, you need to update the webhook URL.
The code used to define this application is available on Github here: https://github.com/conductor-sdk/orkes-java-springboot2-subscription-example
To run this app locally:
orkes.access.key=your_key_id
orkes.access.secret=your_key_secret
orkes.conductor.server.url=https://developer.orkescloud.com/api.
You also need to provide permissions for the application to access the workflow and tasks.
Note: If you are running Conductor locally, replace orkes.conductor.server.url with your Conductor server URL.
mvn spring-boot:run
This application has a controller that is exposed in SubscriptionApiController.java and has the following API methods:
Now you’ve got an understanding of the subscription workflow. Since you have configured and run your Spring Boot app, let’s run the workflow now!
{
"userId": "",
"userEmail": "",
"billingPeriods": "",
"billingAmount": ""
}
A successful execution looks like this in case if the user hasn’t canceled:
If the subscription is canceled by the user (a signal is received via Webhook), the execution looks like this:
We built a visualized flow that can manage subscriptions effectively and even included handling a trial period! 🥂
Try building the application from scratch, and reach out to us for any queries.
Meanwhile, explore other Conductor features through Orkes Developer Edition, a free dedicated developer sandbox for you to try out Conductor in real-time.
If you enjoy building applications with Conductor, don’t forget to give us a star on our Conductor repo. ⭐⭐⭐