UNPKG

react-native-plugpag-lib

Version:

Integre facilmente as principais formas de pagamento da PagSeguro em seus aplicativos React Native através deste módulo nativo.

127 lines (126 loc) 3.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.PaymentTypes = exports.InstallmentTypes = void 0; exports.doAbort = doAbort; exports.doPayment = doPayment; exports.initializeAndActivatePinPad = initializeAndActivatePinPad; exports.plugPag = void 0; exports.print = print; exports.readNFCCard = readNFCCard; exports.refundPayment = refundPayment; exports.reprintCustomerReceipt = reprintCustomerReceipt; exports.useTransactionPaymentEvent = useTransactionPaymentEvent; var _reactNative = require("react-native"); var _react = require("react"); let PaymentTypes = exports.PaymentTypes = /*#__PURE__*/function (PaymentTypes) { PaymentTypes[PaymentTypes["CREDIT"] = 1] = "CREDIT"; PaymentTypes[PaymentTypes["DEBIT"] = 2] = "DEBIT"; PaymentTypes[PaymentTypes["VOUCHER"] = 3] = "VOUCHER"; PaymentTypes[PaymentTypes["PIX_QR_CODE"] = 5] = "PIX_QR_CODE"; return PaymentTypes; }({}); let InstallmentTypes = exports.InstallmentTypes = /*#__PURE__*/function (InstallmentTypes) { InstallmentTypes[InstallmentTypes["NO_INSTALLMENT"] = 1] = "NO_INSTALLMENT"; InstallmentTypes[InstallmentTypes["SELLER_INSTALLMENT"] = 2] = "SELLER_INSTALLMENT"; InstallmentTypes[InstallmentTypes["BUYER_INSTALLMENT"] = 3] = "BUYER_INSTALLMENT"; return InstallmentTypes; }({}); const { PagseguroPlugpag } = _reactNative.NativeModules; const plugPag = exports.plugPag = { installmentTypes: InstallmentTypes, paymentTypes: PaymentTypes }; async function initializeAndActivatePinPad(activationCode) { try { const response = await PagseguroPlugpag.initializeAndActivatePinPad(activationCode); return response; } catch (error) { console.error(error); throw error; } } async function doPayment({ amount, installmentType, installments, printReceipt, type, userReference }) { try { const dataPayment = { amount, installmentType, installments, printReceipt, type, userReference }; const dataFormatted = JSON.stringify(dataPayment); const response = await PagseguroPlugpag.doPayment(dataFormatted); return response; } catch (error) { console.error(error); throw error; } } async function refundPayment(refundPaymentData) { try { const data = JSON.stringify(refundPaymentData); const response = await PagseguroPlugpag.voidPayment(data); return response; } catch (error) { console.error(error); throw error; } } async function print(filePath) { try { await PagseguroPlugpag.print(filePath); } catch (error) { console.error(error); throw error; } } async function reprintCustomerReceipt() { try { await PagseguroPlugpag.reprintCustomerReceipt(); } catch (error) { console.error(error); throw error; } } function useTransactionPaymentEvent() { const [transactionPaymentEvent, setTransactionPaymentEvent] = (0, _react.useState)({ code: 0, message: '' }); (0, _react.useEffect)(() => { _reactNative.DeviceEventEmitter.addListener('eventPayments', event => { setTransactionPaymentEvent(event); }); }, []); return transactionPaymentEvent; } async function doAbort() { try { return PagseguroPlugpag.doAbort(); } catch (error) { console.error(error); throw error; } } async function readNFCCard() { try { return PagseguroPlugpag.readNFCCard(); } catch (error) { console.error(error); throw error; } } var _default = exports.default = plugPag; //# sourceMappingURL=index.js.map