@mercadopago/sdk-react
Version:
Mercado Pago SDK React
80 lines (79 loc) • 3.16 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const initial_1 = require("../util/initial");
const renderBrick_1 = require("../util/renderBrick");
const constants_1 = require("../util/constants");
/**
* Wallet Brick allows you to offer payments from your Mercado Pago account at any stage of the purchase process.
*
* Usage:
*
* ```ts
* import Wallet, {initMercadoPago} from '@mercadopago/sdk-react'
*
* initMercadoPago('YOUR_PUBLIC_KEY')
*
* const Example = () => {
* return(
* <Wallet initialization={{ preferenceId: '<PREFERENCE_ID>'}} /> // PREFERENCE_ID generated in backend
* )
* }
* export default Example
* ```
*
* @see {@link https://www.mercadopago.com/developers/en/docs/checkout-bricks/wallet-brick/introduction Wallet Brick documentation} for more information.
*/
const Wallet = ({ onReady = initial_1.onReadyDefault, onError = initial_1.onErrorDefault, onSubmit = initial_1.onSubmitDefault, customization, initialization, locale, id = 'walletBrick_container', }) => {
(0, react_1.useEffect)(() => {
// CardPayment uses a debounce to prevent unnecessary reRenders.
const WalletBrickConfig = {
settings: {
initialization,
customization,
locale,
callbacks: {
onReady: onReady,
onSubmit: onSubmit,
onError: onError,
},
},
name: 'wallet',
containerId: id,
controller: 'walletBrickController',
};
const timer = setTimeout(() => {
(0, renderBrick_1.initBrick)(WalletBrickConfig);
}, constants_1.DEBOUNCE_TIME_RENDER);
return () => {
var _a;
clearTimeout(timer);
(_a = window.walletBrickController) === null || _a === void 0 ? void 0 : _a.unmount();
};
}, [customization, initialization, onReady, onError, onSubmit]);
return react_1.default.createElement("div", { id: id });
};
exports.default = Wallet;