AI resources

Default rendering

Before rendering the Wallet Brick, first execute the initialization steps shared among all Bricks. From there, see below the necessary information to configure and render the Wallet Brick.

To consult the types and specifications of the parameters and responses of the Brick functions, refer to the technical documentation.

Configure the Brick

Create Brick's startup configuration.

const renderWalletBrick = async (bricksBuilder) => {
    await bricksBuilder.create("wallet", "walletBrick_container", {
        initialization: {
            preferenceId: "<PREFERENCE_ID>",
        },
        customization: {
            theme: "default",
            customStyle: {
                valueProp: "practicality",
                valuePropColor: "white",
            },
        },
    });
};

renderWalletBrick(bricksBuilder);
Attention
Whenever the user leaves the screen where some Brick is displayed, it is necessary to destroy the current instance with the command window.walletBrickController.unmount(). When entering again, a new instance must be generated.

This flow is designed for stores that use Wallet Brick at the end of the checkout process and already have the preference created when rendering the Brick, sending it during initialization. If desired, you can use the Brick by creating the preference at the time of submission (onSubmit). See more information in the Preference on submit section.

Render the Brick

Once the configurations are created, enter the code below to render the brick.

Important
El id walletBrick_container de la div html abajo debe corresponder que el valor enviado en el metodo create() de la etapa anterior.
<div id="walletBrick_container"></div>

The result of rendering the Brick should blook like the image below, presenting a text and a standard visual.

wallet-brick-render

If you want to change the text and the standard visual of the Brick, check the sections Change texts and Change appearance, respectively.

Enable payment with Mercado Pago

To use a payment method (paymentMethods) of the "mercadoPago" type, a preference must be sent during Brick initialization, replacing the value PREFERENCE_ID by the ID of the preference created.

To create a preference in your backend, add the Mercado Pago SDK and the necessary credentials to your project to enable the preference usage:

<?php
// Mercado Pago SDK
require __DIR__ .  '/vendor/autoload.php';
// Add Your credentials
MercadoPago\SDK::setAccessToken('PROD_ACCESS_TOKEN');
?>

Then set the preference according to your product or service.

The code examples below set the purpose of preference to wallet_purchase, but it is also possible to set it to onboarding_credits. Understand the difference between the two:

  • wallet_purchase: the user must log in when redirected to his Mercado Pago account.

  • onboarding_credits: after logging in, the user will see the pre-selected credit payment option in his Mercado Pago account.

<?php
$client = new PreferenceClient();
$preference = $client->create([
  "items"=> array(
    array(
      "title" => "My product",
      "quantity" => 1,
      "unit_price" => 25 // item unit price, must be an integer.
    )
  )
]);
?>
When a user chooses to make a payment through Mercado Pago Wallet, they are redirected to the Mercado Pago page to complete the payment. The back_urls allow them to be returned to the site after the payment is completed. Do not use local domains for this value (such as 'localhost/' or '127.0.0.1' with or without a specified port). We recommend using a server with a named domain (DNS) or development IPs to be able to return to the site after payment.

For more details on how to configure it, access the Preferences section.

Test your integration

With the integration completed, you will be able to test payment reception. For more information, access the section Make test purchase.