feat(checkout): troca CPF por e-mail do pagador (PIX sem CPF confirmado no Orders API)
build-image / build-push (push) Successful in 6m39s
build-image / build-push (push) Successful in 6m39s
This commit is contained in:
1 parent
8fab1e2ab6
commit
9748c8e9e0
3 files changed
+14
-17
No files matched your search
@@ -505,7 +505,7 @@
|
||||
<section id="view-payer" class="card hidden" aria-labelledby="payerTitle">
|
||||
<div class="pay-head">
|
||||
<h2 id="payerTitle">Seus dados</h2>
|
||||
<p>Para emissão do PIX, informe nome e CPF</p>
|
||||
<p>Para emissão do PIX, informe seu nome e e-mail</p>
|
||||
</div>
|
||||
|
||||
<label class="field">
|
||||
@@ -514,8 +514,8 @@
|
||||
</label>
|
||||
|
||||
<label class="field">
|
||||
<span>CPF</span>
|
||||
<input id="payerCpf" type="text" inputmode="numeric" maxlength="14" placeholder="000.000.000-00">
|
||||
<span>E-mail</span>
|
||||
<input id="payerEmail" type="email" autocomplete="email" inputmode="email" maxlength="120" placeholder="[email protected]">
|
||||
</label>
|
||||
|
||||
<div class="row">
|
||||
@@ -624,14 +624,6 @@
|
||||
return mpDevice || window.MP_DEVICE_SESSION_ID || null;
|
||||
}
|
||||
|
||||
function maskCpf(v) {
|
||||
const d = v.replace(/\D/g, '').slice(0, 11);
|
||||
return d
|
||||
.replace(/^(\d{3})(\d)/, '$1.$2')
|
||||
.replace(/^(\d{3})\.(\d{3})(\d)/, '$1.$2.$3')
|
||||
.replace(/\.(\d{3})(\d{1,2})$/, '.$1-$2');
|
||||
}
|
||||
|
||||
function toast(msg) {
|
||||
const t = $('toast');
|
||||
t.textContent = msg;
|
||||
@@ -699,14 +691,14 @@
|
||||
async function checkout(planId) {
|
||||
try {
|
||||
const payerName = $('payerName').value.trim();
|
||||
const payerCpf = $('payerCpf').value.trim();
|
||||
const payerEmail = $('payerEmail').value.trim();
|
||||
if (payerName.length < 3) { toast('Informe seu nome completo'); show('payer'); return; }
|
||||
if (payerCpf.replace(/\D/g, '').length !== 11) { toast('Informe um CPF com 11 dígitos'); show('payer'); return; }
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(payerEmail)) { toast('Informe um e-mail válido'); show('payer'); return; }
|
||||
|
||||
const res = await fetch('/api/checkout', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ planId, mac, payerName, payerCpf, deviceId: deviceId() }),
|
||||
body: JSON.stringify({ planId, mac, payerName, payerEmail, deviceId: deviceId() }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.error) throw new Error(data.error);
|
||||
@@ -768,7 +760,6 @@
|
||||
$('backBtn2').addEventListener('click', (e) => { e.preventDefault(); show('plans'); });
|
||||
$('payerBack').addEventListener('click', () => show('plans'));
|
||||
$('payerNext').addEventListener('click', () => checkout(selectedPlanId));
|
||||
$('payerCpf').addEventListener('input', (e) => { e.target.value = maskCpf(e.target.value); });
|
||||
|
||||
// ===== Login no hotspot (voucher) =====
|
||||
const HS_LOGIN = 'http://10.10.10.1/login';
|
||||
|
||||
@@ -51,9 +51,13 @@ app.get('/api/plans', (req, res) => {
|
||||
|
||||
app.post('/api/checkout', async (req, res) => {
|
||||
try {
|
||||
const { planId, mac, payerName, payerCpf, deviceId } = req.body || {};
|
||||
const { planId, mac, payerName, payerEmail, payerCpf, deviceId } = req.body || {};
|
||||
const plan = getDb().plans.find((p) => p.id === planId && p.active);
|
||||
if (!plan) return res.status(400).json({ error: 'plano invalido' });
|
||||
const email = String(payerEmail || '').trim();
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email)) {
|
||||
return res.status(400).json({ error: 'email invalido' });
|
||||
}
|
||||
if (payerCpf && !validCpf(payerCpf)) return res.status(400).json({ error: 'CPF invalido' });
|
||||
|
||||
// historico do comprador (primeira compra / ultima compra)
|
||||
@@ -80,6 +84,7 @@ app.post('/api/checkout', async (req, res) => {
|
||||
planId: plan.id,
|
||||
planName: plan.name,
|
||||
payerName,
|
||||
payerEmail: email,
|
||||
payerCpf,
|
||||
firstPurchase,
|
||||
registrationDate,
|
||||
|
||||
+2
-1
@@ -63,6 +63,7 @@ export async function createPixPayment(opts) {
|
||||
planId,
|
||||
planName,
|
||||
payerName,
|
||||
payerEmail,
|
||||
payerCpf,
|
||||
firstPurchase,
|
||||
registrationDate,
|
||||
@@ -72,7 +73,7 @@ export async function createPixPayment(opts) {
|
||||
|
||||
const name = splitName(payerName);
|
||||
const payer = {
|
||||
email: '[email protected]',
|
||||
email: payerEmail || '[email protected]',
|
||||
first_name: name.first,
|
||||
last_name: name.last,
|
||||
entity_type: 'individual',
|
||||
|
||||
Reference in new issue
Block a user