- The customer starts with discount code
ORDER2EARNfor 10% off. - After the first confirmed order, the next order gets 20% off.
- After the second confirmed order, the next order gets 30% off.
- After the third order, no more campaign discounts are added.
How it works
Regular discount codes apply one promotion until they expire or hit their limits. To change the discount over time, use a webhook and the GraphQL API:- Firmhouse sends an Order Confirmed webhook.
- Your webhook handler checks whether the subscription used the campaign discount code.
- Your handler fetches the subscription with the GraphQL API.
- Your handler checks which campaign promotions have already been applied.
- Your handler applies the next promotion with
applyPromotionToSubscription.
Requirements
- A project access token with Write access.
- Three promotions in Firmhouse, for example 10%, 20%, and 30%.
- A discount code that applies the first promotion.
- A deployed HTTP endpoint that can receive Firmhouse webhooks.
Create the promotions and discount code
Create three discounts in Firmhouse, for example:- First order discount: 10%
- Second order discount: 20%
- Third order discount: 30%
ORDER2EARN, that applies the first discount.
Configure the webhook payload
Create an Order Confirmed webhook in Firmhouse. Include the subscription token and applied discount codes in the payload.text/plain. If your framework depends on Content-Type to parse JSON automatically, parse the body manually with JSON.parse.
Read the webhook payload
The exact code depends on your runtime. In a JavaScript handler, extract the payload and project access token first.Define the campaign promotions
Collect the promotion IDs in the order they should be applied. You can find a promotion ID in the URL when editing a discount in Firmhouse:Fetch the subscription
Fetch the subscription and its applied promotions withgetSubscription.
Decide whether to apply the next promotion
If one of the campaign promotions is still active, do not apply another promotion.Apply the next promotion
Apply the next promotion withapplyPromotionToSubscription.
Secure the webhook endpoint
Firmhouse supports basic authentication for webhooks. Configure a username and password in the webhook settings, then validate theAuthorization header in your handler.
Test and deploy
- Deploy your webhook endpoint.
- Configure the Firmhouse webhook in Apps > Webhooks.
- Create a subscription using the campaign discount code.
- Complete the first payment so the order is confirmed.
- Check your webhook logs.
- Open the customer in Firmhouse and verify the next discount was applied.
- Deploy the workflow for production events.