我需要将 stripe 导入到我的应用程序中
首先我安装了 stripe npm 包
npm install stripe --save
Stripe 文档说应该在连接 api 之前设置 key 。
在 Node 中它是这样的
var stripe = require('stripe')(' your stripe API key ');
我需要把它转换成 typescript
我尝试了以下方式。但它对我不起作用
import * as stripe from 'stripe';
stripe('sk_test_...')
如果有人可以帮助我解决这个问题,那将对我毫不拖延地继续我的项目有很大帮助。
谢谢
最佳答案
你可以引用GitHub上的repo: https://github.com/stripe/stripe-node
import Stripe from 'stripe';
const stripe = new Stripe('sk_test_...', {
apiVersion: '2020-08-27',
});
const createCustomer = async () => {
const params: Stripe.CustomerCreateParams = {
description: 'test customer',
};
const customer: Stripe.Customer = await stripe.customers.create(params);
console.log(customer.id);
};
createCustomer();
关于node.js - 使用 node js + typescript 导入 strip ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41998980/