Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout Pro not open #9

Open
felipeusr opened this issue Oct 2, 2021 · 0 comments
Open

Checkout Pro not open #9

felipeusr opened this issue Oct 2, 2021 · 0 comments

Comments

@felipeusr
Copy link

Alguma coisa falta, mas não sei o que é... A documentação não é clara.

Frontend index.html

<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Checkout Pro Integração</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script src="https://secure.mlstatic.com/sdk/javascript/v1/mercadopago.js"></script>
    </head>

    <body>
        <div style="width: 500px; height: 500px; background-color: #f0f0f0;">
            <form class="cho-container" action="http://localhost:3001/pagar" method="post">
                <!--Botão renderizado aqui-->
            </form>
        </div>

        <script src="https://sdk.mercadopago.com/js/v2"></script>
        <script>
            // Adicione as credenciais do SDK
            const mp = new MercadoPago('TEST-a324251b-bd2e-4c0f-9507-c8ec807b6145', {
                locale: 'pt-BR'
            });

            // Inicialize o checkout
            mp.checkout({
                preference: {
                    id: '1'
                },
                render: {
                    container: '.cho-container', // Indique o nome da class onde será exibido o botão de pagamento
                    label: 'Comprar agora', // Muda o texto do botão de pagamento (opcional)
                }
            });
        </script>
    
    </body>
</html>

Server-side (node) index.js

const express = require("express");
const app = express();
const cors = require("cors");
const body_parser = require("body-parser");
const mercadopago = require ('mercadopago');

app.use(express.json());
app.use(cors());
app.use(body_parser.urlencoded({ extended : true }));

mercadopago.configure({
    access_token: 'TEST-3059303028461564-092022-f2dda18bb6dff04b17c65d5fd6a3d2e1-807277607'
});

app.post("/pagar", (req, res) => {
    var preference = {
        items: [
            {
                id: '1',
                title: 'Lightweight Paper Table',
                description: 'Inspired by the classic foldable art of origami',
                category_id: 'home',
                quantity: 1,
                currency_id: 'BRL',
                unit_price: 55
            }
        ]
    };
    mercadopago.preferences.create(preference)
    .then(function (response) {
        res.json({
            id: response.body.id
        });
    }).catch(function (error) {
        console.log(error);
    });
});

app.listen(3001, () => {
    console.info("Server running in 3001 port!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant