Skip to content

An example which demonstrates how to setup mandates in stripe.

Notifications You must be signed in to change notification settings

orbcorp/stripe-mandate-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stripe India E-Mandate Example

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.

What This Does

  1. Creates a Stripe SetupIntent with India-specific mandate options
  2. Collects payment method details securely using Stripe Elements
  3. Confirms the setup and creates a mandate with the customer's authorization
  4. 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.


Prerequisites

  • Node.js installed on your machine
  • A Stripe account in test mode
  • A test customer created in your Stripe dashboard

Setup Instructions

1. Install Dependencies

npm install

Or if starting from scratch:

npm init -y
npm install express stripe

2. Create a Test Customer

Go to your Stripe Customers page and create a test customer. Copy the customer ID (it looks like cus_xxxxxxxxxxxxx).

3. Configure Customer ID

Open server.js and replace the placeholder customer ID on line 18:

const CUSTOMER_ID = "cus_xxxxxxxxxxxxx"; // Replace with your actual test customer ID

4. Set Your API Keys

Backend (Secret Key)

Go 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_xxxxxxxxxxxxx

Frontend (Publishable Key)

Copy your Publishable key (starts with pk_test_) and update public/index.html on line 18:

const stripe = Stripe("pk_test_xxxxxxxxxxxxx");

5. Run the Server

node server.js

You should see:

Server running at http://localhost:4242
Customer dashboard link:
https://dashboard.stripe.com/test/customers/cus_xxxxxxxxxxxxx

6. Open in Browser

Navigate to http://localhost:4242


Testing the Mandate

Enter Payment Details

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)

Submit the Form

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."

Testing multiple times

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

Verify in Stripe Dashboard

  1. Go to your customer's page in Stripe
  2. Click on the customer you used
  3. 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

Next Steps

For more information, see Stripe's India Mandates documentation.


Troubleshooting

"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.

About

An example which demonstrates how to setup mandates in stripe.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published