UNPKG

declastruct-stripe-sdk

Version:

declarative control of stripe constructs, via declastruct

33 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setInvoiceVoided = void 0; const helpful_errors_1 = require("helpful-errors"); const visualogic_1 = require("visualogic"); const DeclaredStripeInvoice_1 = require("../../domain/objects/DeclaredStripeInvoice"); const castToDeclaredStripeInvoice_1 = require("../cast/castToDeclaredStripeInvoice"); const getInvoice_1 = require("./getInvoice"); /** * .what = set the status of an invoice to "void" * .what.intent * - marks the invoice as one that does not have to be paid */ exports.setInvoiceVoided = (0, visualogic_1.withLogTrail)(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 issue an invoice that does not exist', { input, invoiceFound, }); // verify it is still in draft mode if (invoiceFound.status === DeclaredStripeInvoice_1.DeclaredStripeInvoiceStatus.void) return invoiceFound; // if its already "void", then this could be an idempotent retry, so just return it if (invoiceFound.status !== DeclaredStripeInvoice_1.DeclaredStripeInvoiceStatus.open) throw new helpful_errors_1.BadRequestError('can not void an invoice that is not in open mode', { invoiceFound }); // otherwise, finalize it const stripeInvoiceUpdated = await context.stripe.invoices.voidInvoice(invoiceFound.id); return (0, castToDeclaredStripeInvoice_1.castToDeclaredStripeInvoice)(stripeInvoiceUpdated); }, { name: (0, visualogic_1.getResourceNameFromFileName)(__filename), }); //# sourceMappingURL=setInvoiceVoided.js.map