This application allows you to "sweep" the balance in your account as the time of receiving an inbound faster payment or Nostro deposit to a savings goal.
I run this as an Azure Function but thanks to the way they run, this can be run independently standalone anywhere without any tie-in to the likes of AWS Lamba.
- Starling Bank triggers a webhook on each transaction.
- This webhook is configured to POST the transaction data to this application running on Azure Functions.
- The application...
- checks the signature of the request,
- checks the transaction UID and if it's not the transaction we swept last,
- checks the amount is greater than a set threshold,
- checks balance from prior to the incoming,
- and then sends a request back to Starling Bank to move the original balance to a savings goal.
Balance: £200
Threshold: £2000
Incoming payment: £2100
Result: £200 tranferred to goal.
Balance after: £2100
Balance: £200
Threshold: £2000
Incoming payment: £1700
Result: No transfer
Balance after: £1900
Balance: (£100)
Threshold: £2000
Incoming payment: £2300
Result: No transfer
Balance after: £2200
- A Starling Bank account.
- A Starling Bank Developer account.
- An Azure account.
- A Redis database. I use a free account from Redis as it's cheaper than Azure.
-
Create your function app:
-
in the Azure portal:
How to set up a custom handler Azure Function
Start by searching for Function App in the Azure Portal and click Create. The important settings for this are below, other settings you can use default or your own preferences.
[Basic]
- Publish: Code
- Runtime stack: Custom Handler
- Version: custom
[Hosting]
- Operating System: Linux
- Plan type: Consumption (Serverless)
... or ...
- in VSCode
-
-
As we're shipping an executable, you will need to use a Azure Service Principal for RBAC for the deployment credentials. Follow these instructions.
-
Register an application with your Starling developer account.
-
Create a personal webhook using the URL from when you created your function app above.
-
Make a note of the webhook secret and the personal access token.
-
Set the following keys under Settings > Configuration > Application Settings for your function app:
WEBHOOK_SECRET
- used to validate inbound requests.PERSONAL_ACCESS_TOKEN
- used to request transfers to savings goal.SWEEP_GOAL
- the target savings goal for sweeps.SWEEP_THRESHOLD
- the threshold, in pence, for incoming payments to trigger a sweep.ACCOUNT_UID
- the identifier of the Starling account on which you want this to run.REDIS_URL
- the URL for the Redis database you want to use.FUNCTION_APP
- the name of your Azure Function app. You should probably use the Key Vault for all secrets to be extra safe.
-
Deploy the application, either using VSCode or via GitHub Actions by pushing to
main
or merging a pull request intomain
.
- Configure your environment
- Save the above settings to a
.env
file. You can also add these to alocal.settings.json
file by pulling them from Azure and later push push these to Azure when you deploy from VSCode. Don't commit either of these files to your repo unless you really don't like your money. - Start the application:
make start
.
- Starling Roundup (for AWS) - the origin of the fork of this fork.
- Starling CoinJar