A company wants to give out promo codes worth x amount during events so people can get free rides to and from the event. The flaw with that is people can use the promo codes without going to the event. The Promocode API can be used to
- Generate new promocodes
- Get generated promocodes
- Validate promocodes
Promocodes is only valid when user’s pickup or destination is within x radius of the event venue. The promocode radius and expiry date is configurable.
This API is built with Laravel 7.x
Composer
PHP >= 7.2.5
MySQL
- Clone the repository with
git clone https://github.com/mangya/promocodes.git <your_project_folder_name>
- Change directory to your project folder
cd <your_project_folder_name>
- Install the dependencies with
composer install
- Create database in MySQL.
- Update the your database name and credentials in the
.env
file. - Create database tables and sample data with
php artisan migrate:refresh --seed
- Run the application with
php artisan server
(MySQL service should be up and running). - Access
http://localhost:8000
and you're ready to go!
- Sanctum — Laravel Sanctum provides a authentication system for token based APIs.
All API requests require the use of a bearer roken in the Authorization header.
POST /api/get-access-token
Parameter | Type | Description |
---|---|---|
email |
string |
Required. Your Email |
password |
string |
Required. Your Password |
device_name |
string |
Required. Your Device Name (Any String) |
POST /api/promocodes/generate
Parameter | Type | Description |
---|---|---|
discount |
integer |
Required. Discount in % |
max_discount |
integer |
Required. Maximum discount limit |
validity_radius |
integer |
Required. Promocode valid in radius |
validity_radius_unit |
string |
Required. "kms" OR "miles" |
expires_in |
integer |
Required. Expires in days |
POST /api/promocodes/validate
Parameter | Type | Description |
---|---|---|
origin_lat |
integer |
Required. Origin Latitude |
origin_lng |
integer |
Required. Origin Longitude |
dest_lat |
integer |
Required. Destination Latitude |
dest_lng |
string |
Required. Destination longitude |
promocode |
integer |
Required. Promocode to be applied |
POST /api/promocodes/get
Parameter | Type | Description |
---|---|---|
active |
integer |
(Optional). 1 to retrieve active promocodes |
All enpoints returns a JSON response in the following format:
{
"message" : string,
"status" : string,
"data" : array
}
The message
attribute contains a message commonly used to indicate descrption of errors
The status
attribute describes if the transaction was successful or not. Values will be 'success' OR 'error'
The data
attribute contains any other metadata associated with the response.
Thank you 😊