Skip to main content
Using Pipedream to automate purchase price updates
Michiel Sikkes avatar
Written by Michiel Sikkes
Updated over 2 years ago

This article explains how to use webhooks and the developer integration service Pipedream to automate calculating and updating the purchase price for assets assigned to subscriptions. The assigned purchase price is then used when offering a purchase flow, for example in a try and buy setup.

Create an empty Pipedream workflow configured as HTTP / Webhooks Requests

First, in Pipedream we're going to create a placeholder workflow that has its own URL to receive webhook requests on. Later we will be adding steps to this workflow which will calculate the purchase price and which will set the purchase price on the specific asset.

Steps:

  1. In Pipedream, click New to create a new workflow.

  2. On the right, choose New HTTP / Webhook Requests from the list of presets.

  3. On the top-left name your workflow from Untitled workflow to Asset Purchase Price Updater.

  4. Click Save and continue.

You should now have a new empty Pipedream workflow created that is hosted on on its own unique URL with something like https://xxx.m.pipedream.net/.

Create two Firmhouse webhooks on asset assigning and invoice creation

Now that we have the empty Pipedream workflow placeholder on a URL, we can configure webhooks in Firmhouse and point them to Pipedream. We are going to create two webhooks: one for when an asset is assigned to a (new) customer. And one when a customer is charged for their periodic invoice.

First we'll create the webhook that gets triggered when assigning an asset to a subscription.

Steps

  1. In Firmhouse, navigate to Apps in the sidebar.

  2. Find the Webhooks app and click Configure.

  3. Click New outgoing webhook on the top-right.

  4. Enter a name for the webhook, such as Asset purchase - Asset assigned

  5. In the Endpoint url field enter the URL obtained from creating the Pipedream workflow in the previous section of this guide.

  6. Leave Authentication type on None.

  7. From the Event dropdown, choose Asset assigned.

  8. In the Template field, paste the following snippet:

    {
    "invoicesCount": {{subscription.initial_or_recurring_invoices_count}},
    "assetOwnershipIds": {{subscription.not_purchased_asset_ownership_ids | split:',' | join: ", "}},
    "event": "asset_assigned"
    }

  9. Click Save to save the outgoing webhook.

Now repeat the above steps to create the second invoice invoiced webhook and change the following fields:

  • Enter a Name for the webhook: Asset purchase - Invoice invoiced

  • From the Event dropdown, choose Invoice invoiced.

Keep Authentication type, and the Template the same as for the Asset assigned webhook.

Add a price calculation step to the workflow in Pipedream

We will now return to the Pipedream workflow from the previous step. We're going to add the create the where we will calculate the purchase price for the customer to purchase their asset.

Steps

  1. In Pipedream, open your workflow, and click Edit on the top-right if you're not in the Edit mode from the previous steps anymore.

  2. Click the little [+] button to add a new step.

  3. In the Add a step, choose the Node item

  4. In the next step, choose Run Node code option.

  5. In the new code editor clear out what is currently there and paste in the contents from the following link: https://raw.githubusercontent.com/firmhouse/pipedream-actions/main/asset_purchase/calculate_asset_purchase_price_from_map.js:

  6. Click Test to save the code and continue configuring your pricing.

  7. In the new configuration pane set RecurringInvoicesCount to {{steps.trigger.event.body.invoicesCount}}.

  8. In the PricesMap field modify the mapping between the number of months and which purchase price you would like to offer. There is already a default mapping with 5 months in there. You can choose to update the prices, or add or remove months. The highest value will always be picked as purchase price in case the customer's trial month exceeds what you've set up here.

  9. Press Test again to save the changes.

Now you've set up a basic price calculation step based on a mapping between the number of months – or recurring invoices – and the purchase price. If you would like to have a different way of calculating the purchase price. You could do this by building custom logic instead of this standard step.

We now need to set up the workflow to save the calculated purchase price on the customer's asset.

Add a price updating step to the workflow in Pipedream

We're going to add another step to the Pipedream workflow. In this step the Firmhouse API is called and the purchase price is updated on the relationship between the asset and the subscriber.

Steps

  1. In Pipedream, open your workflow, and click Edit on the top-right if you're not in the Edit mode from the previous steps anymore.

  2. Click the little [+] button to add a new step.

  3. In the Add a step, choose the Node item

  4. In the next step, choose Run Node code option.

  5. In the new code editor clear out what is currently there and paste in the contents from the following link: https://raw.githubusercontent.com/firmhouse/pipedream-actions/main/asset_purchase/set_asset_purchase_price.js.

  6. Click Test to save the code and continue configuring this step.

  7. In the new configuration pane set FirmhouseProjectAccessToken to an Access Token with Write access type that you can generate in your Firmhouse project under Settings > Integrations.

  8. Leave the FirmhouseApiUrl field as is.

  9. Set PurchasePriceCents to {{steps.node.purchasePriceCents}}

  10. Set AssetOwnershipId to {{steps.trigger.event.body.assetOwnershipIds[0]}}

  11. Click Save to store and test the configuration.

    At this point it's possible that you get several error messages. This is because you saved and tested the steps in this workflow manually and important variables that would normally come in via the webhook are missing.

  12. On the top-right in the Pipedream workflow editor click Deploy and confirm the dialog that warns for errors.

Let's now test the automation with a real webhook to ensure everything works and get rid of the errors.

Test and confirm the automation

It is now time to test and confirm the whole price updating setup.

Steps

  1. Create an asset for the product you want to offer a purchase flow for.

  2. Perform a checkout of your product as you normally would so you have a test customer to work with.

  3. Head over to the new test customer in the Firmhouse portal and assign the customer the asset you just created.

  4. Head over to the workflow in Pipedream to see if the webhook you created earlier triggered an execution:

  5. If everything went fine there should be a task execution with a green checkmark. If you see a task execution with a red exclamation mark icon, something is probably not yet correctly set up in the workflow.
    If you don't see any task execution it might be the webhook you created in the beginnen of this guide is not enabled or not set up correctly. In any case, reach out to our support if you need help!

  6. If everything went well, you should see the new purchase price visible in the assets overview on the customer:

Did this answer your question?