Am正试图向stripe-api发送一个post请求以创建一个新客户。但stripe不断返回Invalid stripe API版本——尽管我从他们那里得到了推荐的最新版本。
以下是我的代码:
import Stripe from 'stripe';
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
const stripe = new Stripe('sk_test_....' || '', {
apiVersion: "2020-08-27",
});
interface ICreateCustomer {
// stripeToken: string;
email: string;
username: string;
}
export const respond = (fulfillmentText: any): any => {
return {
statusCode: 200,
body: JSON.stringify(fulfillmentText),
headers: {
"Access-Control-Allow-Credentials": true,
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json"
}
};
};
export const createCustomer: Handler = async (
event: APIGatewayEvent,
context: Context
) => {
const incoming: ICreateCustomer = JSON.parse(event.body);
const { email, username } = incoming;
try {
//Create Stripe Customer
const customer = await stripe.customers.create({
email,
name: username,
});
return respond(JSON.stringify(customer));
} catch (err) {
return respond(err);
}
};
此解决方案适用于我
- 删除node_module和package-lock.json文件
- npm安装
有关更多详细信息,请参阅https://github.com/stripe/stripe-node/blob/master/examples/webhook-signing/typescript-node-express/express-ts.ts