Always use Stripe in test mode for this example!
This project demonstrates how to create and manage India E-Mandates using Stripe's SetupIntent API. E-Mandates enable recurring or sporadic payments in India, allowing you to charge customers without requiring them to be present for each transaction.
- Creates a Stripe SetupIntent with India-specific mandate options
- Collects payment method details securely using Stripe Elements
- Confirms the setup and creates a mandate with the customer's authorization
- Sets the payment method as the customer's default for future off-session charges
This is useful for subscription services, usage-based billing platforms (like Orb), or any business that needs to charge Indian customers on a recurring basis.
- Node.js installed on your machine
- A Stripe account in test mode
- A test customer created in your Stripe dashboard
npm installOr if starting from scratch:
npm init -y
npm install express stripeGo to your Stripe Customers page and create a test customer. Copy the customer ID (it looks like cus_xxxxxxxxxxxxx).
Open server.js and replace the placeholder customer ID on line 18:
const CUSTOMER_ID = "cus_xxxxxxxxxxxxx"; // Replace with your actual test customer IDGo to your API keys page and copy your Secret key (starts with sk_test_).
Set it as an environment variable:
export STRIPE_SECRET_KEY=sk_test_xxxxxxxxxxxxxCopy your Publishable key (starts with pk_test_) and update public/index.html on line 18:
const stripe = Stripe("pk_test_xxxxxxxxxxxxx");node server.jsYou should see:
Server running at http://localhost:4242
Customer dashboard link:
https://dashboard.stripe.com/test/customers/cus_xxxxxxxxxxxxx
Navigate to http://localhost:4242
Use these test card details:
- Card number:
4000003560000123(India test card) - Expiry date: Any future date (e.g.,
12/31) - CVC: Any 3 digits (e.g.,
123) - Postal code: Any 5 digits (e.g.,
12345)
You will be prompted with a test mandate confirmation. This should just read
Click Setup Mandate. If everything is configured correctly, you should see:
- "Success! Mandate created and set as default payment method."
Unfortunatly this very small example requires you to exit and restart the server after every mandate setup. Simply ctrl+c, and rerun node server.js
- Go to your customer's page in Stripe
- Click on the customer you used
- You should see:
- The payment method listed under "Payment methods"
- In the developers tab, one minute after creating the card, a webhook event fire for
mandate.updated - The payment method set as the default
For more information, see Stripe's India Mandates documentation.
"Customer not found" error: Make sure you've replaced CUSTOMER_ID in server.js with a valid test customer ID from your Stripe dashboard.
"Invalid API key" error: Ensure your STRIPE_SECRET_KEY environment variable is set and you're using a test mode key (starts with sk_test_).
Payment element not showing: Verify your publishable key in public/index.html is correct and in test mode (starts with pk_test_). Check the logs in the terminal.