Reputation: 205
When i try to use stripe.fileUploads.create i get that create is undefined?
ERROR: TypeError: Cannot read property 'create' of undefined
i followed the request format in the docs using the stripe/typings library in node.js https://stripe.com/docs/api/files/create
/**
* "@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;
}
);
}
Upvotes: 0
Views: 1622
Reputation: 465
I don't think you are initialising the library correctly.
As stated in Stripe's documentation, no class constructor ("new") is necessary:
const stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7dc")
Please try to import the library as follows:
import Stripe from 'stripe'
const stripe = Stripe('mykey')
EDIT:
Please import the library as follows:
import { Stripe } from 'stripe';
const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc')
I've just tested the code locally and it works.
To use the create
method you have to access the files
key as filesUpload
does not exist:
stripe.files.create(...)
Upvotes: 3