#hearse_best-practices

1 messages ¡ Page 1 of 1 (latest)

graceful sundialBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1357165279792070759

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

bright token
#

For example, this is what i am doing in test mode:


// test
        const stripeClient = getStripeClient(c.env.STRIPE_SECRET_KEY);
        assert.ok(stripeClient, 'Stripe client is not defined');
        // Create a payment method
        const paymentMethod =
            await stripeClient.paymentMethods.retrieve('pm_card_visa');
        assert.ok(paymentMethod, 'Payment method is not defined');
        // Create a customer
        const email = 'test@gmail.com';
        const customer = await stripeClient.customers.create({
            email: email,
            payment_method: paymentMethod.id,
            description: 'Created by testing environment',
        });
// ... create subscription to invoke the webhook for invoice payment succeeded


// Inside my webhook ->
// => in my webhook i also use things like:
                const product = await stripeClient.products.retrieve(productId);
// and then eventually use information to populate the database
dbManager.createUser(...);
#

i can't really create a unit test for this since, vitest would not receive the webhook event

rain falcon
bright token
rain falcon
#

What does getStripeClient return ? are you using Stripe Node.js SDK?

bright token
#

i use things like inside of my webhook:

        const event = await stripeClient.webhooks.constructEventAsync(
            (await c.req.text()) as string,
            sig as string,
            c.env.STRIPE_WEBHOOK_ENDPOINT_SECRET,
        );
                const stripeSubscription =
                    await stripeClient.subscriptions.retrieve(subscriptionId);

                const productId = invoice.lines.data[0].price?.product as string;
                if (!productId) {
                    throw new Error('Could not retrieve product id from invoice');
                }
                const product = await stripeClient.products.retrieve(productId);

bright token
#

inside of cloudflare workers but i doubt that matters

rain falcon
#

So that Stripe Node.js SDK will make request to your stripe-mock endpoint for mocked responses.

bright token
#

oh that makes perfect sense.
So basically i could start stripe-mock, setup the stripe sdk to use stripe-mock endpoint as the server.

And in my testing environment, create a mock request to my webhook (since i cannot receive http requests in my testing environment)