Search code examples
javascriptnode.jsemailstripe-paymentsfulfillment

How to use Stripe payment_intent_data to send email to client after succesful payment?


I cannot figure out how to send email to client after successful payment. Documentation says about setting "payment_intent_data.receipt_email" but what I have below in my code is not working (nothing arrives to emai-box). How am I correctly to set this?

app.post('/create-checkout-session', async (req, res) => {
  try {
    const session = await stripe.checkout.sessions.create({
      payment_method_types: ['card'],
      **payment_intent_data: {receipt_email: "[email protected]"},**
      shipping_rates: ['shr_1JgbJxAuqIBxGbL5lCkeLyfu'],
      shipping_address_collection: {
        allowed_countries: ['FI'],
      },
      line_items: [
        {
          price_data: {
            currency: 'eur',
            product_data: {
              name: 'book',
            },
            unit_amount: 6200,
          },
          quantity: 2,
        },
      ],
      mode: 'payment',
      success_url: 'http://localhost:4200/myynti/success',
      cancel_url: 'http://localhost:4200/myynti/cancel',
    });

    res.json({ id: session.id });

Solution

  • You don't necessarily need to pass the customer's email in payment_intent_data.receipt_email.

    When using Checkout, you can automatically email your customers upon successful payments. Enable this feature with the email customers for successful payments option in your email receipt settings.

    However, the most important point to note is that receipts for payments created using your test API keys are not sent automatically. Instead, you can view or manually send a receipt using the Dashboard by finding the payment in the Dashboard and click "Send Receipt" under "Receipt history".