Skip to content

MarinX/kit-payment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Payment service with go-kit

Build Status Go Report Card GoDoc License MIT

Getting started

Building

Clone the repo

git clone https://github.com/MarinX/kit-payment

Fetch dependencies

go get ./...

Build as any other go project

go build

Usage

Usage of ./kit-payment:
  -http.addr string
        HTTP listen address (default ":8080")

Storage

Kit-payment is using embedded key/value database called boltdb.

Endpoints

Accounts

Creating account

curl -H "Content-Type: application/json" -X POST http://localhost:8080/accounts

Listing accounts

curl -H "Content-Type: application/json" -X GET http://localhost:8080/accounts

Adding balance to account

Example addding $100 to account id 3479d3a8-42c4-4b40-8a1d-1b1661d7b6ef

curl -d '{"currency":"USD", "amount":100}' -H "Content-Type: application/json" -X POST http://localhost:8080/accounts/3479d3a8-42c4-4b40-8a1d-1b1661d7b6ef/balances

Transactions

List Transactions

curl -H "Content-Type: application/json" -X GET http://localhost:8080/transactions

Creating Transaction

Example of moving $50 from account 3479d3a8-42c4-4b40-8a1d-1b1661d7b6ef to account 06e39e77-776a-4694-bc59-fea69bc8afd8

curl -d '{"from":"3479d3a8-42c4-4b40-8a1d-1b1661d7b6ef", "to":"06e39e77-776a-4694-bc59-fea69bc8afd8", "currency":"USD", "amount":50}' -H "Content-Type: application/json" -X POST http://localhost:8080/transactions

If success, it will return a created transaction object

{"transaction":{"id":"fecf39a1-c4f2-4706-8eca-bc71f310eeb6","from":"3479d3a8-42c4-4b40-8a1d-1b1661d7b6ef","to":"06e39e77-776a-4694-bc59-fea69bc8afd8","status":"created","amount":50,"currency":"USD"}}

Get Transaction

Example of getting single transaction by id fecf39a1-c4f2-4706-8eca-bc71f310eeb6

curl -H "Content-Type: application/json" -X GET http://localhost:8080/transactions/fecf39a1-c4f2-4706-8eca-bc71f310eeb6

Commit Transaction

Once the transaction is created, you need to commit. Example is commiting created transaction fecf39a1-c4f2-4706-8eca-bc71f310eeb6

curl -H "Content-Type: application/json" -X PUT http://localhost:8080/transactions/fecf39a1-c4f2-4706-8eca-bc71f310eeb6/commit

Now you can check the status with Get Transaction method. If account has enough balance, you will see the change on amount when listing accounts.

Transaction verification

It provides a interface for merkle tree so we can check if all transactions are verified. Example of checking our last transaction fecf39a1-c4f2-4706-8eca-bc71f310eeb6

curl -H "Content-Type: application/json" -X GET http://localhost:8080/transactions/fecf39a1-c4f2-4706-8eca-bc71f310eeb6/hash

will return the hash for verification

{"hash":"fdf227bade5496e59824a4c9ef59ec992c61b4521fe0003c5be4d79cec3c885c"}

Tests

Nothing fancy, just run

go test -v ./...

Roadmap

  • Support currency conversion
  • Support user accounts
  • Integrate merkle tree so we can verify transactions and extend (mining?)

PR's welcome :)

About

A go-kit microservice payment system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages