Looking to see why I am getting a 200 success in my stripe dashboard yet in my Firebase Functions logs I see this function being called twice once is successful 200 and second is 400 error. I added my Node.js code, my call functions call in swift, and a picture of my firebase logs. I have tested if I am calling this function twice in swift and I am not.
Node.js stripe Webhook call
exports.events = functions.https.onRequest(async (request, response) => {
const endpointSecret = 'whsec_qYR81nTsb0uyACJL92TIx9dct6nHNLqg'
const stripe = require('stripe')(functions.config().stripe.token);
const payloadData = request.rawBody;
const webhookStripeSignatureHeader = request.headers['stripe-signature'];
let event = request.body;
if (endpointSecret) {
// Get the signature sent by Stripe
const signature = request.headers['stripe-signature'];
try {
event = stripe.webhooks.constructEvent(payloadData, webhookStripeSignatureHeader, endpointSecret);
} catch (err) {
console.log(`⚠️ Webhook signature verification failed.`, err.message);
return response.sendStatus(400);
}
}
// Handle the event
switch (event.type) {
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
console.log(`PaymentIntent for ${paymentIntent.amount} was successful!`);
// Then define and call a method to handle the successful payment intent.
// handlePaymentIntentSucceeded(paymentIntent);
break;
case 'payment_method.attached':
const paymentMethod = event.data.object;
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handlePaymentMethodAttached(paymentMethod);
break;
default:
// Unexpected event type
console.log(`Unhandled event type ${event.type}.`);
}
// Return a 200 response to acknowledge receipt of the event
response.send();
});
How I am calling in Swift
var functions = Functions.functions()
functions.httpsCallable("events").call() { result, error in
print(result)
print("printing the functions call result")
debugPrint(error)
print("debug printing the error")
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
print(code)
print(message)
print(details)
}
// ...
}
if let error = error as NSError? {
print(error)
print("printing the error in stripeWebhook call")
debugPrint(error)
}
if let data = result?.data as? [String: Any] {
print(data)
}
}
My Firebase Functions logs