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