function doPost(e) { const cache = CacheService.getScriptCache(); const raw = e.postData.contents; const hash = Utilities.base64Encode(Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, raw)); if (cache.get(hash)) { return ContentService .createTextOutput(JSON.stringify({ ok: true, duplicate: true })) .setMimeType(ContentService.MimeType.JSON); } cache.put(hash, "1", 600); const ss = SpreadsheetApp.openById('1UXXDFdVMyRL8B4F7sLZXVbqWd5hRFU2U-k3UaNwR8Ow'); const feuille = ss.getSheetByName('Inscriptions'); const payload = JSON.parse(raw); /* CAS 1 — SONDAGE */ if (payload.type === 'sondage') { const prenom = payload.prenom || ''; const nom = payload.nom || ''; const email = payload.email || ''; const participe = payload.participation === 'oui' ? 'Oui' : ''; const participePas = payload.participation === 'non' ? 'Non' : ''; const opera = payload.opera === 'oui' ? 'Oui' : 'Non'; const annulation = payload.annulation === 'oui' ? 'Oui' : 'Non'; feuille.appendRow([ prenom, nom, participePas, participe, payload.participation === 'oui' ? opera : '', payload.participation === 'oui' ? annulation : '', email, '', '', '', '' ]); } /* CAS 2 — PAIEMENT STRIPE */ else if (payload.type === 'payment_intent.succeeded') { const intent = payload.data.object; const meta = intent.metadata; const montant = intent.amount_received / 100; const options = meta.options || ''; const aOpera = options.includes('opera') ? 150 : ''; const baseAvecOpera = options.includes('opera') ? 670 : 520; const aAssurance = options.includes('annulation') ? Math.round(baseAvecOpera * 0.07 * 100) / 100 : ''; const email = meta.email || ''; const prenom = meta.prenom || ''; const nom = meta.nom || ''; /* Cherche si la personne existe déjà par email en colonne G */ const lastRow = feuille.getLastRow(); let ligneExistante = -1; for (let i = 2; i <= lastRow; i++) { if (feuille.getRange(i, 7).getValue() === email) { ligneExistante = i; break; } } if (ligneExistante > 0) { feuille.getRange(ligneExistante, 8).setValue(520); feuille.getRange(ligneExistante, 9).setValue(aOpera); feuille.getRange(ligneExistante, 10).setValue(aAssurance); feuille.getRange(ligneExistante, 11).setValue(montant); } else { feuille.appendRow([ prenom, nom, '', 'Oui', aOpera ? 'Oui' : '', aAssurance ? 'Oui' : '', email, 520, aOpera, aAssurance, montant ]); } /* Envoi via proxy WordPress → Brevo */ UrlFetchApp.fetch('https://vernex6568.org/wp-json/vernex/v1/paiement-confirme', { method: 'post', contentType: 'application/json', payload: JSON.stringify({ prenom: prenom, nom: nom, email: email, montant: montant.toString(), opera: aOpera ? '150.00' : '', assurance: aAssurance ? aAssurance.toString() : '' }), muteHttpExceptions: true }); } return ContentService .createTextOutput(JSON.stringify({ ok: true })) .setMimeType(ContentService.MimeType.JSON); } Se connecter ‹ vernex6568 — WordPress

Se connecter

Login to continue

← Aller sur vernex6568