Crates.io | correlate |
lib.rs | correlate |
version | 0.3.0 |
created_at | 2025-05-22 21:53:41.836614+00 |
updated_at | 2025-05-22 21:53:41.836614+00 |
description | correlate is a standalone server that listens for Stripe webhook events and sends notification emails about successful orders. |
homepage | |
repository | https://code.orbitsolutions.dev/orb-it-solutions/correlate.git |
max_upload_size | |
id | 1685671 |
size | 189,667 |
cor·re·late, verb | ˈkôrəˌlāt | to have a mutual relationship or connection, in which one thing affects or depends on another.
Correlate is a service that listens for webhook events and, in response to those events, sends notification emails about orders. It can optionally store order information in a database, allowing you to query and make connections between the data later on (or, one could say correlations). e.g. Which product variant has the most sales? Which day typically has the most sales?
# Clone the repository
git clone https://code.orbitsolutions.dev/orb-it-solutions/correlate.git
cd correlate
# Build the project (with database support enabled by default)
cargo build --release
# Build without database support
cargo build --release --no-default-features
# Run the application
cargo run --release
# Build the Docker image (with database support by default)
docker build -t correlate .
# Build the Docker image without database support
docker build --build-arg WITH_DATABASE=false -t correlate:no-db .
# Run the container with database support
docker run -p 8000:8000 -p 25:25 \
-e CORRELATE_STRIPE_SECRET=your_stripe_secret_key \
-e CORRELATE_EMAIL_SENDER=your_sender_email \
-e CORRELATE_EMAIL_RECIPIENT=your_recipient_email \
-e CORRELATE_PRODUCTS='[{name="Product Name",sku="product-sku",price="price_12345"},{name="Another Product",sku="another-sku",price="price_67890"}]' \
-e CORRELATE_DATABASES={db_name={url="mysql://user:password@hostname:3306/db_name"}} \
correlate
# Run the container without database support
docker run -p 8000:8000 -p 25:25 \
-e CORRELATE_STRIPE_SECRET_KEY=your_stripe_secret_key \
-e CORRELATE_EMAIL_SENDER=your_sender_email \
-e CORRELATE_EMAIL_RECIPIENT=your_recipient_email \
-e CORRELATE_PRODUCTS='[{name="Product Name",sku="product-sku",price="price_12345"},{name="Another Product",sku="another-sku",price="price_67890"}]' \
correlate:no-db
The project uses the following key dependencies:
These dependencies are only required if database integration is enabled:
Feature Flag | Description | Default |
---|---|---|
database |
Enables database integration | Enabled |
To build without database support:
cargo build --no-default-features
To explicitly enable database support:
cargo build --features database
Variable | Description | Default | Required |
---|---|---|---|
CORRELATE_STRIPE_SECRET |
Your Stripe API secret key | - | Yes |
CORRELATE_EMAIL_SENDER |
Email address to send notifications from | - | Yes |
CORRELATE_EMAIL_RECIPIENT |
Email address to send notifications to | - | Yes |
CORRELATE_EMAIL_SMTP_RELAY_HOST |
SMTP server hostname | - | No |
CORRELATE_EMAIL_SMTP_RELAY_PORT |
SMTP server port | 25 | No |
CORRELATE_EMAIL_SMTP_USERNAME |
SMTP username (if authentication required) | - | No |
CORRELATE_EMAIL_SMTP_PASSWORD |
SMTP password (if authentication required) | - | No |
CORRELATE_PRODUCTS |
TOML-formatted array of product variants for checkout (see example below) | - | Yes |
CORRELATE_DATABASES |
MySQL connection string (only needed when database feature is enabled) | - | Only with database feature |
You can also configure the application using a Rocket.toml
file:
[default.stripe]
secret_key = "sk_test_your_test_key"
[default.email]
sender = "noreply@example.com"
recipient = "orders@example.com"
smtp_relay_host = "smtp.example.com"
smtp_relay_port = 2525
smtp_username = "username"
smtp_password = "password"
# Product configuration for checkout session creation
default.products = [
{ name = "Product Name", sku = "product-sku", price = "price_12345" },
{ name = "Another Product", sku = "another-sku", price = "price_67890" }
]
# Only needed when database feature is enabled
[default.databases]
database_name = { url = "mysql://user:password@hostname:3306/database_name" }
https://your-domain.com/
)checkout.session.completed
event to listen forGET /
: Returns application informationPOST /
: Webhook endpoint for Stripe eventsPOST /checkout
: Endpoint to create a new Stripe checkout sessionTo create a new checkout session for payment processing:
Rocket.toml
file or environment variables (see Configuration section)/checkout
endpoint with the following JSON payload:{
"success_url": "https://your-domain.com/success",
"submission_url": "https://your-domain.com/cancel",
"items": [
{
"name": "Product Name",
"sku": "product-sku",
"quantity": 1
}
]
}
Note: The name
and sku
in your request must match entries in your product configuration. The service will use these to find the corresponding Stripe price ID.
When a successful checkout is completed in Stripe, the webhook will:
When the database feature is enabled, the application uses the following tables:
stripe_customers
: Stores customer information from Stripe eventsusers
: Basic user account information (if user accounts are enabled)Note: The database integration is optional. If you don't want to store order information, you can build the application without database support using
--no-default-features
.
To create a local mysql/mariadb database named correlate
you would use diesel to run the commands below:
# Install development dependencies
cargo install diesel_cli --no-default-features --features mysql
# Set up the database
diesel setup --database-url=mysql://root:root@localhost:3306/correlate
diesel migration run
# Set up the database without TLS support
diesel setup --database-url=mysql://root:root@localhost:3306/correlate?ssl_mode=DISABLED
diesel migration run
# Run in development mode with database support
cargo run
If you don't need database integration:
# Run in development mode without database support
cargo run --no-default-features
cargo test
This project is licensed under the MIT License - see the LICENSE file for details.