prog
prog

Reputation: 193

stripe firebase callable function returning null

I made a firebase callable function to call stripe api to get a stripe customer object

exports.getDefaultPayment = functions.https.onCall(async (data, context) => {
  await stripe.customers.retrieve("cus_H5UarU16gpUbqM", (customer) => {
    // asynchronously called
    return customer;
  });
});

then I’m trying to simply log that object

onPress={() => {
              const getDefaultPayment = functions().httpsCallable(
                'getDefaultPayment'
              );
              getDefaultPayment().then((result) => {
                console.log(JSON.parse(result.data));
              });
            }}

but the result is null

Upvotes: 0

Views: 136

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317477

Your callable function isn't actually returning anything to the client. You need a return statement at the top level, not inside a callback. Also, it seems you're mixing up callbacks with async/await, which doesn't make sense. Just use await - don't bother with the callback. Perhaps this will work:

return stripe.customers.retrieve("cus_H5UarU16gpUbqM")

Upvotes: 1

Related Questions