The code in the comment block is not functioning properly when placed inside an if statement.
It seems that the issue may be related to its position before a return statement, so I am looking for a way to ensure it completes running before the return is called.
I have attempted using let {cool} = await ....
but have had no success.
The goal is to simply copy and paste the code snippet from above into the if statement.
let AWS = require("aws-sdk");
AWS.config.region = "us-east-1";
let lambda = new AWS.Lambda();
exports.handler = async (event) => {
////----------------------------THIS CODE WORKS HERE-------------------------------------------///////
let PayloadObj = {
amount: String(event["amount"]),
email: String(event["email"]),
};
let Payload = JSON.stringify(PayloadObj);
let params = {
FunctionName: "lambda-2", // the lambda function we are invoking
Payload: Payload,
};
let { cool } = lambda.invoke(params, function (err, data) {
if (err) {
console.log(err);
} else {
console.log(data.Payload);
}
});
//-------------------------------------END of this CODE --------------------------------------////
// TODO implement
const stripe = require("stripe")("sk_test");
let amount = event["amount"];
let token = event["token"];
let { status } = await stripe.charges.create({
amount: amount * 100,
currency: "usd",
description: amount,
source: token,
});
if (status === "succeeded") {
//--------------------------------Same code here!-------------------------------///
// same code from above
//---------------------------Does not work!!------------------------------------------//
const response = {
statusCode: 200,
body: JSON.stringify(status),
};
return response;
} else {
const response = {
statusCode: 402,
body: JSON.stringify("Payment Failed"),
};
return response;
}
};