Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fabric.properties

### dotenv ###
.env
.oneclick-setup.env

### Linux ###
*~
Expand All @@ -145,7 +146,6 @@ fabric.properties
# Icon must end with two \r
Icon


# Thumbnails
._*

Expand Down
66 changes: 47 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
prestart-hook:
image: curlimages/curl-base:latest
container_name: prestart-hook
environment:
- ONE_CLICK_SETUP=${ONE_CLICK_SETUP:-false}
entrypoint:
[
"/bin/sh",
Expand All @@ -29,7 +31,7 @@ services:
networks:
- router_net
volumes:
- pg_data:/VAR/LIB/POSTGRESQL/DATA
- pg_data:/var/lib/postgresql/data
environment:
- POSTGRES_USER=db_user
- POSTGRES_PASSWORD=db_pass
Expand Down Expand Up @@ -108,23 +110,6 @@ services:
start_period: 5s
timeout: 5s

poststart-hook:
image: curlimages/curl-base:latest
container_name: poststart-hook
depends_on:
hyperswitch-server:
condition: service_healthy # Ensures it only starts when `hyperswitch-server` is healthy
entrypoint:
[
"/bin/sh",
"-c",
"apk add --no-cache bash jq && /bin/bash /poststart_hook.sh",
]
volumes:
- ./scripts/poststart_hook.sh:/poststart_hook.sh
networks:
- router_net

hyperswitch-producer:
image: docker.juspay.io/juspaydotin/hyperswitch-producer:standalone
pull_policy: always
Expand Down Expand Up @@ -223,6 +208,49 @@ services:
labels:
logs: "promtail"

create-default-user:
image: curlimages/curl-base:latest
container_name: create-default-user
depends_on:
hyperswitch-server:
condition: service_healthy
hyperswitch-control-center:
condition: service_started
environment:
- HYPERSWITCH_SERVER_URL=http://hyperswitch-server:8080
- HYPERSWITCH_CONTROL_CENTER_URL=http://hyperswitch-control-center:9000
entrypoint:
[
"/bin/sh",
"-c",
"apk add --no-cache bash jq && /bin/bash /create_default_user.sh",
]
volumes:
- ./scripts/create_default_user.sh:/create_default_user.sh
networks:
- router_net

poststart-hook:
image: curlimages/curl-base:latest
container_name: poststart-hook
depends_on:
create-default-user:
condition: service_completed_successfully
hyperswitch-server:
condition: service_healthy # Ensures it only starts when `hyperswitch-server` is healthy
environment:
- ONE_CLICK_SETUP=${ONE_CLICK_SETUP:-false}
entrypoint:
[
"/bin/sh",
"-c",
"apk add --no-cache bash jq && /bin/bash /poststart_hook.sh",
]
volumes:
- ./scripts/poststart_hook.sh:/poststart_hook.sh
networks:
- router_net

### Clustered Redis setup
redis-cluster:
image: redis:7
Expand Down Expand Up @@ -476,4 +504,4 @@ services:
- HYPERSWITCH_CLIENT_URL=http://localhost:9050
- HYPERSWITCH_SERVER_URL=http://localhost:8080
labels:
logs: "promtail"
logs: "promtail"
138 changes: 138 additions & 0 deletions scripts/create_default_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#! /usr/bin/env bash
EMAIL="[email protected]"
PASSWORD="Hyperswitch@123"
# Initialize merchant_id and profile_id to empty strings
merchant_id=""
profile_id=""

# Test the health endpoint first to ensure the API is responsive
health_response=$(curl -s -w "\\nStatus_Code:%{http_code}" "${HYPERSWITCH_SERVER_URL}/health")
health_status_code=$(echo "${health_response}" | grep "Status_Code:" | cut -d':' -f2)
health_response_body=$(echo "${health_response}" | head -n1)

# Try signin first
signin_payload="{\"email\":\"${EMAIL}\",\"password\":\"${PASSWORD}\"}"
signin_response=$(curl -s -X POST -H "Content-Type: application/json" -H "api-key: hyperswitch" -H "User-Agent: HyperSwitch-Shell-Client/1.0" -H "Referer: ${HYPERSWITCH_CONTROL_CENTER_URL}/" -d "${signin_payload}" "${HYPERSWITCH_SERVER_URL}/user/signin")

# Check if user needs to be created
if [[ $(
echo "${signin_response}" | grep -q "error"
echo $?
) -eq 0 ]]; then
# User doesn't exist or login failed, create new account
signup_payload="{\"email\":\"${EMAIL}\",\"password\":\"${PASSWORD}\",\"country\":\"IN\"}"

# Only try signing up once - using exact headers from browser
# For making signup request without verbose logging
signup_cmd="curl -s -X POST '${HYPERSWITCH_SERVER_URL}/user/signup' \
-H 'Accept: */*' \
-H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \
-H 'Content-Type: application/json' \
-H 'Origin: ${HYPERSWITCH_CONTROL_CENTER_URL}' \
-H 'Referer: ${HYPERSWITCH_CONTROL_CENTER_URL}/' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36' \
-H 'api-key: hyperswitch' \
-d '${signup_payload}'"

signup_response=$(eval "${signup_cmd}")

# Extract token from signup response
token=$(echo "${signup_response}" | grep -o '"token":"[^"]*"' | cut -d'"' -f4)
token_type=$(echo "${signup_response}" | grep -o '"token_type":"[^"]*"' | cut -d'"' -f4)
is_new_user=true
else
auth_response="${signin_response}"
token=$(echo "${auth_response}" | grep -o '"token":"[^"]*"' | cut -d'"' -f4)
token_type=$(echo "${auth_response}" | grep -o '"token_type":"[^"]*"' | cut -d'"' -f4)
is_new_user=false
fi

# Handle 2FA if needed
if [ "${token_type}" = "totp" ]; then
MAX_RETRIES=3
for i in $(seq 1 ${MAX_RETRIES}); do
terminate_response=$(curl -s -X GET -H "Content-Type: application/json" -H "api-key: hyperswitch" -H "authorization: Bearer ${token}" "${HYPERSWITCH_SERVER_URL}/user/2fa/terminate?skip_two_factor_auth=true")

new_token=$(echo "${terminate_response}" | grep -o '"token":"[^"]*"' | cut -d'"' -f4)
if [ -n "${new_token}" ]; then
token="${new_token}"
break
else
if [ $i -lt ${MAX_RETRIES} ]; then
sleep 1
fi
fi
done
fi

# Get user info
if [ -n "${token}" ]; then
user_info_cmd="curl -s -X GET -H 'Content-Type: application/json' -H 'api-key: hyperswitch' -H 'authorization: Bearer ${token}' '${HYPERSWITCH_SERVER_URL}/user'"
user_info=$(eval "${user_info_cmd}")
else
user_info="{}"
fi

merchant_id=$(echo "${user_info}" | grep -o '"merchant_id":"[^"]*"' | cut -d'"' -f4 || echo "")
profile_id=$(echo "${user_info}" | grep -o '"profile_id":"[^"]*"' | cut -d'"' -f4 || echo "")

# Configure account for new users
if [ "${is_new_user}" = true ] && [ -n "${merchant_id}" ] && [ -n "${token}" ]; then
# Create merchant account
merchant_payload="{\"merchant_id\":\"${merchant_id}\",\"merchant_name\":\"Test\"}"
merchant_response=$(curl -s -X POST -H "Content-Type: application/json" -H "api-key: hyperswitch" -H "authorization: Bearer ${token}" -d "${merchant_payload}" "${HYPERSWITCH_SERVER_URL}/accounts/${merchant_id}")

# Configure connector
connector_payload=$(
cat <<EOF
{
"connector_type": "payment_processor",
"profile_id": "${profile_id}",
"connector_name": "paypal_test",
"connector_label": "paypal_test_default",
"disabled": false,
"test_mode": true,
"payment_methods_enabled": [
{
"payment_method": "card",
"payment_method_types": [
{
"payment_method_type": "debit",
"card_networks": [
"Mastercard"
],
"minimum_amount": 0,
"maximum_amount": 68607706,
"recurring_enabled": true,
"installment_payment_enabled": false
},
{
"payment_method_type": "credit",
"card_networks": [
"Visa"
],
"minimum_amount": 0,
"maximum_amount": 68607706,
"recurring_enabled": true,
"installment_payment_enabled": false
}
]
}
],
"metadata": {},
"connector_account_details": {
"api_key": "test_key",
"auth_type": "HeaderKey"
},
"status": "active"
}
EOF
)
connector_response=$(curl -s -X POST -H "Content-Type: application/json" -H "api-key: hyperswitch" -H "authorization: Bearer ${token}" -d "${connector_payload}" "${HYPERSWITCH_SERVER_URL}/account/${merchant_id}/connectors")

# Silently check if configuration was successful without printing messages
if [ -z "$(echo "${merchant_response}" | grep -o 'merchant_id')" ] || [ -z "$(echo "${connector_response}" | grep -o 'connector_id')" ]; then
# Only log to debug log if we want to troubleshoot later
: # No-op command
fi
fi
24 changes: 24 additions & 0 deletions scripts/notify_scarf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env bash
set -euo pipefail

# Define the URL and parameters
SCARF_URL="https://hyperswitch.gateway.scarf.sh/docker"
VERSION=$1
INSTALLATION_STATUS=$2

CURL_COMMAND=("curl" "--get" "${SCARF_URL}" "--data-urlencode" "${VERSION}" "--data-urlencode" "${INSTALLATION_STATUS}")

# Calculate number of arguments and process remaining args (if any)
if [ $# -gt 2 ]; then
# Starting from the 3rd argument (index 2 in $@)
for param in "${@:3}"; do
CURL_COMMAND+=("--data-urlencode" "${param}")
done
fi

# Execute the curl command
echo "Executing: ${CURL_COMMAND[@]}"
"${CURL_COMMAND[@]}"

# Print confirmation
echo "Request sent to ${SCARF_URL} with ${VERSION} and ${INSTALLATION_STATUS}"
34 changes: 21 additions & 13 deletions scripts/poststart_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ STATUS=""
SERVER_BASE_URL="http://hyperswitch-server:8080"
HYPERSWITCH_HEALTH_URL="${SERVER_BASE_URL}/health"
HYPERSWITCH_DEEP_HEALTH_URL="${SERVER_BASE_URL}/health/ready"
WEBHOOK_URL="https://hyperswitch.gateway.scarf.sh/docker"
ONE_CLICK_SETUP="${ONE_CLICK_SETUP:-false}"

if [[ "${ONE_CLICK_SETUP}" == "true" ]]; then
SCARF_URL="https://hyperswitch.gateway.scarf.sh/docker"
else
SCARF_URL="https://hyperswitch.gateway.scarf.sh/only-docker"
fi

# Fetch health status
echo "Fetching app server health status..."
HEALTH_RESPONSE=$(curl --silent --fail "${HYPERSWITCH_HEALTH_URL}") || HEALTH_RESPONSE="connection_error"

if [[ "${HEALTH_RESPONSE}" == "connection_error" ]]; then
STATUS="error"
ERROR_MESSAGE="404 response"
ERROR_MESSAGE="500 response"

curl --get "${WEBHOOK_URL}" \
curl --get "${SCARF_URL}" \
--data-urlencode "version=${VERSION}" \
--data-urlencode "status=${STATUS}" \
--data-urlencode "error_message=${ERROR_MESSAGE}"
--data-urlencode "error_message='${ERROR_MESSAGE}'"

echo "Webhook sent with connection error."
exit 0
Expand All @@ -33,10 +39,10 @@ echo "Fetching Hyperswitch health status..."
HEALTH_RESPONSE=$(curl --silent "${HYPERSWITCH_DEEP_HEALTH_URL}")

# Prepare curl command
CURL_COMMAND=("curl" "--get" "${WEBHOOK_URL}" "--data-urlencode" "version=${VERSION}")
CURL_COMMAND=("curl" "--get" "${SCARF_URL}" "--data-urlencode" "version=${VERSION}")

# Check if the response contains an error
if [[ "$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error')" != 'null' ]]; then
if [[ "$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error')" != "null" ]]; then
STATUS="error"
ERROR_TYPE=$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error.type')
ERROR_MESSAGE=$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error.message')
Expand All @@ -48,17 +54,19 @@ if [[ "$(echo "${HEALTH_RESPONSE}" | jq --raw-output '.error')" != 'null' ]]; th
"--data-urlencode" "error_message='${ERROR_MESSAGE}'"
"--data-urlencode" "error_code='${ERROR_CODE}'"
)
else
"${CURL_COMMAND[@]}"
echo "Webhook sent with error status."
exit 0
elif [[ "${ONE_CLICK_SETUP}" == "false" ]]; then
STATUS="success"
CURL_COMMAND+=("--data-urlencode" "status=${STATUS}")

for key in $(echo "${HEALTH_RESPONSE}" | jq --raw-output 'keys_unsorted[]'); do
value=$(echo "${HEALTH_RESPONSE}" | jq --raw-output --arg key "${key}" '.[$key]')
CURL_COMMAND+=("--data-urlencode" "'${key}=${value}'")
CURL_COMMAND+=("--data-urlencode" "${key}=${value}")
done
"${CURL_COMMAND[@]}"
echo "Webhook notification sent for success status."
else
echo "ONE_CLICK_SETUP=true and status=success, skipping webhook call."
fi

# Send the webhook request
bash -c "${CURL_COMMAND[*]}"

echo "Webhook notification sent."
14 changes: 11 additions & 3 deletions scripts/prestart_hook.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#! /usr/bin/env bash
set -euo pipefail

ONE_CLICK_SETUP="${ONE_CLICK_SETUP:-false}"

# Check if ONE_CLICK_SETUP is set to true; if so, skip execution
if [ "${ONE_CLICK_SETUP}" = "true" ]; then
echo "ONE_CLICK_SETUP is true; skipping script execution."
exit 0
fi

# Define the URL and parameters
WEBHOOK_URL="https://hyperswitch.gateway.scarf.sh/docker"
SCARF_URL="https://hyperswitch.gateway.scarf.sh/only-docker"
VERSION="unknown"
STATUS="initiated"

# Send the GET request
curl --get "${WEBHOOK_URL}" --data-urlencode "version=${VERSION}" --data-urlencode "status=${STATUS}"
curl --get "${SCARF_URL}" --data-urlencode "version=${VERSION}" --data-urlencode "status=${STATUS}"

# Print confirmation
echo "Request sent to ${WEBHOOK_URL} with version=${VERSION} and status=${STATUS}"
echo "Request sent to ${SCARF_URL} with version=${VERSION} and status=${STATUS}"
Loading
Loading