Payment transaction is a Restful API written in Golang, which simulates a purchase made with card and according to certain rules, approve or not approve the financial transaction.
To run this program, you will need to:
$ export GOPATH=$(go env GOPATH)
$ go get github.com/vinixavier/payment_transaction
$ cd $GOPATH/vinixavier/payment_transaction
$ go install
$ $GOPATH/bin/payment_transaction &
Once this is done, the program will listen on localhost:3000
.
To test this program:
$ cd $GOPATH/github.com/vinixavier/payment_transaction
$ go test
To make a payment, use the curl
command or the postman
application to perform a POST for the API.
Example in Linux with the curl
command:
$ curl -X POST -d @examples/input.json http://localhost:3000/payment
{"approved":false,"deniedReasons":["Card is blocked!"]}
See examples of request files in the examples/*.json
directory.
Make a payment.
{
"account": {
"cardIsActive": "Boolean",
"limit": "Number",
"blacklist": [ "String" ],
"isWhitelisted": "Boolean"
},
"transaction": {
"merchant": "String",
"amount": "Number",
"time": "String"
},
"lastTransaction":
[ "<Transaction>" ]
}
}
{
"approved": "Boolean",
"newLimit": "Number",
"deniedReasons": [ "String" ]
}
This API considers the following rules to be applied at the time of the transaction:
- The transaction amount should not be above limit.
- No transaction should be approved when the card is blocked.
- The first transaction shouldn't be above 90% of the limit.
- There should not be more than 10 transactions on the same merchant.
- Merchant blacklist.
- There should not be more than 3 transactions on a 2 minutes interval
- Include
application/json
header. - Include more unit tests.