Learn how to enable and customize email receipts in Stripe, including setup, branding, API options, testing, and monitoring for a seamless customer experience.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Introduction
Stripe offers email receipts functionality that automatically sends receipt emails to your customers after successful payments. This tutorial will guide you through the process of enabling and customizing email receipts in Stripe, exploring all available options and settings.
Step 1: Access Your Stripe Dashboard
First, you need to log in to your Stripe account:
Step 2: Navigate to Email Receipt Settings
To configure email receipts:
Step 3: Enable Email Receipts
To turn on the email receipt feature:
Step 4: Customize Your Receipt Template
Personalize your receipt emails:
Business Information:
Email Appearance:
Step 5: Configure Receipt Settings via API (Optional)
For developers who want programmatic control, use Stripe's API:
// Example: Setting receipt email when creating a PaymentIntent
const stripe = require('stripe')('sk_test_your_secret_key');
const paymentIntent = await stripe.paymentIntents.create({
amount: 2000,
currency: 'usd',
receipt\_email: '[email protected]',
// other PaymentIntent options...
});
Or when creating a Charge directly:
// Example: Setting receipt email when creating a Charge
const charge = await stripe.charges.create({
amount: 2000,
currency: 'usd',
source: 'tok\_visa',
receipt\_email: '[email protected]',
// other Charge options...
});
Step 6: Customize Email Content through Branding Settings
To further customize the appearance:
Step 7: Test Your Email Receipt Configuration
Before going live, test your email receipt setup:
Step 8: Set Up Receipt Metadata (Advanced)
Add custom data to your receipts using metadata:
// Adding metadata to a PaymentIntent
const paymentIntent = await stripe.paymentIntents.create({
amount: 2000,
currency: 'usd',
receipt\_email: '[email protected]',
metadata: {
order\_id: '6735',
customer\_name: 'John Doe',
product\_details: 'Premium Subscription - Annual'
}
});
This metadata will be available in your Stripe Dashboard and can be included in receipt templates.
Step 9: Configure Webhook Notifications for Email Events (Optional)
Set up webhooks to track email delivery status:
customer.email.created
customer.email.delivered
customer.email.failed
Example webhook handler code:
// Example Express.js webhook handler
const express = require('express');
const app = express();
// This is your Stripe CLI webhook secret for testing
const endpointSecret = 'whsec\_...';
app.post('/webhook', express.raw({type: 'application/json'}), (request, response) => {
const sig = request.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
} catch (err) {
response.status(400).send(`Webhook Error: ${err.message}`);
return;
}
// Handle email events
switch (event.type) {
case 'customer.email.created':
const emailCreated = event.data.object;
console.log('Email created and queued for sending');
break;
case 'customer.email.delivered':
const emailDelivered = event.data.object;
console.log('Email successfully delivered');
break;
case 'customer.email.failed':
const emailFailed = event.data.object;
console.log('Email delivery failed:', emailFailed.failure\_reason);
break;
default:
console.log(`Unhandled event type ${event.type}`);
}
response.send();
});
app.listen(8000, () => console.log('Webhook server running on port 8000'));
Step 10: Monitor Email Performance
Track how your receipt emails are performing:
Conclusion
You've now successfully set up and customized email receipts in Stripe. This feature not only provides customers with confirmation of their purchases but also enhances your brand's professionalism. Remember to regularly review your email templates and performance metrics to ensure they continue to meet your business needs and customer expectations.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.