Сервис Promos #
Сервис Promos служит для централизованного управления (добавления, удаления) Specials и Promocodes. К сервису обращаются через web интерфейс сайта продаж Store и через web административную панель.
Авторизация в сервис Promos #
-
Для авторизации через логин и пароль используется метод signin. Детальнее метод описан в Авторизация пользователя
-
Для авторизации по Токену используется метод authenticate, после того как пользователь прошел signin. Детальнее метод описан в Авторизация пользователя
Закрытые методы сервиса Promos для сущностей Special and Upgrade #
Для сущностей Spacial and Upgrade используется общий API интерфейс.
router.HandleFunc("/get", controllers.GetAllCRUDHandler).Methods("GET") // get all specials or upgrades
router.HandleFunc("/create", controllers.CreateCRUDHandler).Methods("POST") // create special or upgrade
router.HandleFunc("/update", controllers.UpdateCRUDHandler).Methods("PUT") // update special or upgrade
router.HandleFunc("/get/{id}", controllers.CRUDInfoByIDHandler).Methods("GET") // get special or upgrade by id
router.HandleFunc("/delete/{id}", controllers.DeleteCRUDlHandler).Methods("DELETE") // delete special or upgrade
Данные методы находятся в файле controllers/cruds.go
- Для работы со Special в запросе надо отправить параметр с именем module со значением specials
https://host.example/api/update?module=specials
- Для работы с Upgrade в запросе надо отправить параметр с именем module со значением upgrades
https://host.example/api/update?module=upgrades
Закрытые методы сервиса Promos для сущностей promocodes #
promocodes/set - Method “POST” //set promocodes #
REQUEST data → {"discount_percentage": 20, // percent of discount "discount_amount": 0, // amount of discount (either discount_percentage or discount_amount) "usage_count": 4, // how many times you used the discount code "charset": "123456789QWERTYUPASDFGHJKLZXCVBNM", // charset for generation of codes "count": 3, // how many codes you want to generate "expires_in": "2024-12-31", // date of expiration of code "pattern": "############", // pattern of discount code "products": ["SKU12345", "SKU67890"], // products array on which spread discount code "usage_by": "user@example.com" // user who can use this discount code } RESPONSE success→ {"message":"Promocode {name} created.","status":200} errors→ pcgen error → {"error": "Some error", "status":500} authenticate error → {"error": "Auth error", "status":401} other error → {"error": "Some error", "status":400}
promocodes/get - Method “GET” //get all discount codes #
RESPONSE: success → [{"id": 1, // discount code id in database "code": "SUMMER21", // code "discount_percentage": 20, // discount_percentage of code "discount_amount": 0, // discount_amount (if exist discount_percentage then discount_amount =0 and vice versa) "usage_count": 5, // how many times you used the discount code "usage_by": "user@example.com", // user who can use this discount code "products": ["SKU12345", "SKU67890"], // products array on which spread discount code "expires_in": "2024-12-31", // date of expiration of code "created": "2024-01-01", // when the discount code was created "created_unix": 1672531200, // Unix time when discount code was created "pattern": "############", // pattern of code "charset": "123456789QWERTYUPASDFGHJKLZXCVBNM", // charset of code "count": 100 // how many codes were generated },] errors→ database error → {"error": "Some error", "status":500} authenticate error → {"error": "Auth error", "status":401} other error → {"error": "Some error", "status":400}
promocodes/get/{limitin}/{limitout} - Method “GET” //gets discount codes limited #
{limitin} - from (default 0), {limitout} - to (default 100000)
RESPONSE success → [{"id": 1, // discount code id in database "code": "SUMMER21", // code "discount_percentage": 20, // discount_percentage of code "discount_amount": 0, // discount_amount (if exist discount_percentage then discount_amount =0 and vice versa) "usage_count": 5, // how many times you used the discount code "usage_by": "user@example.com", // {user_email} - user who can use this discount code "products": ["SKU12345", "SKU67890"], // ["SKU of product"] - products array on which spread discount code "expires_in": "2024-12-31", // date of expiration of code "created": "2024-01-01", // when the discount code was created "created_unix": 1672531200, // Unix time when discount code was created "pattern": "############", // pattern of code "charset": "123456789QWERTYUPASDFGHJKLZXCVBNM", // charset of code "count": 100 // how many codes were generated },] errors → database error → {"error": "Some error", "status":500} authenticate error → {"error": "Auth error", "status":401} other error → {"error": "Some error", "status":400}
promocodes/get/{search}{limitin}/{limitout} - Method “GET” get promocodes by search template with limits #
{search} - search template, {limitin} - from (default 0), {limitout} - to (default 100000)
RESPONSE success → [{"id": 1, // discount code id in database "code": "SUMMER21", // code "discount_percentage": 20, // discount_percentage of code "discount_amount": 0, // discount_amount (if exist discount_percentage then discount_amount =0 and vice versa) "usage_count": 5, // how many times you used the discount code "usage_by": "user@example.com", // user who can use this discount code "products": ["SKU12345", "SKU67890"], // products array on which spread discount code "expires_in": "2024-12-31", // date of expiration of code "created": "2024-01-01", // when the discount code was created "created_unix": 1672531200, // Unix time when discount code was created "pattern": "############", // pattern of code "charset": "123456789QWERTYUPASDFGHJKLZXCVBNM", // charset of code "count": 100 // how many codes were generated },] errors → database error - {"error": "Some error", "status":500} authenticate error - {"error": "Auth error", "status":401} other error- {"error": "Some error", "status":400}
promocodes/get/{search} - Method “GET” //get promocode by search template #
{search} - search template
RESPONSE success → [{"id": 1, // discount code id in database "code": "SUMMER21", // code "discount_percentage": 20, // discount_percentage of code "discount_amount": 0, // discount_amount (if exist discount_percentage then discount_amount = 0 and vice versa) "usage_count": 5, // how many times you used the discount code "usage_by": "user@example.com", // user who can use this discount code "products": ["SKU12345", "SKU67890"], // products array on which spread discount code "expires_in": "2024-12-31", // date of expiration of code "created": "2024-01-01", // when the discount code was created "created_unix": 1672531200, // Unix time when discount code was created "pattern": "############", // pattern of code "charset": "123456789QWERTYUPASDFGHJKLZXCVBNM", // charset of code "count": 100 // how many codes were generated },] errors → database error - {"error": "Some error", "status":500} authenticate error - {"error": "Auth error", "status":401} other errors- {"error": "Some error", "status":400}
promocodes/getusedby - Method “GET” returns all discount codes that are linked to the email of the user #
RESPONSE: success → [{"id": 1, // discount code id in database "code": "SUMMER21", // code "discount_percentage": 20, // discount_percentage of code "discount_amount": 0, // discount_amount (if exist discount_percentage then discount_amount = 0 and vice versa) "usage_count": 5, // how many times you used the discount code "usage_by": "user@example.com", // user who can use this discount code (will definitely not be empty) "products": ["SKU12345", "SKU67890"], // products array on which spread discount code "expires_in": "2024-12-31", // date of expiration of code "created": "2024-01-01", // when the discount code was created "created_unix": 1672531200, // Unix time when discount code was created "pattern": "############", // pattern of code "charset": "123456789QWERTYUPASDFGHJKLZXCVBNM", // charset of code "count": 100 // how many codes were generated },] errors→ database error - {"error": "Some error", "status":500} authenticate error - {"error": "Auth error", "status":401} other errors- {"error": "Some error", "status":400}
promocodes/getdiscountpercentage - Method “GET” //returns all discount codes that have discount percent #
RESPONSE: success → [{"id": 1, // discount code id in database "code": "SUMMER21", // code "discount_percentage": 20, // discount_percentage of code (will not be empty) "discount_amount": 0, // discount_amount (discount_amount = 0) "usage_count": 5, // how many times you used the discount code "usage_by": "user@example.com", // user who can use this discount code "products": ["SKU12345", "SKU67890"], // products array on which spread discount code "expires_in": "2024-12-31", // date of expiration of code "created": "2024-01-01", // when the discount code was created "created_unix": 1672531200, // Unix time when discount code was created "pattern": "############", // pattern of code "charset": "123456789QWERTYUPASDFGHJKLZXCVBNM", // charset of code "count": 100 // how many codes were generated },] errors→ database error - {"error": "Some error", "status":500} authenticate error - {"error": "Auth error", "status":401} other errors- {"error": "Some error", "status":400}
promocodes/del/{id} - Method “GET” //delete promocode by id #
{id} - is the "code" field in the promocodes structure - for example "code":"SUMMER21"
RESPONSE success → {"message":"Promocodes deleted.","status":200} errors → database error - {"error": "Some error", "status":500} authenticate error - {"error": "Auth error", "status":401} other errors- {"error": "Some error", "status":400}
Открытые методы сервиса Promos #
router.HandleFunc("/special/{sku}", controllers.SpecialInfoBySkuHandler).Methods("GET")
router.HandleFunc("/upgrade-program", controllers.GetActualUpgradesHandler).Methods("GET")
router.HandleFunc("/promocode/upgrade-program", controllers.CreatePromocodeUpgradeProgramHandler).Methods("POST")
Данный метод находится в файле controllers/public.go
promocodes/getbycode/{id} - Method “GET“ //get promocode by id #
{id} - is the "code" field in the promocodes structure - for example "code":"SUMMER21"
RESPONSE success → {"id": 1, // discount code id in database "code": "SUMMER21", // code "discount_percentage": 20, // discount_percentage of code "discount_amount": 0, // discount_amount (if exist discount_percentage then discount_amount = 0 and vice versa) "usage_count": 5, // how many times you used the discount code "usage_by": "user@example.com", // user who can use this discount code "products": ["SKU12345", "SKU67890"], // products array on which spread discount code "expires_in": "2024-12-31", // date of expiration of code "created": "2024-01-01", // when the discount code was created "created_unix": 1672531200, // Unix time when discount code was created "pattern": "############", // pattern of code "charset": "123456789QWERTYUPASDFGHJKLZXCVBNM", // charset of code "count": 100 // how many codes were generated } errors → database error - {"error": "Some error", "status":500} authenticate error - {"error": "Auth error", "status":401} other errors- {"error": "Some error", "status":400}
promocodes/decrement/{id} - Method “GET“ decrement promocode by id #
{id} - is the "code" field in the promocodes structure - for example "code":"SUMMER21"
RESPONSE success → {"message":"Promocode {code} decremented.","status":200} errors → database error - {"error": "Some error", "status":500} authenticate error - {"error": "Auth error", "status":401} other errors- {"error": "Some error", "status":400}
Зависимости сервиса Promos #
Promos обменявается данными со следующими сервисами:
Права доступа к сервису Promos #
-
ADMIN и SALES - Имеют полный доступ ко всем функциям сервиса Promos.
-
ВСЕ (даже не зарегистрованные пользователи) - Могут получать информации о Specials и Promocodes через методы /special/ и /promocodes/getbycode/.