#CheckMate
1 messages · Page 1 of 1 (latest)
In your tsconfig.json, do you set esModuleInterop to true?
Is it mandatory , It doesn't say so in the readme . https://github.com/stripe/stripe-node/tree/v8.0.1#usage-with-typescript
That's the requirement from TypeScript, not stripe
Oh cool , My bad. I have done it.
But now I get this error
server.ts:8:20 - error TS2351: This expression is not constructable.
Type 'typeof import("stripe")' has no construct signatures.
8 const stripe = new Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc', {
~~~~~~
Found 1 error in server.ts:8
Can you share the code how import Stripe?
This is a minimal version of the code
const express = require('express');
const bodyParser = require('body-parser');
import * as Stripe from 'stripe';
// Initialize Stripe with your API key
const stripe = new Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc', {
apiVersion: '2022-11-15',
}) as Stripe;
const app = express();
app.use(bodyParser.json());
// Define an endpoint to create a payment intent
app.post('/create-payment-intent', async (req, res) => {
try {
const { amount, currency } = req.body;
// Create a payment intent
const paymentIntent = await stripe.paymentIntents.create({
amount,
currency,
});
// Send the client secret to the frontend
res.json({ clientSecret: paymentIntent.client_secret });
} catch (error) {
console.error('Error creating payment intent:', error.message);
res.status(500).json({ error: 'Failed to create payment intent' });
}
});
// Start the server
const port = 3000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});