Prerequisites
Before you begin, ensure you have:- A Stripe account with access to the Dashboard
- A Flex account with API credentials
- Node.js 18.17.1 or higher (for JavaScript/TypeScript implementations)
- An existing web application or checkout flow
Step 1: Create Custom Payment Method in Stripe
1
Navigate to the Stripe Dashboard
Log in to your Stripe Dashboard and navigate to Settings → Payments → Custom Payment Methods.
2
Create a new custom payment method
Click Add custom payment method and configure:
- Display Name: Enter “Flex”
- Logo: Upload the Flex logo
- Ensure the logo is visible against light and dark backgrounds
- Recommended size: At least 32x32 pixels
- Include rounded corners if using a filled background
- For transparent backgrounds, consider the background color for visibility
3
Save and copy the Custom Payment Method ID
After creating the custom payment method, Stripe will generate a unique ID starting with
cpmt_. Copy this ID - you’ll need it for your integration.Example ID format: cpmt_1RFYhqIVh7O1TOu8IP4pAWbmThe custom payment method ID is different from your Stripe API keys. Store it as a constant in your application code.
Step 2: Install Required Dependencies
For JavaScript/TypeScript Projects
Install the Stripe client libraries:Additional Dependencies (Optional)
For form validation and schema management:Step 3: Configure Environment Variables
Create or update your environment configuration file (.env.local for Next.js or .env for other frameworks):
.env.local
Step 4: Create Constants File
Create a file to store your custom payment method ID and other constants:lib/constants.ts
Replace the
FLEX_CUSTOM_PAYMENT_METHOD_ID with the ID you copied from the Stripe Dashboard in Step 1.Step 5: Configure Product and Pricing Data
Example structure - This shows one way to organize product data. Your structure may differ based on your needs:data.json
What you actually need: Data to create Flex checkout sessions. This requires Flex price IDs (from your Flex Dashboard) and product information. Structure this data however works best for your application - JSON file, database, CMS, etc. Flex supports both one-time and recurring payments.
Step 6: Set Up Stripe Server Instance
Create a server-side Stripe instance for backend operations:lib/stripe.ts
Step 7: Set Up Stripe.js Client Instance
Create a client-side Stripe.js instance:lib/get-stripejs.ts
Verification
After completing these steps, verify your setup:- Custom payment method created in Stripe Dashboard
- Custom payment method ID saved in constants file
- Dependencies installed
- Environment variables configured
- Stripe server and client instances created
- Product/pricing data configured
Next Steps
With your environment configured, you’re ready to implement the payment flow. Continue to the Custom Payment Methods guide for detailed implementation instructions.Troubleshooting
Custom payment method not showing in Payment Element
- Verify the custom payment method ID is correct
- Ensure the ID is properly passed to the Elements configuration
- Check that the custom payment method is enabled in your Stripe Dashboard
Environment variables not loading
- Restart your development server after adding environment variables
- Verify the variable names match exactly (including prefixes)
- For Next.js, ensure
.env.localis in your project root
Stripe.js not loading
- Check your browser console for errors
- Verify your publishable key is correct
- Ensure you’re using the correct environment key (test vs. production)