Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dfbe5da4be |
BIN
backend/api/main
Executable file
BIN
backend/api/main
Executable file
Binary file not shown.
@@ -77,6 +77,7 @@ func initDB() {
|
|||||||
/*----------------------------PAYMENT--------------------------------------*/
|
/*----------------------------PAYMENT--------------------------------------*/
|
||||||
func payHandler(w http.ResponseWriter, r *http.Request) {
|
func payHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
fmt.Println("PAY HERE, BABY!")
|
||||||
// Структура для тела запроса на localhost:5000
|
// Структура для тела запроса на localhost:5000
|
||||||
type PaymentRequest struct {
|
type PaymentRequest struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
@@ -91,6 +92,11 @@ func payHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
cookie, err := r.Cookie("totalPrice")
|
cookie, err := r.Cookie("totalPrice")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Не удалось получить amount из cookies")
|
||||||
|
fmt.Println("\nPrinting all cookies")
|
||||||
|
for _, c := range r.Cookies() {
|
||||||
|
fmt.Println(c)
|
||||||
|
}
|
||||||
http.Error(w, "Не удалось получить amount из cookies", http.StatusBadRequest)
|
http.Error(w, "Не удалось получить amount из cookies", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -98,6 +104,7 @@ func payHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Преобразуем amount из строки в float64
|
// Преобразуем amount из строки в float64
|
||||||
amount, err := strconv.ParseFloat(cookie.Value, 64)
|
amount, err := strconv.ParseFloat(cookie.Value, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Некорректное значение amount в cookies")
|
||||||
http.Error(w, "Некорректное значение amount в cookies", http.StatusBadRequest)
|
http.Error(w, "Некорректное значение amount в cookies", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -113,6 +120,7 @@ func payHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Преобразуем тело запроса в JSON
|
// Преобразуем тело запроса в JSON
|
||||||
requestBody, err := json.Marshal(paymentRequest)
|
requestBody, err := json.Marshal(paymentRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Ошибка при создании запроса")
|
||||||
http.Error(w, "Ошибка при создании запроса", http.StatusInternalServerError)
|
http.Error(w, "Ошибка при создании запроса", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -120,6 +128,7 @@ func payHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Отправляем POST-запрос на localhost:5000
|
// Отправляем POST-запрос на localhost:5000
|
||||||
resp, err := http.Post("http://localhost:5000/pay", "application/json", bytes.NewBuffer(requestBody))
|
resp, err := http.Post("http://localhost:5000/pay", "application/json", bytes.NewBuffer(requestBody))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Ошибка при отправке запроса на сервер")
|
||||||
http.Error(w, "Ошибка при отправке запроса на сервер", http.StatusInternalServerError)
|
http.Error(w, "Ошибка при отправке запроса на сервер", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -128,6 +137,7 @@ func payHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Читаем ответ от сервера
|
// Читаем ответ от сервера
|
||||||
var paymentResponse PaymentResponse
|
var paymentResponse PaymentResponse
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&paymentResponse); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&paymentResponse); err != nil {
|
||||||
|
fmt.Println("Ошибка при чтении ответа от сервера")
|
||||||
http.Error(w, "Ошибка при чтении ответа от сервера", http.StatusInternalServerError)
|
http.Error(w, "Ошибка при чтении ответа от сервера", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user