The simplest way to run hyperswitch locally is with Docker Compose by pulling the latest images from Docker Hub. However, if you're willing to modify the code and run it, or are a developer contributing to hyperswitch, then you can either set up a development environment using Docker Compose, or set up a Rust environment on your system.
Check the Table Of Contents to jump to the relevant section.
Table Of Contents:
- Run hyperswitch using Docker Compose
- Set up a development environment using Docker Compose
- Set up a Nix development environment
- Set up a Rust environment and other dependencies
- Try out our APIs
-
Install Docker Compose.
-
Clone the repository and switch to the project directory:
git clone --depth 1 --branch latest https://github.com/juspay/hyperswitch cd hyperswitch
-
(Optional) Configure the application using the
config/docker_compose.toml
file. The provided configuration should work as is. If you do update thedocker_compose.toml
file, ensure to also update the corresponding values in thedocker-compose.yml
file. -
Start all the services using Docker Compose:
docker compose up -d
This should run the hyperswitch app server, web client and control center. Wait for the
migration_runner
container to finish installingdiesel_cli
and running migrations (approximately 2 minutes), and for thehyperswitch-web
container to finish compiling before proceeding further. You can also choose to run the scheduler and monitoring services in addition to the app server, web client and control center. -
Verify that the server is up and running by hitting the health endpoint:
curl --head --request GET 'http://localhost:8080/health'
If the command returned a
200 OK
status code, proceed with trying out our APIs.
The default behaviour for docker compose only runs the following services:
- postgres
- redis (standalone)
- hyperswitch server
- hyperswitch control center
- hyperswitch web sdk
You can run the scheduler, data and monitoring services by specifying suitable profile names to the above Docker Compose command. To understand more about the hyperswitch architecture and the components involved, check out the architecture document.
-
To run the scheduler components (consumer and producer), you can specify
--profile scheduler
:docker compose --profile scheduler up -d
-
To run the monitoring services (Grafana, Promtail, Loki, Prometheus and Tempo), you can specify
--profile monitoring
:docker compose --profile monitoring up -d
You can then access Grafana at
http://localhost:3000
and view application logs using the "Explore" tab, select Loki as the data source, and select the container to query logs from. -
To run the data services (Clickhouse, Kafka and Opensearch) you can specify the
olap
profiledocker compose --profile olap up -d
You can read more about using the data services here
-
You can also specify multiple profile names by specifying the
--profile
flag multiple times. To run both the scheduler components and monitoring services, the Docker Compose command would be:docker compose --profile scheduler --profile monitoring up -d
Once the services have been confirmed to be up and running, you can proceed with trying out our APIs
-
Install Docker Compose.
-
Clone the repository and switch to the project directory:
git clone https://github.com/juspay/hyperswitch cd hyperswitch
-
(Optional) Configure the application using the
config/docker_compose.toml
file. The provided configuration should work as is. If you do update thedocker_compose.toml
file, ensure to also update the corresponding values in thedocker-compose.yml
file. -
Start all the services using Docker Compose:
docker compose --file docker-compose-development.yml up -d
This will compile the payments router, the primary component within hyperswitch and then start it. Depending on the specifications of your machine, compilation can take around 15 minutes.
-
(Optional) You can also choose to start the scheduler and/or monitoring services in addition to the payments router.
-
Verify that the server is up and running by hitting the health endpoint:
curl --head --request GET 'http://localhost:8080/health'
If the command returned a
200 OK
status code, proceed with trying out our APIs.
A Nix development environment simplifies the setup of required project dependencies. This is available for MacOS, Linux and WSL2 users.
We recommend that you install Nix using the DetSys nix-installer, which automatically enables flakes.
As an optional next step, if you are interested in using Nix to manage your dotfiles and local packages, you can setup nixos-unified-template.
Once Nix is installed, you can use it to manage external services via flakes
. More services will be added soon.
-
Run below command in hyperswitch directory
nix run .#ext-services
This will start the following services using process-compose
- PostgreSQL
- Creates database and an user to be used by the application
- Redis
Nix development environment ensures all the required project dependencies, including both the tools and services are readily available, eliminating the need for manual setup.
Run below command in hyperswitch directory
nix develop
NOTE: This is a work in progress, and only a selected commands are available at the moment. Look in flake.nix
(hyperswitch-shell) for a full list of packages.
If you are using nix
, please skip the setup dependencies step and jump to
Set up the database.
This section of the guide provides instructions to install dependencies on Ubuntu-based systems. If you're running another Linux distribution, install the corresponding packages for your distribution and follow along.
-
Install the stable Rust toolchain using
rustup
:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
When prompted, proceed with the
default
profile, which installs the stable toolchain.Optionally, verify that the Rust compiler and
cargo
are successfully installed:rustc --version
Be careful when running shell scripts downloaded from the Internet. We only suggest running this script as there seems to be no
rustup
package available in the Ubuntu package repository. -
Install PostgreSQL and start the
postgresql
systemd service:sudo apt update sudo apt install postgresql postgresql-contrib libpq-dev systemctl start postgresql.service
If you're running any other distribution than Ubuntu, you can follow the installation instructions on the PostgreSQL documentation website to set up PostgreSQL on your system.
-
Install Redis and start the
redis
systemd service:sudo apt install redis-server systemctl start redis.service
If you're running a distribution other than Ubuntu, you can follow the installation instructions on the Redis website to set up Redis on your system.
-
Install
diesel_cli
usingcargo
:cargo install diesel_cli --no-default-features --features postgres
-
Make sure your system has the
pkg-config
package and OpenSSL installedsudo apt install pkg-config libssl-dev
Once you're done with setting up the dependencies, proceed with setting up the database.
This section of the guide provides instructions to install dependencies on Ubuntu on WSL2. If you prefer running another Linux distribution, install the corresponding packages for your distribution and follow along.
-
Install Ubuntu on WSL:
wsl --install -d Ubuntu
Refer to the official installation docs for more information. Launch the WSL instance and set up your username and password. The following steps assume that you are running the commands within the WSL shell environment.
Note that a
SIGKILL
error may occur when compiling certain crates if WSL is unable to use sufficient memory. It may be necessary to allow up to 24GB of memory, but your mileage may vary. You may increase the amount of memory WSL can use via a.wslconfig
file in your Windows user folder, or by creating a swap file in WSL itself. Refer to the WSL configuration documentation for more information. -
Install the stable Rust toolchain using
rustup
:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
When prompted, proceed with the
default
profile, which installs the stable toolchain.Optionally, verify that the Rust compiler and
cargo
are successfully installed:rustc --version
Be careful when running shell scripts downloaded from the Internet. We only suggest running this script as there seems to be no
rustup
package available in the Ubuntu package repository. -
Install PostgreSQL and start the
postgresql
service:sudo apt update sudo apt install postgresql postgresql-contrib libpq-dev sudo service postgresql start
For more information, refer to the docs for installing PostgreSQL on WSL. If you're running any other distribution than Ubuntu, you can follow the installation instructions on the PostgreSQL documentation website to set up PostgreSQL on your system.
-
Install Redis and start the
redis-server
service:sudo apt install redis-server sudo service redis-server start
For more information, refer to the docs for installing Redis on WSL. If you're running a distribution other than Ubuntu, you can follow the installation instructions on the Redis website to set up Redis on your system.
-
Make sure your system has the packages necessary for compiling Rust code:
sudo apt install build-essential
-
Install
diesel_cli
usingcargo
:cargo install diesel_cli --no-default-features --features postgres
-
Make sure your system has the
pkg-config
package and OpenSSL installed:sudo apt install pkg-config libssl-dev
Once you're done with setting up the dependencies, proceed with setting up the database.
We'll be using winget
in this section of the guide, where possible.
You can opt to use your favorite package manager instead.
-
Install PostgreSQL database, following the official installation docs.
-
Install Redis, following the official installation docs.
-
Install rust with
winget
:winget install -e --id Rustlang.Rust.GNU
-
Install
diesel_cli
usingcargo
:cargo install diesel_cli --no-default-features --features postgres
-
Install OpenSSL with
winget
:winget install openssl
Once you're done with setting up the dependencies, proceed with setting up the database.
We'll be using Homebrew in this section of the guide. You can opt to use your favorite package manager instead.
-
Install the stable Rust toolchain using
rustup
:brew install rustup rustup default stable
Optionally, verify that the Rust compiler and
cargo
are successfully installed:rustc --version
-
Install PostgreSQL and start the
postgresql
service:brew install postgresql@14 brew services start postgresql@14
If a
postgres
database user was not already created, you may have to create one:createuser -s postgres
-
Install Redis and start the
redis
service:brew install redis brew services start redis
-
Install
diesel_cli
usingcargo
:cargo install diesel_cli --no-default-features --features postgres
If linking
diesel_cli
fails due to missinglibpq
(if the error message is along the lines ofcannot find -lpq
), you may also have to installlibpq
and reinstalldiesel_cli
:brew install libpq export PQ_LIB_DIR="$(brew --prefix libpq)/lib" cargo install diesel_cli --no-default-features --features postgres
You may also choose to persist the value of
PQ_LIB_DIR
in your shell startup file like so:echo 'PQ_LIB_DIR="$(brew --prefix libpq)/lib"' >> ~/.zshrc
-
Install a command runner called
just
:In order to make running migrations easier, you can use a command runner called just
cargo install just
Once you're done with setting up the dependencies, proceed with setting up the database.
-
Create the database and database users, modifying the database user credentials and database name as required.
export DB_USER="db_user" export DB_PASS="db_pass" export DB_NAME="hyperswitch_db"
On Ubuntu-based systems (also applicable for Ubuntu on WSL2):
sudo -u postgres psql -e -c \ "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;" sudo -u postgres psql -e -c \ "CREATE DATABASE $DB_NAME;"
On MacOS:
psql -e -U postgres -c \ "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;" psql -e -U postgres -c \ "CREATE DATABASE $DB_NAME"
-
Clone the repository and switch to the project directory:
git clone https://github.com/juspay/hyperswitch cd hyperswitch
-
Run database migrations:
Export the
DATABASE_URL
env variableexport DATABASE_URL=postgres://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME
Run the migrations
- If you have just installed
just migrate
- Using the diesel-cli command
diesel migration run
Once you're done with setting up the database, proceed with configuring the application.
The application configuration files are present under the
config
directory.
The configuration file read varies with the environment:
- Development:
config/development.toml
- Sandbox:
config/sandbox.toml
- Production:
config/production.toml
Refer to config.example.toml
for all the available
configuration options.
Refer to development.toml
for the recommended defaults for
local development.
Ensure to update the development.toml
file if you opted
to use different database credentials as compared to the sample ones included in
this guide.
Once you're done with configuring the application, proceed with running the application.
-
Compile and run the application using
cargo
:cargo run
If you are using
nix
, you can compile and run the application usingnix
:nix run
-
Verify that the server is up and running by hitting the health endpoint:
curl --head --request GET 'http://localhost:8080/health'
If the command returned a
200 OK
status code, proceed with trying out our APIs.
-
Sign up or sign in to Postman.
-
Open our Postman collection and switch to the "Variables" tab. Update the value under the "current value" column for the
baseUrl
variable to have the hostname and port of the locally running server (http://localhost:8080
by default). -
While on the "Variables" tab, add the admin API key you configured in the application configuration under the "current value" column for the
admin_api_key
variable.- If you're running Docker Compose, you can find the configuration file at
config/docker_compose.toml
, search foradmin_api_key
to find the admin API key. - If you set up the dependencies locally, you can find the configuration
file at
config/development.toml
, search foradmin_api_key
to find the admin API key
- If you're running Docker Compose, you can find the configuration file at
-
Open the "Quick Start" folder in the collection.
-
Open the "Merchant Account - Create" request, switch to the "Body" tab and update any request parameters as required.
- If you want to use a different connector for making payments with
than the provided default, update the
data
field present in therouting_algorithm
field to your liking.
Click on the "Send" button to create a merchant account (You may need to "create a fork" to fork this collection to your own workspace to send a request). You should obtain a response containing most of the data included in the request, along with some additional fields. Store the merchant ID and publishable key returned in the response.
- If you want to use a different connector for making payments with
than the provided default, update the
- Open the "API Key - Create" request, switch to the "Body" tab and update any request parameters as required. Click on the "Send" button to create an API key. You should obtain a response containing the data included in the request, along with the plaintext API key. Store the API key returned in the response securely.
-
Sign up on the payment connector's (say Stripe, Adyen, etc.) dashboard and store your connector API key (and any other necessary secrets) securely.
-
Open the "Payment Connector - Create" request, switch to the "Body" tab and update any request parameters as required.
- Pay special attention to the
connector_name
andconnector_account_details
fields and update them. You can find connector-specific details to be included in this spreadsheet. - Open the "Variables" tab in the
Postman collection and set the
connector_api_key
variable to your connector's API key.
Click on the "Send" button to create a payment connector account. You should obtain a response containing most of the data included in the request, along with some additional fields.
- Pay special attention to the
-
Follow the above steps if you'd like to add more payment connector accounts.
Ensure that you have set up your merchant account and set up at least one payment connector account before trying to create a payment.
-
Open the "Payments - Create" request, switch to the "Body" tab and update any request parameters as required. Click on the "Send" button to create a payment. If all goes well and you had provided the correct connector credentials, the payment should be created successfully. You should see the
status
field of the response body having a value ofsucceeded
in this case.- If the
status
of the payment created wasrequires_confirmation
, setconfirm
totrue
in the request body and send the request again.
- If the
-
Open the "Payments - Retrieve" request and click on the "Send" button (without modifying anything). This should return the payment object for the payment created in Step 2.
- Open the "Refunds - Create" request in the
"Quick Start" folder folder and switch to the "Body" tab.
Update the amount to be refunded, if required, and click on the "Send" button.
This should create a refund against the last payment made for the specified
amount.
Check the
status
field of the response body to verify that the refund hasn't failed. - Open the "Refunds - Retrieve" request and switch to the
"Params" tab.
Set the
id
path variable in the "Path Variables" table to therefund_id
value returned in the response during the previous step. This should return the refund object for the refund created in the previous step.
That's it! Hope you got a hang of our APIs. To explore more of our APIs, please check the remaining folders in the Postman collection.