Ciao! At Routefusion we love programmable money. So today, to start the new year, we are going to do a brief tutorial on how you can create recurring payments using Google Cloud functions and the Routefusion API!This tutorial will assume you already have a GCP account and project setup, with billing attached.It will assume you also have the Gcloud command-line tools installed.It will also assume that you have signed up on Routefusion and copied down your developer keys, created a beneficiary and have that beneficiary_id.
This tutorial will assume a few things:
If you need to create GCP account, you can setup an account here: https://cloud.google.com/, and if you do some searching around you will find out how you can get lots of free credits.
If you need to create a Routefusion account you can sign up here: routefusion.com.
If you need to download gcloud command line tools you can do that here: https://cloud.google.com/sdk/docs/install
Open a terminal, create a new directory called cron-send-payment, and run npm init.
Hit enter through the instructions for npm init, and then check out your file structure.
It should have only created you a package.json
Now create your index.js file
Next, install the routefusion node SDK
The next thing we are going to do is open our favorite code editor and create our Routefusion function. For ease you can just copy the code I wrote ;)
A quick rundown of this function. We are initializing the Routefusion SDK
We then create a cloud function named CreateTransferRoutefusion
We JSON'ify (if thats a word) the data, and create our transfer object. Then we make our recurring payment! Super simple 😉
You will notice that we have environment variables set. With cloud functions all you need to do is create a .env.yaml file in project directory and add in your ENV vars.
Open your editor and paste in the below variables. Be sure to change the credentials to the ones found in your Routefusion developer tab on routefusion.com
For good measure let's create a .gcloudignore.
Open your editor and paste this in .gcloudignore
If you are not familiar with PubSub, take some time and read about it here: https://blog.stackpath.com/pub-sub/
Ok, lets create our topic. Open your terminal and type the following
Wow, that was easy! Now make sure you topic was created
It should give you output that looks like this
Sweet! Now let's create our cloud function.
Similar to creating a topic we use the Gcloud command line tools. Super convinent. You can find a list of all the Gcloud function commands here for reference. https://cloud.google.com/sdk/gcloud/reference/functions/deploy
From your terminal with a working directory inside of your directory we setup earlier run the below command.
After the command runs maker sure it was created by running the below command
Great, now our function has been created! Now for the last part.
For this tutorial we are going to automate the paying of our rent every month. Earlier at the start of the tutorial we mentioned we are assuming you have created a beneficiary. Make sure you have that beneficiary id, and lets get our function live!
From your terminal run the below command.
That command creates a cron job that will publish a message with the transfer details on the first of every month.
Just to double check that it was created lets run the scheduler command
I hope you enjoyed this tutorial. If you want this payment to go live, all you need to do is submit compliance documents on routefusion.com. We will approve your account for production access ASAP. Once you are approved you will link a bank account and everything will just work! How fun is that.
If you have any questions or want to discuss any cool ideas you have for programming money, please email the team at engineering@routefusion.com
We love to chat about all sorts of ideas and problems.
- You already have a GCP account and project setup, with billing attached.
- You also have the Gcloud command-line tools installed.
- You have signed up on Routefusion and copied down your developer keys, created a beneficiary and have that beneficiary_id.
- Payroll & Contractor Payments
- AP/AR & Treasury Management
- Global USDC Funding
