node.js - 使用 node js + typescript 导入 strip

标签 node.js typescript stripe-payments

我需要将 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/

相关文章:

javascript - 使用 Facebook Live API 创建实时视频对象时的隐私设置

javascript - Node.js 请求 - 无法获取 REST 响应 (JSON) 的属性

<script> 标签中的 Javascript 变量

node.js - 类型错误 : Cannot read properties of undefined (reading 'listen' ) when testing with Jest, super 测试、Express、Typescript

ios - 应用内购买动态订阅价格

forms - 使用 Angular 6 和 NodeJs 自定义 Stripe 结账表单

javascript - Electron JS,使用 Express 后端和单独的 html 前端启动应用程序

javascript - 提取现有 javascript 文件中数组的值

javascript - typescript 无法访问 JSON 对象 (Angular2)

html - Angular 8 通过只有 id 从输入中获取值