This repository currently contains:
- Payment processing services
- Payout services
- Payout splitting (affiliates, vendors, platform) and accounting services
- Double-entry accounting between transactions and payouts.
Variant of this with escrow used in https://gunmarketplace.com.au/
Run:
git clone https://github.com/peitalin/gm-payment-service
cd ./gm-payment-service
cargo build
Stripe frontends require HTTPS (ssl), meaning the connection to backed also needs SSL enabled. This is required for local development.
Run to make SSL certs, then move them:
mkcert -install;
mkcert localhost 127.0.0.1 0.0.0.0
mv localhost+2-key.pem keys/mkcert/localhost-key.pem
mv localhost+2.pem keys/mkcert/localhost.pem
- Required for Stripe requests
- These are fake self-signed certs just for development purposes
- You need a proper SSL cert (fileworks.net cert) to deploy
Once SSL is enabled you can run the payment service locally:
cargo run --bin payment
Build the docker image with this command:
docker build -f ./Dockerfile -t gcr.io/fileworks/gm-payment-service:latest .
Run the docker image:
docker run -p 8898:8898 \
-e JWT_DOMAIN="127.0.0.1" \
gcr.io/fileworks/gm-payment-service
- PS: If using SSL locally, You need to set
-e JWT_DOMAIN="127.0.0.1"
for local development to get 'set-cookies' credentials to work. - HttpOnly cookies will not be set if there is domain mismatch, it's automatically set.
Then push to Google Container Registry
docker push gcr.io/fileworks/gm-payment-service:latest
To remove old containers and images, try:
### Remove images
docker rmi <image-id>
docker rm <container-id>
docker image prune
### Stop and remove all containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
-
If there are dangling/detached containers, use
sudo kill $(lsof -t -i:8082)
which will kill the process hogging port 8082 (if it is runnning in the background).
The top level directory is organized as follows:
- Cargo.toml contains dependencies + commands
├── "Cargo.toml"
├── "Dockerfile"
├── "README.md"
├── "diesel.toml" // set source for schema
├── "keys"
├── "migrations"
├── "src"
│ ├── "bin" // Where the main src code lives
│ ├── "db"
│ ├── "lib.rs"
│ └── "utils"
-
src/bin/payment
is where the main src code resides. -
The other folders in
src
are helper functions (lib.rs
). Modules in thesrc/bin/payment
folder can accesslib.rs
byuse gm::utils
.
The src/bin/payment/main.rs
file is the entry point for the service, which you build and execute with cargo run --bin payment
.
"src/bin/"
└── "payment"
├── "db/" // Postgres and redis actors + message handlers
├── "main.rs"
├── "models/" // structs and user models
└── "rest/" // handlers for each REST endpoint
-
If you want access to functions exposed in the top-level library (
./src/lib.rs
), you canuse gm::MODULENAME
-
The
main.rs
file runs a server, which routes requests to "actors" that handle and process requests (e.g. db, graphql, login, etc). See: https://actix.rs/.
-
3a. Actors handles async event loops, and queues messages to be dispatched to db, websocket, and graphql services.
-
3b. Actors all implement the
Actor
trait (how and when the actor starts and stops etc), andHandler<Message>
trait (how it handles specificMessages
).