"use strict";
/*
Set default payment source for signed in customer.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const create_payment_method_1 = __importDefault(require("@cocalc/server/billing/create-payment-method"));
const get_account_1 = __importDefault(require("lib/account/get-account"));
const get_params_1 = __importDefault(require("lib/api/get-params"));
async function handle(req, res) {
    try {
        res.json(await set(req));
    }
    catch (err) {
        res.json({ error: `${err.message}` });
        return;
    }
}
exports.default = handle;
async function set(req) {
    const account_id = await (0, get_account_1.default)(req);
    if (account_id == null) {
        throw Error("must be signed in to create payment method");
    }
    const { id } = (0, get_params_1.default)(req);
    if (!id) {
        throw Error("must specify the token id");
    }
    await (0, create_payment_method_1.default)(account_id, id);
    return { success: true };
}
//# sourceMappingURL=create-payment-method.js.map