#abvfx
1 messages · Page 1 of 1 (latest)
Hello! I'm not sure I understand what you're asking, can you provide more context?
Is webCrypto needed to create this event ( const event = await stripe.webhooks.constructEvent( body, sig, env.STRIPE_ENDPOINT_SECRET, undefined, webCrypto );)
I don't know.
I don't believe so.
Can you provide more details? What are you trying to build/do?
Creating a basic webhook for fulfilling orders. This is the code so far. `const Stripe = require("stripe");
export default {
fetch: handleRequest
};
async function handleRequest(request, env, ctx) {
const stripe = Stripe(env.STRIPE_API_KEY);
const body = await request.text()
const sig = request.headers.get('stripe-signature')
const event = await stripe.webhooks.constructEvent(
body,
sig,
env.STRIPE_ENDPOINT_SECRET,
undefined,
webCrypto
);
switch (event.type) {
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
// 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;
// ... handle other event types
default:
console.log(`Unhandled event type ${event.type}`);
}
// Return a response to acknowledge receipt of the event
return new Response(JSON.stringify({ received: true }), {
headers: { 'Content-type': 'application/json' }
})
};`
Most of the cloudflare examples use webcrypto but the docs from stripe don't
No, webCrypto is not required there. Why are you adding it? Are you trying to solve a problem or error?
I can't speak to the Cloudflare part, I can only help you with the Stripe part.
Like, you can specify something there, but it's not typically required.
Ok, I just wanted to ensure it's not something Stripe requires.
The library should create one on its own, but you can override it if you need to. See here: https://github.com/stripe/stripe-node/blob/89712edf61eb15f7c6eb50b68dd30d0df96eb747/src/stripe.core.ts#L162-L186