@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
45 lines • 1.53 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripe_sales_tax = void 0;
/*
Compute sales tax for a given customer in WA state.
*/
const sales_tax_1 = __importDefault(require("@cocalc/util/stripe/sales-tax"));
const connection_1 = __importDefault(require("./connection"));
async function stripe_sales_tax(customer_id, dbg) {
const conn = await (0, connection_1.default)();
const customer = await conn.customers.retrieve(customer_id);
if (customer.deleted) {
// mainly have this check so Typescript is happy
dbg("customer was deleted");
return 0;
}
if (customer.default_source == null) {
dbg("no default source");
return 0;
}
let zip = undefined;
if (customer.sources != null) {
for (const x of customer.sources.data) {
if (x.id == customer.default_source) {
zip = x.address_zip?.slice(0, 5); // as any due to bug in Stripe's types
break;
}
}
}
if (zip == null) {
return 0;
}
const tax = (0, sales_tax_1.default)(zip);
dbg("tax: ", tax);
return tax;
}
exports.stripe_sales_tax = stripe_sales_tax;
//# sourceMappingURL=sales-tax.js.map