How to Build a Donation Platform with Stripe: A Step-by-Step Guide

Stripe makes it simple to accept donations online. Whether you’re building for a nonprofit or a personal cause, you can integrate secure payments in just a few steps. This tutorial walks you through the core pieces: a Stripe account, a payment form, server-side handling, and optional extras like recurring donations.

You’ll need basic knowledge of HTML, JavaScript, and a backend language (Node.js examples are used here). Let’s dive in.

Article illustration

1. Set Up a Stripe Account and Get API Keys

Sign up at stripe.com. From the Dashboard, grab your Publishable Key (client-side) and Secret Key (server-side). Keep the secret key safe – never expose it in frontend code.

2. Build the Donation Form (Client-Side)

Create an HTML form with an amount field and a button. Use Stripe’s Elements library to securely collect card details. Initialise Stripe with your publishable key:

const stripe = Stripe('pk_test_...');
const elements = stripe.elements();
const card = elements.create('card');
card.mount('#card-element');

On form submit, trigger a backend call to create a PaymentIntent.

3. Handle PaymentIntent Creation (Server-Side)

Your server (e.g., Express.js) creates a PaymentIntent with the donation amount:

const paymentIntent = await stripe.paymentIntents.create({
  amount: req.body.amount * 100, // cents
  currency: 'usd',
});

Return the client_secret to the frontend. Then confirm the payment client-side:

stripe.confirmCardPayment(clientSecret, { payment_method: { card } });

Handle success: show a thank-you message. Handle failure: prompt the user to retry.

4. Add Recurring Donations and Receipts

For monthly donations, use Stripe’s Subscription API with a fixed price ID. For receipts, Stripe automatically sends email receipts if you set a “Statement descriptor” and enable receipt emails in the Dashboard. You can also listen to payment_intent.succeeded webhooks to send custom messages.

Test everything in Stripe’s test mode before going live.

Conclusion

Building a donation platform with Stripe is straightforward: set up API keys, create a payment form, handle the PaymentIntent, and layer on subscriptions as needed. With less than 100 lines of code you can start accepting donations. Deploy your app and make an impact.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *