UNPKG

@jackiemacklein/nettz-utils

Version:

Serviços de imagem, e-mail, códigos de barras, utilitários numéricos e componentes React para apps Node.js com TypeScript

100 lines (99 loc) 4.87 kB
"use strict"; /** * @author Jackiê Macklein * @company Onside tecnologia/Nettz * @copyright Todos direitos reservados. * @description Normalização de dados entre formato local Nettz e payload da API Asaas. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.NormalizeToLocal = exports.NormalizeToIntegration = void 0; class NormalizeToIntegration { customer(data) { var _a, _b; return { name: data.name, cpfCnpj: (_a = data.cpf_cnpj) === null || _a === void 0 ? void 0 : _a.replace(/\D/g, ""), email: data.email, mobilePhone: (_b = (data.cell_phone || data.phone)) === null || _b === void 0 ? void 0 : _b.replace(/\D/g, ""), externalReference: data.id, postalCode: data.zipcode, addressNumber: data.number || "s/n", }; } charge(data) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; const payload = { externalReference: ((_a = data.external_reference) === null || _a === void 0 ? void 0 : _a.trim()) || (data.id != null ? String(data.id) : undefined), customer: data.customer_provider_id, value: (data.value || 0) / 100, description: data.description, dueDate: data.due_date, billingType: data.billing_type === "BILLET" ? "BOLETO" : data.billing_type, }; if (data.billing_type === "CREDIT_CARD" && data.credit_card) { const [month, yearSuffix] = data.credit_card.expiry.split("/"); payload.creditCard = { ccv: data.credit_card.cvc, expiryMonth: month, expiryYear: `20${yearSuffix}`, holderName: data.credit_card.name, number: data.credit_card.number, }; payload.creditCardHolderInfo = { name: (_b = data.customer) === null || _b === void 0 ? void 0 : _b.name, cpfCnpj: (_d = (_c = data.customer) === null || _c === void 0 ? void 0 : _c.cpf_cnpj) === null || _d === void 0 ? void 0 : _d.replace(/\D/g, ""), email: ((_e = data.customer) === null || _e === void 0 ? void 0 : _e.email) || "", postalCode: ((_g = (_f = data.customer) === null || _f === void 0 ? void 0 : _f.zipcode) === null || _g === void 0 ? void 0 : _g.replace(/\D/g, "")) || "", mobilePhone: (_k = (((_h = data.customer) === null || _h === void 0 ? void 0 : _h.phone) || ((_j = data.customer) === null || _j === void 0 ? void 0 : _j.cell_phone))) === null || _k === void 0 ? void 0 : _k.replace(/\D/g, ""), addressNumber: ((_l = data.customer) === null || _l === void 0 ? void 0 : _l.number) || "0", }; } return payload; } } exports.NormalizeToIntegration = NormalizeToIntegration; class NormalizeToLocal { customer(data) { return { id: data.id }; } charge(data) { var _a, _b, _c, _d, _e, _f, _g, _h, _j; const pix = data.pix; const billet = data.billet; const creditCard = data.creditCard; const status = data.status; const billingType = data.billingType; return { provider_id: String(data.id), status, pix: (pix === null || pix === void 0 ? void 0 : pix.payload) ? { image_base64: (_a = pix.encodedImage) !== null && _a !== void 0 ? _a : "", payload: pix.payload, expiration_at: (_b = pix.expirationDate) !== null && _b !== void 0 ? _b : "", } : undefined, billet: billet ? { barcode: (_c = billet.barCode) !== null && _c !== void 0 ? _c : "", number: (_d = billet.nossoNumero) !== null && _d !== void 0 ? _d : "", identification_field: (_e = billet.identificationField) !== null && _e !== void 0 ? _e : "", url: (_g = (_f = billet.url) !== null && _f !== void 0 ? _f : billet.bankSlipUrl) !== null && _g !== void 0 ? _g : "", } : undefined, credit_card: creditCard ? { number: (_h = creditCard.creditCardNumber) !== null && _h !== void 0 ? _h : "", brand: (_j = creditCard.creditCardBrand) !== null && _j !== void 0 ? _j : "", } : undefined, net_value: typeof data.netValue === "number" ? data.netValue * 100 : undefined, paid_type: ["CONFIRMED", "RECEIVED", "RECEIVED_IN_CASH"].includes(String(status)) ? billingType : undefined, paid_date: data.paymentDate || data.confirmedDate, }; } } exports.NormalizeToLocal = NormalizeToLocal;