#simsim_webhooks

1 messages ยท Page 1 of 1 (latest)

ionic depotBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1261281001762455654

๐Ÿ“ Have more to share? Add details, code, screenshots, videos, etc. below.

static anchor
halcyon jolt
#
const stripe = require('stripe')('YOUR_STRIPE_SECRET_KEY'); // Replace with your Stripe secret key
const axios = require('axios');
const bodyParser = require('body-parser');

const app = express();
const discordWebhookUrl = 'YOUR_DISCORD_WEBHOOK_URL'; // Replace with your Discord webhook URL

app.use(bodyParser.json());

app.post('/webhook', async (req, res) => {
    const event = req.body;

    // Handle the event
    switch (event.type) {
        case 'payment_intent.succeeded':
            const paymentIntent = event.data.object;
            
            // Extract custom fields from metadata
            const donorName = paymentIntent.metadata.donorName || 'Anonymous';
            const customField = paymentIntent.metadata.customField || 'No custom field data';

            // Construct the message
            const message = `${donorName} just donated and here is custom field data: ${customField}`;

            // Send the message to Discord
            try {
                await axios.post(discordWebhookUrl, {
                    content: message
                });
                res.status(200).send('Success');
            } catch (error) {
                console.error('Error sending message to Discord:', error);
                res.status(500).send('Error');
            }
            break;
        default:
            // Unexpected event type
            return res.status(400).end();
    }

    res.json({ received: true });
});

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});```
#

how this shoult look like?

static anchor
#

When you say 'custom fields' what exactly are you using? Can you share one of these evt_xxx IDs you're processing?

#

Because your code references metadata but you mean the custom fields collected on the Payment Link payment page, right?

halcyon jolt
#

yes its all about payment link

static anchor
#
case 'checkout.session.completed':
const checkoutSession = event.data.object;
            
            // Extract custom fields from metadata
            const donorName = checkoutSession.custom_fields[0][text].value || 'Anonymous';
            const customField = checkoutSession.custom_fields[1][text].value || 'No custom field data';

            // Construct the message
            const message = `${donorName} just donated and here is custom field data: ${customField}`;

            // Send the message to Discord
            try {
                await axios.post(discordWebhookUrl, {
                    content: message
                });
                res.status(200).send('Success');
            } catch (error) {
                console.error('Error sending message to Discord:', error);
                res.status(500).send('Error');
            }
            break;
#

Something like that should work really

halcyon jolt
#

ohh, thanks, i hve been strugeling like two days to get data from custom field and send this to discord message in channel ๐Ÿ˜ฆ

static anchor
#

Let me know if that works

halcyon jolt
#

i will

static anchor
#

Make sure your webhook is configured to listen for checkout.session.completed events