diff --git a/not_sorted/url_for_pay_example b/not_sorted/url_for_pay_example new file mode 100755 index 00000000..179f01cf Binary files /dev/null and b/not_sorted/url_for_pay_example differ diff --git a/not_sorted/url_for_pay_example.go b/not_sorted/url_for_pay_example.go new file mode 100644 index 00000000..0eba506f --- /dev/null +++ b/not_sorted/url_for_pay_example.go @@ -0,0 +1,55 @@ +package main + +import ( + "fmt" + "net/http" + "net/url" +) + +func Pay(sum float64) string{ + // Базовый URL + baseURL := "https://yoomoney.ru/quickpay/confirm.xml" + baseSum := fmt.Sprintf("%f", sum) + + // Параметры запроса + params := url.Values{} + params.Add("receiver", "410012845407838") + params.Add("quickpay-form", "shop") + params.Add("targets", "Тестовая покупка") + params.Add("paymentType", "SB") + params.Add("sum", baseSum) + params.Add("label", "cheche") + + // Формируем полный URL с параметрами + fullURL := fmt.Sprintf("%s?%s", baseURL, params.Encode()) + // fmt.Println("Request URL:", fullURL) + + // Создаем кастомный HTTP-клиент с отключенными редиректами + client := &http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + // Останавливаемся после первого редиректа + return http.ErrUseLastResponse + }, + } + + // Отправляем POST-запрос с пустым телом + resp, err := client.Post(fullURL, "application/x-www-form-urlencoded", nil) + if err != nil { + // fmt.Println("Error sending request:", err) + return "WHOOPS" + } + defer resp.Body.Close() + + location, err := resp.Location() + if err != nil { + // fmt.Println("Error getting location:", err) + return "WHOOPS" + } + // fmt.Println("Redirect URL:", location.String()) + return location.String() +} + +func main() { + pay := Pay(6.0) + fmt.Println(pay) +} \ No newline at end of file