This project demonstrates a basic use case for Stripe Payment Link to create a simple donation page. It utilizes webhooks to integrate Stripe with a Laravel project. Upon successful payment, Stripe sends an event to the Laravel project, which then inserts a new donation record into the database. A custom field, message
, is implemented to allow users to add a message with their donation. This message is also sent to the Laravel project via Stripe's webhook.
- Simple donation page powered by Stripe Payment Link.
- Webhook integration to process successful payments.
- Custom
message
field for donors.
- A Stripe account.
- A configured Payment Link product in your Stripe dashboard.
Follow these steps to run the project locally:
-
Clone the Project
git clone https://github.com/hilmihidyt/stripe-donation cd stripe-donation
-
Configure Environment
- Copy the
.env.example
file to.env
:cp .env.example .env
- Update the
.env
file with your database credentials and Stripe API keys.
- Copy the
-
Run Migrations
php artisan migrate
-
Start the Development Server
php artisan serve
-
Setup Webhook with Ngrok
- Install and run Ngrok:
ngrok http 8000
- Copy the forwarding URL from Ngrok (e.g.,
https://<random-id>.ngrok.io
). - Configure the following webhook endpoints in your Stripe dashboard:
- Event:
charge.succeeded
Endpoint:https://{random-id}.ngrok-free.app/api/donation
- Event:
checkout.session.completed
Endpoint:https://{random-id}.ngrok-free.app/api/checkout-session-completed
- Event:
- Install and run Ngrok:
- A user accesses the donation page and is redirected to Stripe Payment Link.
- The user fills in their donation details, including the custom
message
field. - Upon successful payment, Stripe sends a webhook event to the Laravel backend.
- The Laravel backend processes the webhook event and stores the donation data, including the
message
field, in the database.
- Routes: Handles the webhook endpoint.
- Controllers: Processes the webhook event.
- Migrations: Sets up the database tables for storing donations.
- Ensure your Stripe account and Payment Link are properly configured.
- Ngrok is required for local development to expose your server to the internet.
- Test the webhook endpoint using Stripe's test mode before going live.
- Check the Laravel logs (
storage/logs/laravel.log
) for any errors. - Use Stripe's dashboard to inspect webhook events and responses.