declastruct-stripe-sdk
Version:
declarative control of stripe constructs, via declastruct
25 lines • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendInvoice = void 0;
const helpful_errors_1 = require("helpful-errors");
const DeclaredStripeInvoice_1 = require("../../domain/objects/DeclaredStripeInvoice");
const getInvoice_1 = require("./getInvoice");
const sendInvoice = async (input, context) => {
// find the invoice
const invoiceFound = await (0, getInvoice_1.getInvoice)(input, context);
if (!invoiceFound)
throw new helpful_errors_1.BadRequestError('can not send an invoice that does not exist', {
input,
invoiceFound,
});
// verify it is still in issued mode
if (invoiceFound.status === DeclaredStripeInvoice_1.DeclaredStripeInvoiceStatus.paid)
throw new helpful_errors_1.BadRequestError('should not send invoice that was already paid'); // if its already "paid", then we should throw a bad request, since folks shouldn't ask to resend
if (invoiceFound.status !== DeclaredStripeInvoice_1.DeclaredStripeInvoiceStatus.open)
throw new helpful_errors_1.BadRequestError('can not send an invoice that is not in open mode', { invoiceFound });
// otherwise, send it
const result = await context.stripe.invoices.sendInvoice(invoiceFound.id);
console.log(result);
};
exports.sendInvoice = sendInvoice;
//# sourceMappingURL=sendInvoice.js.map