{"size": 703, "ext": "js", "max_stars_repo_path": "billing.js", "max_stars_repo_name": "sriramkasyap/serverless-notes", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "billing.js", "max_issues_repo_name": "sriramkasyap/serverless-notes", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "billing.js", "max_forks_repo_name": "sriramkasyap/serverless-notes", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.5652173913, "max_line_length": 66, "alphanum_fraction": 0.6187766714}
import stripePackage from "stripe";
import { calculateCost } from "./libs/billing-lib";
import { success, failure } from "./libs/response";

export async function main(event, context, callback) {
    const stripe = stripePackage(process.env.stripeSecretKey);

    const { source, storage } = JSON.parse(event.body);
    const description = "Charge for Notes Storage";
    const amount = calculateCost(storage);
    try {
        await stripe.charges.create({
            source,
            amount,
            description,
            currency: "inr"
        });
        return success({ status: true });
    } catch (error) {
        return failure({ status: false, message: error.message });
    }
}
