Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
github.com/febriansr/simple-payment-api
Simple Payment API is a RESTful API application designed to provide various functionalities related to user authentication, payment processing, and session management. The API enables users to perform actions such as login, logout, and make a payment.
This project is built using the following technologies:
To run this project locally, follow these steps:
git clone https://github.com/febriansr/simple-payment-api
cd simple-payment-api
sudo service redis-server start
SERVER_PORT=[ServerPort]
SERVER_HOST=[ServerHost]
JSON_FILE_NAME_CUSTOMER=./data/customer.json
JSON_FILE_NAME_MERCHANT=./data/merchant.json
JSON_FILE_NAME_HISTORY=./data/history.json
ACCESS_TOKEN_LIFETIME=[AccessTokenLifetimeinMinutes]
APPLICATION_NAME=[ApplicationName]
JWT_SIGNATURE_KEY=[SignatureKey]
REDDIS_ADDRESS=[RedisHost]:[RedisPort]
REDDIS_PASSWORD=[RedisPassword]
go run main.go
go test -v ./... -coverprofile=cover.out && go tool cover -html=cover.out
Make sure you have installed Go Lang and Redis on your machine before running the project.
To use the application, you need to login by sending a POST request to the following endpoint:
http://[ServerHost]:[ServerPort]/v1/login/
Include the following JSON request format in the request body:
{
"username": [username],
"password": [password]
}
The password field in the JSON request body should be a plaintext version of the hashed password saved in the customer JSON file. If the request is successful, you will receive the following response:
{
"code": 200,
"message": "Success",
"data": {
"token" : [token]
}
}
If the server is unable to process your request, you will receive an error response with the appropriate error code and message.
To make a payment, send a POST request to the following endpoint:
http://[ServerHost]:[ServerPort]/v1/payment/
Include the access token in the Authorization header of the request and provide the necessary payment details in the request body using the following format:
{
"merchant_code": [merchant code],
"amount": [amount]
}
The amount inputted should be less than or equal to the customer's balance and greater than 0. The token in Authorization should be valid and not expired. The transaction can only be made by registered users to registered merchants. A registered user cannot make a payment for another registered user without changing the token. If the payment request is successful, you will receive a success response. If there is an error, you will receive an appropriate error response.
To logout from the application, send a POST request to the following endpoint:
http://[ServerHost]:[ServerPort]/v1/logout/
Include the access token in the Authorization header of the request. If the logout request is successful, you will receive a success response. If there is an error, you will receive an appropriate error response. If you already logged out, you have to login again to access the application.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.