/starling-sweeper

💰 Sweep your Starling balance to a savings goal when you get paid.

Primary LanguageGoMIT LicenseMIT

Starling Sweeper

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.

How it works

  1. Starling Bank triggers a webhook on each transaction.
  2. This webhook is configured to POST the transaction data to this application running on Azure Functions.
  3. 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.

Examples

Above Threshold

Balance: £200
Threshold: £2000
Incoming payment: £2100
Result: £200 tranferred to goal.
Balance after: £2100

Below Threshold

Balance: £200
Threshold: £2000
Incoming payment: £1700
Result: No transfer
Balance after: £1900

Overdrawn

Balance: (£100)
Threshold: £2000
Incoming payment: £2300
Result: No transfer
Balance after: £2200

Installation

Pre-Requisites

Configuring Your App

  • 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]

      1. Publish: Code
      2. Runtime stack: Custom Handler
      3. Version: custom

      [Hosting]

      1. Operating System: Linux
      2. Plan type: Consumption (Serverless)

    ... or ...

  • 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 into main.

Local Development and Testing

Similar Projects