#CheckMate

1 messages · Page 1 of 1 (latest)

winter adderBOT
hearty heron
#

In your tsconfig.json, do you set esModuleInterop to true?

light heath
hearty heron
#

That's the requirement from TypeScript, not stripe

light heath
#

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
hearty heron
#

Can you share the code how import Stripe?

light heath
#

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}`);
});

hearty heron
#

Stripe import should be:

import Stripe from 'stripe';
const stripe = new Stripe('sk_test_...', {
  apiVersion: '2022-11-15',
});
#

Can you change the import statement?