1

I am trying to fix my previously working(can not give a head on this one) firebase cloud function that on document delete should trigger stripe's customers.deleteSource endpoint. However it simply does not trigger it and I can not understand why.

This is the function:

    exports.removePaymentSource = functions.region('europe-west1').firestore.document('/stripe_customers/{userId}/sources/{sourceId}').onDelete(async (change, context) => {
    
      console.log('Does not log..')
    
      try {
        const source = change.before.data();
        const customer_id = source.customer;
        const card = source.card;
        console.log('Does not log..')
        console.log('Does not trigger the await')
        return await stripe.customers.deleteSource(customer_id, card);
    
      } catch (error) {
        return reportError(error, {user: context.params.userId});
      }

});

In this case I would expect to see some error since it does log on Firebase's functions log but it logs 'executed successfully..'. Also I would like to mention that all my other stripe endpoints are working perfectly, so the stripe implementation itself is fine, just the damn deleteSource.

This is the picture from Firebase's functions logs:

enter image description here

What I am doing wrong? Can anybody please lead me to the right direction? Any help is appreciated!

Tarvo Mäesepp
  • 4,477
  • 3
  • 44
  • 92
  • Do you have free plan? You need a Blaze plan to allow calls to apis or domain outside google. More info in this answer: https://stackoverflow.com/a/50007666/6693213 :) – Motoralfa Sep 07 '20 at 18:33
  • @Motoralfa I do have Blaze plan on my project and as I said all my other enpoints are working perfectly, but thanks for pointing that out ;) – Tarvo Mäesepp Sep 07 '20 at 18:40
  • So, what exactly are you observing? Please edit the question to be more clear. "I would expect to see some error but nothing" isn't very descriptive. Are you saying that you see nothing in the log at all for the function? Or are you saying that you see the function runs, but it does nothing? I suggest adding more logging and show the output so we can see what you are seeing. – Doug Stevenson Sep 07 '20 at 18:44
  • Does the function itself get called? That is, can you see your `console.log('tere')` log? – ttmarek Sep 07 '20 at 18:54
  • @DougStevenson Yeah, that part of the question might be a little bit off but the point is that all my console logs in the function are logging(except error) and also I can see from firebase function logs that it executed successfully but it does not trigger the await function. And I can say that it does not trigger the stripe function because on Stripe dashboard I do not see DELETE request. – Tarvo Mäesepp Sep 07 '20 at 19:07
  • @ttmarek I updated the question. – Tarvo Mäesepp Sep 07 '20 at 19:30
  • @TarvoMäesepp, interesting, from your question I gather that none of your log statements are working. Even the first console.log before the try/catch. If so, are you sure you're running the most up to date code? – ttmarek Sep 08 '20 at 18:43

0 Answers0