This commit is contained in:
2025-02-16 20:18:04 +03:00
parent 09b545bf47
commit 19b8f0716b
4 changed files with 26 additions and 17 deletions

View File

@@ -24,14 +24,14 @@ type PaymentRequest struct {
// Структура для ответа от localhost:5000
type PaymentResponse struct {
Message string `json:"message"`
URL string `json:"url"`
URL string `json:"redir_url"`
}
var db *sql.DB
func initDB() {
var err error
dbFile := "users.db"
dbFile := "urls_pay.db"
db, err = sql.Open("sqlite3", dbFile)
if err != nil {
log.Fatal("Ошибка подключения к базе данных:", err)
@@ -97,7 +97,7 @@ func payHandler(w http.ResponseWriter, r *http.Request) {
}
// Сохраняем данные в базу данных
insertSQL := `INSERT INTO pay_urls (id, url) VALUES (?, ?)`
insertSQL := `INSERT INTO pay_urls (uuid, url) VALUES (?, ?)`
_, err = db.Exec(insertSQL, newUUID, paymentResponse.URL)
if err != nil {
http.Error(w, "Ошибка при сохранении данных в базу данных", http.StatusInternalServerError)
@@ -107,6 +107,12 @@ func payHandler(w http.ResponseWriter, r *http.Request) {
// Формируем ответ клиенту в виде простого текста
response := fmt.Sprintf("UUID: %s\nURL: %s", newUUID, paymentResponse.URL)
// Set uuid cookie
cookie = &http.Cookie{
Name: "uuid",
Value: newUUID,
}
http.SetCookie(w, cookie)
// Отправляем ответ в виде простого текста
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
@@ -179,6 +185,10 @@ func checkPayHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(response))
}
func TestHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, World!"))
}
func main() {
initDB()
@@ -191,6 +201,7 @@ func main() {
)
// Register handlers
http.HandleFunc("/", TestHandler)
http.HandleFunc("/api/pay", payHandler)
http.HandleFunc("api/check_pay", checkPayHandler)

Binary file not shown.