start adding payment

This commit is contained in:
Thomas Demirdjian
2025-11-04 14:46:12 +01:00
parent 02a2333a41
commit 4bb083ea46
24 changed files with 3507 additions and 7604 deletions
+24 -2
View File
@@ -18,7 +18,9 @@ const WELCOME_EMAIL_SUBJECT = "Bienvenue sur MusicLand";
exports.testWelcomMail = onRequest(async (req, res) => {
if (req.method !== "GET") {
res.set("Allow", "GET");
return res.status(405).json({ success: false, error: "Method not allowed" });
return res
.status(405)
.json({ success: false, error: "Method not allowed" });
}
try {
const targetEmail = req.query.email || "tdtomthomas@gmail.com";
@@ -48,7 +50,27 @@ exports.testWelcomMail = onRequest(async (req, res) => {
exports.onUserCreated = onDocumentCreated("users/{userID}", async (event) => {
try {
const { email = "", firstName = "", lastName = "" } = event?.data?.data();
const {
email = "",
firstName = "",
lastName = "",
} = event?.data?.data() || {};
try {
await event.data.ref.set(
{
coins: admin.firestore.FieldValue.increment(10),
coinWelcomeGrantedAt: admin.firestore.FieldValue.serverTimestamp(),
},
{ merge: true },
);
} catch (coinError) {
console.warn(
"[users-onUserCreated] Unable to grant welcome coins",
event?.params?.userID,
coinError?.message || coinError,
);
}
if (email) {
if (!resendClient) {
console.warn("Resend API key not configured; skipping welcome email.");