Is this a correct way to make a PayPal payment system secure?

first of all, Thank you to take the time to read this.

I am making a Payment Test app, with Java and Spring boot, but to take the ad data I am making a form with the data of that ad in my HTML template of the ad in which the user will click on the pay button .

This is the HTML so you can understand it better.

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Detalle del Anuncio</title>
<h1 th:text="${anuncio.titulo}">Título del Anuncio</h1>

<img th:src="@{${anuncio.imageUrl}}" alt="Imagen del anuncio">

<p>Categoría: <span th:text="${anuncio.categoria}"></span></p>

<p>Estado: <span th:text="${anuncio.estado}"></span></p>

<p>Precio: <span th:text="${anuncio.precio}"></span></p>

<p>Descripción: <span th:text="${anuncio.descripcion}"></span></p>

<button id="btn">Comprar</button>
<input type="text" name="amount" th:value="${anuncio.precio}">

<input type="text" name="descripcion" th:value="${anuncio.titulo}">

<button type="submit">comprar</button>
public String pay(@PathVariable("id") Long id, @RequestParam("amount") Long amount, @RequestParam("descripcion")String description) {

    

    Anuncio anuncio = anuncioService.findAdById(id);

    if(anuncio == null) {

        //THIS IS A EXAMPLE ETROR HANDLING. ITS JUST A EXAMPLE

        

        //SOLO ES UN EJEMPLO SOBRE EL MANEJO DE ERRORES, ESTO ES AUN UNA PRUEBA.

        

        return "redirect:/nullAnonce";

    } else {

        Long originalPrice = anuncio.getPrecio(); 

        //JUST A EXAMPLE TAKING ONLY THE PRICE, IN A REAL CASE I WILL BE TAKING ALL.

        

        //ES SOLO UN EJEMPLO TOMANDO SOLO EL PRECIO, EN UN CASO REAL TOMARIAMOS NO SOLO EL PRECIO TAMBIEN LA DESCRIPCION Y ESAS COSAS. 

        if(amount != originalPrice) {

                        //JUST A EXAMPLE TAKING ONLY THE PRICE, IN A REAL CASE I WILL BE TAKING ALL.

            return "redirect:/PriceNotCorrect";

        } else {

            try {

        // Configurar las credenciales de PayPal

        String clientId = "CLIENTID";

        String clientSecret = "CLIENTSECRET";

        String mode = "sandbox"; // O "live" para producción



        // Crear el objeto APIContext

        APIContext apiContext = new APIContext(clientId, clientSecret, mode);



        // Configurar la cantidad y la transacción

        Amount paymentAmount = new Amount();

        paymentAmount.setCurrency("USD");

        paymentAmount.setTotal("500");



        Transaction transaction = new Transaction();

        transaction.setDescription("Descripción del pago");

        transaction.setAmount(paymentAmount);



        List<Transaction> transactions = new ArrayList<>();

        transactions.add(transaction);



        // Configurar el pagador

        Payer payer = new Payer();

        payer.setPaymentMethod("paypal");



        // Configurar el pago

        Payment payment = new Payment();

        payment.setIntent("sale");

        payment.setPayer(payer);

        payment.setTransactions(transactions);



        // Configurar las URLs de redirección

        RedirectUrls redirectUrls = new RedirectUrls();

        redirectUrls.setCancelUrl("https://localhost:3000/cancel");

        redirectUrls.setReturnUrl("https://localhost:3000/rooms");

        payment.setRedirectUrls(redirectUrls);



        // Crear el pago

        Payment createdPayment = payment.create(apiContext);



        // Obtener la URL de aprobación y redirigir al usuario

        String approvalUrl = createdPayment.getLinks().stream()

                .filter(link -> "approval_url".equals(link.getRel()))

                .findFirst()

                .orElseThrow(() -> new PayPalRESTException("Approval URL not found"))

                .getHref();



        return "redirect:" + approvalUrl;

    } catch (PayPalRESTException e) {

        e.printStackTrace();

        return "redirect:/error";

    }

        }

    }

    

}`

Sorry if it seems a bit ‘stupid’…

What we are trying to do is that even if a user changes the value to the price, it will be compared with the price in the database, if it is correct, good, and if not then he is redirected.

New contributor

Luka Varga is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật