当我尝试使用stripe.fileUploads.create时,我得到的创建未定义?
错误:TypeError:无法读取未定义的属性“创建”
我使用node.js https://stripe.com/docs/api/files/create
中的stripe / typings库遵循文档中的请求格式/**
* "@types/stripe": "^6.31.23"
* "stripe": "^7.8.0" */
import * as Stripe from 'stripe';
const stripe = new Stripe('mykey');
function uploadFileToStripe(fileUrl:string,fileType:string,fileName:string):Promise<Stripe.fileUploads.IFileUpdate>{
const upload: Promise<Stripe.fileUploads.IFileUpdate> =
stripe.fileUploads.create(
{
file: {
data: fileUrl,
name: fileName,
type: 'image/jpeg',
},
purpose: 'identity_document',
}
);
return upload.then(
(document: Stripe.fileUploads.IFileUpdate) => {
console.log('Document upload ', document);
return document;
}
).catch(
(_error: any) => {
console.log('Error uploading document ', _error);
return _error;
}
);
}
答案 0 :(得分:2)
我认为您没有正确初始化库。
如Stripe文档中所述,不需要类构造函数(“新”):
const stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7dc")
请尝试按以下方式导入库:
import Stripe from 'stripe'
const stripe = Stripe('mykey')
编辑:
请按如下所示导入库:
import { Stripe } from 'stripe';
const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc')
我刚刚在本地测试了代码,并且可以正常工作。
要使用create
方法,您必须访问files
键,因为filesUpload
不存在:
stripe.files.create(...)