Selling back-orders by collecting a deposit is a great strategy to not only secure sales that might have been lost, but also get customer committment before sourcing new inventory.
Using the Downpay API and Shopify Flow, we can create a workflow that will allow out-of-stock variants to be sold with a deposit.
We will do this by listening to variant inventory quantity changes, and adding the variant to a deposit purchase option when the inventory hits zero or below.
A second workflow will remove the variants from the same deposit option when the variant comes back in stock.
Below are the links to the two completed flow templates. You can import them into Shopify Flow to start playing around. You will need to edit them to add your Downpay API key in the HTTP action of each flow, as well as change the ID of the deposit purchase option you want to add/remove variants from.
Adding deposits to variants when out of stock
Removing deposits from variants when back in stock
The rest of this tutorial explains in depth how to create your own flow from scratch.
Within the Downpay app, create a purchase option that will be applied to out-of-stock variants. When creating the option, add a variant to it to start, to let Downpay know that this purchase option will be applied to variants henceforth:
![flexli-dev · Downpay · Shopify 2024-02-27 16-44-43](https://private-user-images.githubusercontent.com/209316/308379781-cd3fa95a-4e27-4239-a9ff-09318eca3b98.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAxNzU0NzIsIm5iZiI6MTcyMDE3NTE3MiwicGF0aCI6Ii8yMDkzMTYvMzA4Mzc5NzgxLWNkM2ZhOTVhLTRlMjctNDIzOS1hOWZmLTA5MzE4ZWNhM2I5OC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwNVQxMDI2MTJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jMzUwYTZlMWI0NmVlOGRiZjQyZmQ0YWE2YmUzYjQ1NDQ1NzViN2M5NWM3MTI5YTFmOGQ1ODdkZGJkYmY1ZDU3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.TMlk_cA2ygnb_LYUwxNXpSKUdBDxlPBSNTWec9v5eP4)
After you've created this option, click on it and note the number at the end of the URL in your browser address bar. This is the purchase option ID. We will need that ID later on.
In Shopify Flow, create a new flow. The flow will have three parts:
![add](https://private-user-images.githubusercontent.com/209316/308378439-74381816-b680-4949-b69b-06a63ececd82.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAxNzU0NzIsIm5iZiI6MTcyMDE3NTE3MiwicGF0aCI6Ii8yMDkzMTYvMzA4Mzc4NDM5LTc0MzgxODE2LWI2ODAtNDk0OS1iNjliLTA2YTYzZWNlY2Q4Mi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwNVQxMDI2MTJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wYmYwNzIyNjg0MGI3ZWQxNjRlOWY3ZTJiZWU1NjhhMWZhYWYwODhjNGIwMDk3ZjMyYzk3ZTg4NmY1NTcyMDg3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.q1Y6zUi5L61r5jje6tawZBuC_IvmUuonM2nBp-tHARg)
To kick off the flow, we add a 'Product Variant Inventory Change' trigger. This will run this flow anytime a variant's inventory is changed.
If the inventory changed to zero or below, we will go onto the next step. Otherwise do nothing.
We will call the Downpay API using the Send HTTP request
action, which is found under the Flow set of available actions in Shopify Flow.
There are a few configuration options to enter here:
- HTTP Method: Set to
POST
- URL: Set to
https://downpay.hypehound.app/graphql
For Headers, there are two to set:
- Key:
Content-Type
, value:Application/json
- Key:
Authorization
, Value:Token <your_api_key>
You can find the Downpay API key for your shop inside the Downpay app, under the Settings page.
For the Body field, enter the following:
{
"query": "mutation addVariant($input: PurchaseOptionGroupAddProductVariantsInput!) { purchaseOptionGroupAddProductVariants(input: $input){ errors { field message }}}",
"operationName": "addVariant",
"variables": {
"input": {
"id": "<your_purchase_option_id>",
"productVariantIds": ["{{productVariant.id}}"]
}
}
}
In the above snippet, replace the text "<your_purchase_option_id>" with the ID of the purchase option we created in Downpay earlier.
If you don't want to apply this logic to all the variants in your store, you can add another condition in the middle of the flow, for example to check if a particular tag is applied to a product. That way you can only offer deposits on out-of-stock variants of a particular product type, instead of store-wide.
But we're not done yet! We still need to create a second flow that will do the opposite - remove variants from a purchase option when stock climbs above zero...
To start off, duplicate the flow we just created. You can do this by selecting the flow on the main shopify flow screen. The new flow will be very similar to the first one, it's simply some of the logic that will change. The finished version will look similar to this:
![flexli-dev · Flow · Shopify 2024-02-27 17-08-11](https://private-user-images.githubusercontent.com/209316/308383358-cd061c91-d636-41ff-8565-7bda6e1cd079.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAxNzU0NzIsIm5iZiI6MTcyMDE3NTE3MiwicGF0aCI6Ii8yMDkzMTYvMzA4MzgzMzU4LWNkMDYxYzkxLWQ2MzYtNDFmZi04NTY1LTdiZGE2ZTFjZDA3OS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwNVQxMDI2MTJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wY2EyOTdiMzZlZGU5NDdkMWY2OTAwOWExNTk1NWMyMmI3Yjg4ZWQxYjM1N2U2ZjRjOTU3MTdiODY3NjI1YjE4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.tCLD4N5jbnsc75DPElW0V7kdvcZ7675NnwjJsIuM7g4)
The trigger will remain the same - we want this flow to run whenever variant inventory changes.
The condition will change to only allow execution to proceed if the inventory level is 1 or above.
The action is similar to the previous one, however the body of the API call will change, to the following:
{
"query": "mutation removeVariant($input: PurchaseOptionGroupRemoveProductVariantsInput!) { purchaseOptionGroupRemoveProductVariants(input: $input){ errors { field message }}}",
"operationName": "removeVariant",
"variables": {
"input": {
"id": "<your_purchase_option_id>",
"productVariantIds": ["{{productVariant.id}}"]
}
}
}
Once again, change <your_purchase_option_id> to the ID of the Downpay purchase option created in the first step of the tutorial.
Once you're done editing, make sure both your flows are activated. You can then test things out by adjusting the stock on any variant and seeing the deposit options get enabled/disabled on the storefront product pages as the variants come in and out of stock.
For questions and support, contact us at support@hypehound.io