Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Incrementing firebase monetary value after Paypal transaction instead of replacing value

I am trying to increment a monetary value within firebase. When a user makes a project donation by paypal, a project key variable is attached to the paypal button and then is passed along with the transaction details to firebase. Then the mc_gross value (amount donated) is added to the amountFundraised key for that specific project key. Right now it is just replacing the current value from amountFundraised with mc_gross instead of incrementing.

So if the current amountFundraised is 100 and mc_gross is 50, the value for amountFunraised will now be 150.

Does anyone have any suggestions?

I tried using the increment() function but it is not working.

import { Router } from "express";
import { database,} from "../../firebase";
import { increment } from 'firebase/database';

export const router = Router();

router.get('/', (req, res) => {
  res.send('Express + TypeScript Server');
});

router.post('/payments', (req, res) => {
  console.log(req.body);
  console.log(req.query);
  const data = {
    ...req.body,
    ...req.query,
  }

  database.ref().child('/payments').push(data);
  database.ref().child(`projects/${data.projectKey}`).update({amountFundraised : increment(Number(data.mc_gross))})

  res.json('Okay');
})

I have also tried firebase.firestore.FieldValue.increment(Number(data.mc_gross))

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda