#abvfx

1 messages · Page 1 of 1 (latest)

foggy egretBOT
turbid aspen
#

Hello! I'm not sure I understand what you're asking, can you provide more context?

tawny arch
#

Is webCrypto needed to create this event ( const event = await stripe.webhooks.constructEvent( body, sig, env.STRIPE_ENDPOINT_SECRET, undefined, webCrypto );)

turbid aspen
#

I don't know.

#

I don't believe so.

#

Can you provide more details? What are you trying to build/do?

tawny arch
#

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

turbid aspen
#

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.

tawny arch
#

Ok, I just wanted to ensure it's not something Stripe requires.

turbid aspen