@voyantjs/finance 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -4
- package/dist/payment-policy.d.ts +113 -0
- package/dist/payment-policy.d.ts.map +1 -0
- package/dist/payment-policy.js +193 -0
- package/dist/routes-documents.d.ts +2 -2
- package/dist/routes-public.d.ts +12 -12
- package/dist/routes.d.ts +530 -31
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +120 -5
- package/dist/schema.d.ts +538 -6
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +84 -0
- package/dist/service-issue.d.ts +108 -0
- package/dist/service-issue.d.ts.map +1 -0
- package/dist/service-issue.js +57 -0
- package/dist/service-public.d.ts +5 -5
- package/dist/service.d.ts +257 -37
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +278 -20
- package/dist/validation-billing.d.ts +109 -0
- package/dist/validation-billing.d.ts.map +1 -1
- package/dist/validation-billing.js +58 -0
- package/dist/validation-payments.d.ts +16 -16
- package/dist/validation-public.d.ts +3 -3
- package/dist/validation-shared.d.ts +5 -5
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -19,13 +19,15 @@ export interface FinanceHonoModuleOptions extends FinanceRuntimeOptions, PublicF
|
|
|
19
19
|
}
|
|
20
20
|
export declare function createFinanceHonoModule(options?: FinanceHonoModuleOptions): HonoModule;
|
|
21
21
|
export declare const financeHonoModule: HonoModule;
|
|
22
|
+
export type { ComputedScheduleEntry, ComputeScheduleInput, DepositKind, DepositRule, PaymentPolicy, PaymentPolicyCascadeLayers, PaymentPolicySource, PaymentScheduleEntryType, ResolvedPaymentPolicy, } from "./payment-policy.js";
|
|
23
|
+
export { computePaymentSchedule, isPaymentPolicyEmpty, noDepositPolicy, policyShouldRequireFullPayment, resolveEffectivePaymentPolicy, } from "./payment-policy.js";
|
|
22
24
|
export { buildFinanceRouteRuntime, FINANCE_ROUTE_RUNTIME_CONTAINER_KEY, type FinanceRouteRuntime, type FinanceRuntimeOptions, } from "./route-runtime.js";
|
|
23
25
|
export { bookingsQuickCreateExtension } from "./routes-bookings-quick-create.js";
|
|
24
26
|
export { createFinanceAdminDocumentRoutes, type FinanceDocumentRouteOptions, type InvoiceDocumentGenerator, } from "./routes-documents.js";
|
|
25
27
|
export { createFinanceAdminSettlementRoutes, type FinanceSettlementRouteOptions, type InvoiceSettlementPoller, } from "./routes-settlement.js";
|
|
26
|
-
export type { BookingGuarantee, BookingItemCommission, BookingItemTaxLine, BookingPaymentSchedule, CreditNote, CreditNoteLineItem, FinanceNote, Invoice, InvoiceExternalRef, InvoiceLineItem, InvoiceNumberSeries, InvoiceRendition, InvoiceTemplate, NewBookingGuarantee, NewBookingItemCommission, NewBookingItemTaxLine, NewBookingPaymentSchedule, NewCreditNote, NewCreditNoteLineItem, NewFinanceNote, NewInvoice, NewInvoiceExternalRef, NewInvoiceLineItem, NewInvoiceNumberSeries, NewInvoiceRendition, NewInvoiceTemplate, NewPayment, NewPaymentAuthorization, NewPaymentCapture, NewPaymentInstrument, NewPaymentSession, NewSupplierPayment, NewTaxRegime, NewVoucher, NewVoucherRedemption, Payment, PaymentAuthorization, PaymentCapture, PaymentInstrument, PaymentSession, SupplierPayment, TaxRegime, Voucher, VoucherRedemption, } from "./schema.js";
|
|
27
|
-
export { bookingGuarantees, bookingItemCommissions, bookingItemTaxLines, bookingPaymentSchedules, creditNoteLineItems, creditNotes, financeNotes, invoiceExternalRefs, invoiceLineItems, invoiceNumberSeries, invoiceRenditions, invoices, invoiceTemplates, paymentAuthorizations, paymentCaptures, paymentInstruments, paymentSessions, payments, supplierPayments, taxRegimes, voucherRedemptions, voucherSourceTypeEnum, voucherStatusEnum, vouchers, } from "./schema.js";
|
|
28
|
-
export type { InvoiceFromBookingData } from "./service.js";
|
|
28
|
+
export type { BookingGuarantee, BookingItemCommission, BookingItemTaxLine, BookingPaymentSchedule, CreditNote, CreditNoteLineItem, FinanceNote, Invoice, InvoiceExternalRef, InvoiceLineItem, InvoiceNumberSeries, InvoiceRendition, InvoiceTemplate, NewBookingGuarantee, NewBookingItemCommission, NewBookingItemTaxLine, NewBookingPaymentSchedule, NewCreditNote, NewCreditNoteLineItem, NewFinanceNote, NewInvoice, NewInvoiceExternalRef, NewInvoiceLineItem, NewInvoiceNumberSeries, NewInvoiceRendition, NewInvoiceTemplate, NewPayment, NewPaymentAuthorization, NewPaymentCapture, NewPaymentInstrument, NewPaymentSession, NewSupplierPayment, NewTaxClass, NewTaxRegime, NewVoucher, NewVoucherRedemption, Payment, PaymentAuthorization, PaymentCapture, PaymentInstrument, PaymentSession, SupplierPayment, TaxClass, TaxRegime, Voucher, VoucherRedemption, } from "./schema.js";
|
|
29
|
+
export { bookingGuarantees, bookingItemCommissions, bookingItemTaxLines, bookingPaymentSchedules, creditNoteLineItems, creditNotes, financeNotes, invoiceExternalRefs, invoiceLineItems, invoiceNumberSeries, invoiceRenditions, invoices, invoiceTemplates, paymentAuthorizations, paymentCaptures, paymentInstruments, paymentSessions, payments, supplierPayments, taxClasses, taxPolicyProfiles, taxPolicyRules, taxRegimes, voucherRedemptions, voucherSourceTypeEnum, voucherStatusEnum, vouchers, } from "./schema.js";
|
|
30
|
+
export type { CreateInvoiceFromBookingInput, InvoiceFromBookingData } from "./service.js";
|
|
29
31
|
export { financeService, renderInvoiceBody } from "./service.js";
|
|
30
32
|
export type { BookingDualCreatedEvent, DualCreateBookingInput, DualCreateBookingOutcome, DualCreateBookingResult, DualCreateBookingRuntime, } from "./service-bookings-dual-create.js";
|
|
31
33
|
export { dualCreateBooking, dualCreateBookingSchema, } from "./service-bookings-dual-create.js";
|
|
@@ -33,12 +35,14 @@ export type { BookingQuickCreatedEvent, BookingQuickCreateRuntime, QuickCreateBo
|
|
|
33
35
|
export { quickCreateBooking, quickCreateBookingSchema, } from "./service-bookings-quick-create.js";
|
|
34
36
|
export type { GeneratedInvoiceDocumentRecord, GeneratedInvoiceRenditionArtifact, InvoiceDocumentGeneratedEvent, InvoiceDocumentGeneratorContext, InvoiceDocumentRuntimeOptions, StorageBackedInvoiceDocumentGeneratorOptions, StorageBackedInvoiceDocumentSerializer, StorageBackedInvoiceDocumentUpload, } from "./service-documents.js";
|
|
35
37
|
export { createPdfInvoiceDocumentGenerator, createStorageBackedInvoiceDocumentGenerator, defaultPdfInvoiceDocumentSerializer, defaultStorageBackedInvoiceDocumentSerializer, financeDocumentsService, } from "./service-documents.js";
|
|
38
|
+
export type { InvoiceIssuedEvent, InvoiceIssueRuntime } from "./service-issue.js";
|
|
39
|
+
export { issueInvoiceFromBooking, issueProformaFromBooking } from "./service-issue.js";
|
|
36
40
|
export type { FinanceSettlementRuntimeOptions, InvoiceSettledEvent, InvoiceSettlementPollerContext, InvoiceSettlementPollerResult, } from "./service-settlement.js";
|
|
37
41
|
export { financeSettlementService } from "./service-settlement.js";
|
|
38
42
|
export { VoucherServiceError, vouchersService } from "./service-vouchers.js";
|
|
39
43
|
export { migrateVouchersFromPaymentInstruments, type VoucherMigrationOptions, type VoucherMigrationResult, type VoucherMigrationSkip, } from "./service-vouchers-migration.js";
|
|
40
44
|
export type { GeneratedInvoiceDocumentResult, GenerateInvoiceDocumentInput, PolledInvoiceSettlementResult, PollInvoiceSettlementInput, } from "./validation.js";
|
|
41
|
-
export { agingReportQuerySchema, allocateInvoiceNumberInputSchema, applyDefaultBookingPaymentPlanSchema, cancelPaymentSessionSchema, completePaymentSessionSchema, createPaymentSessionFromGuaranteeSchema, createPaymentSessionFromInvoiceSchema, createPaymentSessionFromScheduleSchema, expirePaymentSessionSchema, failPaymentSessionSchema, generatedInvoiceDocumentResultSchema, generateInvoiceDocumentInputSchema, insertBookingGuaranteeSchema, insertBookingItemCommissionSchema, insertBookingItemTaxLineSchema, insertBookingPaymentScheduleSchema, insertCreditNoteLineItemSchema, insertCreditNoteSchema, insertFinanceNoteSchema, insertInvoiceExternalRefSchema, insertInvoiceLineItemSchema, insertInvoiceNumberSeriesSchema, insertInvoiceRenditionSchema, insertInvoiceSchema, insertInvoiceTemplateSchema, insertPaymentAuthorizationSchema, insertPaymentCaptureSchema, insertPaymentInstrumentSchema, insertPaymentSchema, insertPaymentSessionSchema, insertSupplierPaymentSchema, insertTaxRegimeSchema, invoiceFromBookingSchema, invoiceListQuerySchema, invoiceNumberSeriesListQuerySchema, invoiceTemplateListQuerySchema, markPaymentSessionRequiresRedirectSchema, paymentAuthorizationListQuerySchema, paymentCaptureListQuerySchema, paymentInstrumentListQuerySchema, paymentSessionListQuerySchema, polledInvoiceSettlementProviderResultSchema, polledInvoiceSettlementResultSchema, pollInvoiceSettlementInputSchema, profitabilityQuerySchema, renderInvoiceInputSchema, revenueReportQuerySchema, supplierPaymentListQuerySchema, taxRegimeListQuerySchema, updateBookingGuaranteeSchema, updateBookingItemCommissionSchema, updateBookingItemTaxLineSchema, updateBookingPaymentScheduleSchema, updateCreditNoteLineItemSchema, updateCreditNoteSchema, updateInvoiceExternalRefSchema, updateInvoiceLineItemSchema, updateInvoiceNumberSeriesSchema, updateInvoiceRenditionSchema, updateInvoiceSchema, updateInvoiceTemplateSchema, updatePaymentAuthorizationSchema, updatePaymentCaptureSchema, updatePaymentInstrumentSchema, updatePaymentSchema, updatePaymentSessionSchema, updateSupplierPaymentSchema, updateTaxRegimeSchema, } from "./validation.js";
|
|
45
|
+
export { agingReportQuerySchema, allocateInvoiceNumberInputSchema, applyDefaultBookingPaymentPlanSchema, cancelPaymentSessionSchema, completePaymentSessionSchema, createPaymentSessionFromGuaranteeSchema, createPaymentSessionFromInvoiceSchema, createPaymentSessionFromScheduleSchema, expirePaymentSessionSchema, failPaymentSessionSchema, generatedInvoiceDocumentResultSchema, generateInvoiceDocumentInputSchema, insertBookingGuaranteeSchema, insertBookingItemCommissionSchema, insertBookingItemTaxLineSchema, insertBookingPaymentScheduleSchema, insertCreditNoteLineItemSchema, insertCreditNoteSchema, insertFinanceNoteSchema, insertInvoiceExternalRefSchema, insertInvoiceLineItemSchema, insertInvoiceNumberSeriesSchema, insertInvoiceRenditionSchema, insertInvoiceSchema, insertInvoiceTemplateSchema, insertPaymentAuthorizationSchema, insertPaymentCaptureSchema, insertPaymentInstrumentSchema, insertPaymentSchema, insertPaymentSessionSchema, insertSupplierPaymentSchema, insertTaxClassSchema, insertTaxPolicyProfileSchema, insertTaxPolicyRuleSchema, insertTaxRegimeSchema, invoiceFromBookingSchema, invoiceListQuerySchema, invoiceNumberSeriesListQuerySchema, invoiceTemplateListQuerySchema, markPaymentSessionRequiresRedirectSchema, paymentAuthorizationListQuerySchema, paymentCaptureListQuerySchema, paymentInstrumentListQuerySchema, paymentSessionListQuerySchema, polledInvoiceSettlementProviderResultSchema, polledInvoiceSettlementResultSchema, pollInvoiceSettlementInputSchema, profitabilityQuerySchema, renderInvoiceInputSchema, revenueReportQuerySchema, supplierPaymentListQuerySchema, taxClassListQuerySchema, taxPolicyProfileListQuerySchema, taxPolicyRuleListQuerySchema, taxRegimeListQuerySchema, updateBookingGuaranteeSchema, updateBookingItemCommissionSchema, updateBookingItemTaxLineSchema, updateBookingPaymentScheduleSchema, updateCreditNoteLineItemSchema, updateCreditNoteSchema, updateInvoiceExternalRefSchema, updateInvoiceLineItemSchema, updateInvoiceNumberSeriesSchema, updateInvoiceRenditionSchema, updateInvoiceSchema, updateInvoiceTemplateSchema, updatePaymentAuthorizationSchema, updatePaymentCaptureSchema, updatePaymentInstrumentSchema, updatePaymentSchema, updatePaymentSessionSchema, updateSupplierPaymentSchema, updateTaxClassSchema, updateTaxPolicyProfileSchema, updateTaxPolicyRuleSchema, updateTaxRegimeSchema, } from "./validation.js";
|
|
42
46
|
export type { PublicBookingFinanceDocuments, PublicBookingFinancePayments, PublicBookingPaymentOptions, PublicFinanceBookingDocument, PublicFinanceBookingPayment, PublicFinanceDocumentLookup, PublicFinanceDocumentLookupQuery, PublicPaymentOptionsQuery, PublicPaymentSession, PublicStartPaymentSessionInput, PublicValidateVoucherInput, PublicVoucherValidationResult, } from "./validation-public.js";
|
|
43
47
|
export { publicBookingFinanceDocumentsSchema, publicBookingFinancePaymentsSchema, publicBookingPaymentOptionsSchema, publicFinanceBookingDocumentSchema, publicFinanceBookingPaymentSchema, publicFinanceDocumentAvailabilitySchema, publicFinanceDocumentFormatSchema, publicFinanceDocumentLookupQuerySchema, publicFinanceDocumentLookupSchema, publicFinanceInvoiceTypeSchema, publicPaymentOptionsQuerySchema, publicPaymentSessionSchema, publicStartPaymentSessionSchema, publicValidateVoucherSchema, publicVoucherValidationSchema, } from "./validation-public.js";
|
|
44
48
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGvD,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAA6B,KAAK,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EACL,yBAAyB,EACzB,KAAK,yBAAyB,EAC9B,mBAAmB,GACpB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,KAAK,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE5F,eAAO,MAAM,eAAe,EAAE,kBAK7B,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,kBAKrC,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,kBAKhC,CAAA;AAED,eAAO,MAAM,eAAe;;;;CAI3B,CAAA;AAED,eAAO,M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AC/B,4BAA4B,EAC5B,wBAAwB,EACxB,4BAA4B,EAC5B,iCAAiC,EACjC,8BAA8B,EAC9B,kCAAkC,EAClC,8BAA8B,EAC9B,sBAAsB,EACtB,8BAA8B,EAC9B,2BAA2B,EAC3B,+BAA+B,EAC/B,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,gCAAgC,EAChC,0BAA0B,EAC1B,6BAA6B,EAC7B,mBAAmB,EACnB,0BAA0B,EAC1B,2BAA2B,EAC3B,oBAAoB,EACpB,4BAA4B,EAC5B,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iBAAiB,CAAA;AACxB,YAAY,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,2BAA2B,EAC3B,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,8BAA8B,EAC9B,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,mCAAmC,EACnC,kCAAkC,EAClC,iCAAiC,EACjC,kCAAkC,EAClC,iCAAiC,EACjC,uCAAuC,EACvC,iCAAiC,EACjC,sCAAsC,EACtC,iCAAiC,EACjC,8BAA8B,EAC9B,+BAA+B,EAC/B,0BAA0B,EAC1B,+BAA+B,EAC/B,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,wBAAwB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -40,8 +40,16 @@ export function createFinanceHonoModule(options = {}) {
|
|
|
40
40
|
.route("/", createFinanceAdminSettlementRoutes(options));
|
|
41
41
|
const module = {
|
|
42
42
|
...financeModule,
|
|
43
|
-
bootstrap: ({ bindings, container }) => {
|
|
44
|
-
|
|
43
|
+
bootstrap: ({ bindings, container, eventBus }) => {
|
|
44
|
+
const runtime = buildFinanceRouteRuntime(bindings, options);
|
|
45
|
+
// Wire the framework's eventBus into the route runtime so subscribers
|
|
46
|
+
// (notably the storefront's checkout-finalize workflow on
|
|
47
|
+
// `payment.completed`) actually receive emissions from
|
|
48
|
+
// `financeService.completePaymentSession`. Without this, the Netopia
|
|
49
|
+
// webhook silently no-ops because the runtime has no bus attached.
|
|
50
|
+
if (!runtime.eventBus && eventBus)
|
|
51
|
+
runtime.eventBus = eventBus;
|
|
52
|
+
container.register(FINANCE_ROUTE_RUNTIME_CONTAINER_KEY, runtime);
|
|
45
53
|
},
|
|
46
54
|
};
|
|
47
55
|
return {
|
|
@@ -52,17 +60,19 @@ export function createFinanceHonoModule(options = {}) {
|
|
|
52
60
|
};
|
|
53
61
|
}
|
|
54
62
|
export const financeHonoModule = createFinanceHonoModule();
|
|
63
|
+
export { computePaymentSchedule, isPaymentPolicyEmpty, noDepositPolicy, policyShouldRequireFullPayment, resolveEffectivePaymentPolicy, } from "./payment-policy.js";
|
|
55
64
|
export { buildFinanceRouteRuntime, FINANCE_ROUTE_RUNTIME_CONTAINER_KEY, } from "./route-runtime.js";
|
|
56
65
|
export { bookingsQuickCreateExtension } from "./routes-bookings-quick-create.js";
|
|
57
66
|
export { createFinanceAdminDocumentRoutes, } from "./routes-documents.js";
|
|
58
67
|
export { createFinanceAdminSettlementRoutes, } from "./routes-settlement.js";
|
|
59
|
-
export { bookingGuarantees, bookingItemCommissions, bookingItemTaxLines, bookingPaymentSchedules, creditNoteLineItems, creditNotes, financeNotes, invoiceExternalRefs, invoiceLineItems, invoiceNumberSeries, invoiceRenditions, invoices, invoiceTemplates, paymentAuthorizations, paymentCaptures, paymentInstruments, paymentSessions, payments, supplierPayments, taxRegimes, voucherRedemptions, voucherSourceTypeEnum, voucherStatusEnum, vouchers, } from "./schema.js";
|
|
68
|
+
export { bookingGuarantees, bookingItemCommissions, bookingItemTaxLines, bookingPaymentSchedules, creditNoteLineItems, creditNotes, financeNotes, invoiceExternalRefs, invoiceLineItems, invoiceNumberSeries, invoiceRenditions, invoices, invoiceTemplates, paymentAuthorizations, paymentCaptures, paymentInstruments, paymentSessions, payments, supplierPayments, taxClasses, taxPolicyProfiles, taxPolicyRules, taxRegimes, voucherRedemptions, voucherSourceTypeEnum, voucherStatusEnum, vouchers, } from "./schema.js";
|
|
60
69
|
export { financeService, renderInvoiceBody } from "./service.js";
|
|
61
70
|
export { dualCreateBooking, dualCreateBookingSchema, } from "./service-bookings-dual-create.js";
|
|
62
71
|
export { quickCreateBooking, quickCreateBookingSchema, } from "./service-bookings-quick-create.js";
|
|
63
72
|
export { createPdfInvoiceDocumentGenerator, createStorageBackedInvoiceDocumentGenerator, defaultPdfInvoiceDocumentSerializer, defaultStorageBackedInvoiceDocumentSerializer, financeDocumentsService, } from "./service-documents.js";
|
|
73
|
+
export { issueInvoiceFromBooking, issueProformaFromBooking } from "./service-issue.js";
|
|
64
74
|
export { financeSettlementService } from "./service-settlement.js";
|
|
65
75
|
export { VoucherServiceError, vouchersService } from "./service-vouchers.js";
|
|
66
76
|
export { migrateVouchersFromPaymentInstruments, } from "./service-vouchers-migration.js";
|
|
67
|
-
export { agingReportQuerySchema, allocateInvoiceNumberInputSchema, applyDefaultBookingPaymentPlanSchema, cancelPaymentSessionSchema, completePaymentSessionSchema, createPaymentSessionFromGuaranteeSchema, createPaymentSessionFromInvoiceSchema, createPaymentSessionFromScheduleSchema, expirePaymentSessionSchema, failPaymentSessionSchema, generatedInvoiceDocumentResultSchema, generateInvoiceDocumentInputSchema, insertBookingGuaranteeSchema, insertBookingItemCommissionSchema, insertBookingItemTaxLineSchema, insertBookingPaymentScheduleSchema, insertCreditNoteLineItemSchema, insertCreditNoteSchema, insertFinanceNoteSchema, insertInvoiceExternalRefSchema, insertInvoiceLineItemSchema, insertInvoiceNumberSeriesSchema, insertInvoiceRenditionSchema, insertInvoiceSchema, insertInvoiceTemplateSchema, insertPaymentAuthorizationSchema, insertPaymentCaptureSchema, insertPaymentInstrumentSchema, insertPaymentSchema, insertPaymentSessionSchema, insertSupplierPaymentSchema, insertTaxRegimeSchema, invoiceFromBookingSchema, invoiceListQuerySchema, invoiceNumberSeriesListQuerySchema, invoiceTemplateListQuerySchema, markPaymentSessionRequiresRedirectSchema, paymentAuthorizationListQuerySchema, paymentCaptureListQuerySchema, paymentInstrumentListQuerySchema, paymentSessionListQuerySchema, polledInvoiceSettlementProviderResultSchema, polledInvoiceSettlementResultSchema, pollInvoiceSettlementInputSchema, profitabilityQuerySchema, renderInvoiceInputSchema, revenueReportQuerySchema, supplierPaymentListQuerySchema, taxRegimeListQuerySchema, updateBookingGuaranteeSchema, updateBookingItemCommissionSchema, updateBookingItemTaxLineSchema, updateBookingPaymentScheduleSchema, updateCreditNoteLineItemSchema, updateCreditNoteSchema, updateInvoiceExternalRefSchema, updateInvoiceLineItemSchema, updateInvoiceNumberSeriesSchema, updateInvoiceRenditionSchema, updateInvoiceSchema, updateInvoiceTemplateSchema, updatePaymentAuthorizationSchema, updatePaymentCaptureSchema, updatePaymentInstrumentSchema, updatePaymentSchema, updatePaymentSessionSchema, updateSupplierPaymentSchema, updateTaxRegimeSchema, } from "./validation.js";
|
|
77
|
+
export { agingReportQuerySchema, allocateInvoiceNumberInputSchema, applyDefaultBookingPaymentPlanSchema, cancelPaymentSessionSchema, completePaymentSessionSchema, createPaymentSessionFromGuaranteeSchema, createPaymentSessionFromInvoiceSchema, createPaymentSessionFromScheduleSchema, expirePaymentSessionSchema, failPaymentSessionSchema, generatedInvoiceDocumentResultSchema, generateInvoiceDocumentInputSchema, insertBookingGuaranteeSchema, insertBookingItemCommissionSchema, insertBookingItemTaxLineSchema, insertBookingPaymentScheduleSchema, insertCreditNoteLineItemSchema, insertCreditNoteSchema, insertFinanceNoteSchema, insertInvoiceExternalRefSchema, insertInvoiceLineItemSchema, insertInvoiceNumberSeriesSchema, insertInvoiceRenditionSchema, insertInvoiceSchema, insertInvoiceTemplateSchema, insertPaymentAuthorizationSchema, insertPaymentCaptureSchema, insertPaymentInstrumentSchema, insertPaymentSchema, insertPaymentSessionSchema, insertSupplierPaymentSchema, insertTaxClassSchema, insertTaxPolicyProfileSchema, insertTaxPolicyRuleSchema, insertTaxRegimeSchema, invoiceFromBookingSchema, invoiceListQuerySchema, invoiceNumberSeriesListQuerySchema, invoiceTemplateListQuerySchema, markPaymentSessionRequiresRedirectSchema, paymentAuthorizationListQuerySchema, paymentCaptureListQuerySchema, paymentInstrumentListQuerySchema, paymentSessionListQuerySchema, polledInvoiceSettlementProviderResultSchema, polledInvoiceSettlementResultSchema, pollInvoiceSettlementInputSchema, profitabilityQuerySchema, renderInvoiceInputSchema, revenueReportQuerySchema, supplierPaymentListQuerySchema, taxClassListQuerySchema, taxPolicyProfileListQuerySchema, taxPolicyRuleListQuerySchema, taxRegimeListQuerySchema, updateBookingGuaranteeSchema, updateBookingItemCommissionSchema, updateBookingItemTaxLineSchema, updateBookingPaymentScheduleSchema, updateCreditNoteLineItemSchema, updateCreditNoteSchema, updateInvoiceExternalRefSchema, updateInvoiceLineItemSchema, updateInvoiceNumberSeriesSchema, updateInvoiceRenditionSchema, updateInvoiceSchema, updateInvoiceTemplateSchema, updatePaymentAuthorizationSchema, updatePaymentCaptureSchema, updatePaymentInstrumentSchema, updatePaymentSchema, updatePaymentSessionSchema, updateSupplierPaymentSchema, updateTaxClassSchema, updateTaxPolicyProfileSchema, updateTaxPolicyRuleSchema, updateTaxRegimeSchema, } from "./validation.js";
|
|
68
78
|
export { publicBookingFinanceDocumentsSchema, publicBookingFinancePaymentsSchema, publicBookingPaymentOptionsSchema, publicFinanceBookingDocumentSchema, publicFinanceBookingPaymentSchema, publicFinanceDocumentAvailabilitySchema, publicFinanceDocumentFormatSchema, publicFinanceDocumentLookupQuerySchema, publicFinanceDocumentLookupSchema, publicFinanceInvoiceTypeSchema, publicPaymentOptionsQuerySchema, publicPaymentSessionSchema, publicStartPaymentSessionSchema, publicValidateVoucherSchema, publicVoucherValidationSchema, } from "./validation-public.js";
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer-facing payment policy primitive.
|
|
3
|
+
*
|
|
4
|
+
* Decides how to split a booking total into a payment schedule: full
|
|
5
|
+
* payment up-front, or a deposit now + balance due before departure.
|
|
6
|
+
* Pure function — no DB, no IO. Two policies in (the operator default
|
|
7
|
+
* + any per-supplier / per-category / per-listing override) plus the
|
|
8
|
+
* booking total + departure date, schedule rows out.
|
|
9
|
+
*
|
|
10
|
+
* Behaviour:
|
|
11
|
+
*
|
|
12
|
+
* 1. If `policy.deposit.kind === "none"` → one row, full total, due
|
|
13
|
+
* immediately. Skips the rest of the rules.
|
|
14
|
+
* 2. If departure is too close (`< minDaysBeforeDepartureForDeposit`
|
|
15
|
+
* from today) → also full payment now. The agency doesn't have
|
|
16
|
+
* time to chase a balance.
|
|
17
|
+
* 3. Otherwise → two rows:
|
|
18
|
+
* - deposit row, due today, amount = percent × total OR fixed
|
|
19
|
+
* cents (capped at total).
|
|
20
|
+
* - balance row, amount = total − deposit, due
|
|
21
|
+
* `balanceDueDaysBeforeDeparture` before departure, but never
|
|
22
|
+
* sooner than `balanceDueMinDaysFromNow` days from now.
|
|
23
|
+
*
|
|
24
|
+
* Cascade resolution lives in {@link resolveEffectivePaymentPolicy}:
|
|
25
|
+
* the most-specific layer that defines a policy wins (booking >
|
|
26
|
+
* listing > category > supplier > operator default), no field-level
|
|
27
|
+
* merging — so the audit trail is "this whole policy applied".
|
|
28
|
+
*/
|
|
29
|
+
export type DepositKind = "none" | "percent" | "fixed_cents";
|
|
30
|
+
export interface DepositRule {
|
|
31
|
+
kind: DepositKind;
|
|
32
|
+
/** Required when `kind === "percent"`. 0–100 inclusive. */
|
|
33
|
+
percent?: number;
|
|
34
|
+
/** Required when `kind === "fixed_cents"`. Capped at total. */
|
|
35
|
+
amountCents?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface PaymentPolicy {
|
|
38
|
+
deposit: DepositRule;
|
|
39
|
+
/** Below this many days before departure, deposits are rejected and
|
|
40
|
+
* the booking is invoiced for the full amount up-front. */
|
|
41
|
+
minDaysBeforeDepartureForDeposit: number;
|
|
42
|
+
/** When the balance is due (days BEFORE departure). */
|
|
43
|
+
balanceDueDaysBeforeDeparture: number;
|
|
44
|
+
/** Floor on the balance due date so it's never sooner than this
|
|
45
|
+
* many days from "now". Protects the customer from a tight squeeze
|
|
46
|
+
* when departure is barely outside the deposit window. */
|
|
47
|
+
balanceDueMinDaysFromNow: number;
|
|
48
|
+
}
|
|
49
|
+
/** Default policy: 100% up-front, no deposit. Safe fallback for
|
|
50
|
+
* agencies that haven't configured anything yet. */
|
|
51
|
+
export declare const noDepositPolicy: PaymentPolicy;
|
|
52
|
+
export type PaymentScheduleEntryType = "deposit" | "balance" | "full";
|
|
53
|
+
export interface ComputedScheduleEntry {
|
|
54
|
+
scheduleType: PaymentScheduleEntryType;
|
|
55
|
+
amountCents: number;
|
|
56
|
+
currency: string;
|
|
57
|
+
/** ISO `YYYY-MM-DD`. */
|
|
58
|
+
dueDate: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ComputeScheduleInput {
|
|
61
|
+
totalCents: number;
|
|
62
|
+
currency: string;
|
|
63
|
+
/** ISO `YYYY-MM-DD` (or full ISO string — we only look at the date). */
|
|
64
|
+
departureDate: string | null | undefined;
|
|
65
|
+
/** Defaults to `new Date()`. Injectable for deterministic tests. */
|
|
66
|
+
today?: Date;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Compute the customer-facing payment schedule for a booking.
|
|
70
|
+
*
|
|
71
|
+
* Always returns at least one row. When the policy resolves to no
|
|
72
|
+
* deposit (or the gate denies one), the single row is a `full`
|
|
73
|
+
* scheduled for today.
|
|
74
|
+
*/
|
|
75
|
+
export declare function computePaymentSchedule(input: ComputeScheduleInput, policy: PaymentPolicy): ComputedScheduleEntry[];
|
|
76
|
+
/** True when this policy is empty / "inherit from parent". */
|
|
77
|
+
export declare function isPaymentPolicyEmpty(policy: PaymentPolicy | null | undefined): boolean;
|
|
78
|
+
export type PaymentPolicySource = "booking" | "listing" | "category" | "supplier" | "operator_default";
|
|
79
|
+
export interface PaymentPolicyCascadeLayers {
|
|
80
|
+
bookingPolicy?: PaymentPolicy | null;
|
|
81
|
+
listingPolicy?: PaymentPolicy | null;
|
|
82
|
+
categoryPolicy?: PaymentPolicy | null;
|
|
83
|
+
supplierPolicy?: PaymentPolicy | null;
|
|
84
|
+
operatorDefault: PaymentPolicy;
|
|
85
|
+
}
|
|
86
|
+
export interface ResolvedPaymentPolicy {
|
|
87
|
+
policy: PaymentPolicy;
|
|
88
|
+
source: PaymentPolicySource;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Most-specific-wins cascade. Returns both the policy and which
|
|
92
|
+
* layer it came from so contracts and ops UIs can show the trace.
|
|
93
|
+
*
|
|
94
|
+
* A layer is "set" when it's not null/undefined AND not effectively
|
|
95
|
+
* empty (deposit kind === "none" with no other meaningful fields).
|
|
96
|
+
* That way operators who declare an explicit "no deposit" policy on
|
|
97
|
+
* a supplier override their parent's "50% deposit" — they pass an
|
|
98
|
+
* explicit `deposit: { kind: "none" }` AND set non-zero day fields
|
|
99
|
+
* to mark the layer as intentional.
|
|
100
|
+
*
|
|
101
|
+
* For v1 we rely on null/undefined to mean "inherit". The settings
|
|
102
|
+
* API stores `null` for "use parent". An explicit "none" policy
|
|
103
|
+
* needs to be modeled with a different deposit kind later if it
|
|
104
|
+
* proves useful.
|
|
105
|
+
*/
|
|
106
|
+
export declare function resolveEffectivePaymentPolicy(layers: PaymentPolicyCascadeLayers): ResolvedPaymentPolicy;
|
|
107
|
+
/**
|
|
108
|
+
* Predicate the storefront UI uses to decide whether to surface the
|
|
109
|
+
* "deposit + balance" copy or just "pay full now". Returns true when
|
|
110
|
+
* the policy + departure date resolve to a single full-payment row.
|
|
111
|
+
*/
|
|
112
|
+
export declare function policyShouldRequireFullPayment(policy: PaymentPolicy, departureDate: string | null | undefined, today?: Date): boolean;
|
|
113
|
+
//# sourceMappingURL=payment-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-policy.d.ts","sourceRoot":"","s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AO,CAgBtF;AAED,MAAM,MAAM,mBAAmB,GAC3B,SAAS,GACT,SAAS,GACT,UAAU,GACV,UAAU,GACV,kBAAkB,CAAA;AAEtB,MAAM,WAAW,0BAA0B;IACzC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;IACpC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;IACpC,cAAc,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;IACrC,cAAc,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;IACrC,eAAe,EAAE,aAAa,CAAA;CAC/B;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,aAAa,CAAA;IACrB,MAAM,EAAE,mBAAmB,CAAA;CAC5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,0BAA0B,GACjC,qBAAqB,CAMvB;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACxC,KAAK,GAAE,IAAiB,GACvB,OAAO,CAKT"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer-facing payment policy primitive.
|
|
3
|
+
*
|
|
4
|
+
* Decides how to split a booking total into a payment schedule: full
|
|
5
|
+
* payment up-front, or a deposit now + balance due before departure.
|
|
6
|
+
* Pure function — no DB, no IO. Two policies in (the operator default
|
|
7
|
+
* + any per-supplier / per-category / per-listing override) plus the
|
|
8
|
+
* booking total + departure date, schedule rows out.
|
|
9
|
+
*
|
|
10
|
+
* Behaviour:
|
|
11
|
+
*
|
|
12
|
+
* 1. If `policy.deposit.kind === "none"` → one row, full total, due
|
|
13
|
+
* immediately. Skips the rest of the rules.
|
|
14
|
+
* 2. If departure is too close (`< minDaysBeforeDepartureForDeposit`
|
|
15
|
+
* from today) → also full payment now. The agency doesn't have
|
|
16
|
+
* time to chase a balance.
|
|
17
|
+
* 3. Otherwise → two rows:
|
|
18
|
+
* - deposit row, due today, amount = percent × total OR fixed
|
|
19
|
+
* cents (capped at total).
|
|
20
|
+
* - balance row, amount = total − deposit, due
|
|
21
|
+
* `balanceDueDaysBeforeDeparture` before departure, but never
|
|
22
|
+
* sooner than `balanceDueMinDaysFromNow` days from now.
|
|
23
|
+
*
|
|
24
|
+
* Cascade resolution lives in {@link resolveEffectivePaymentPolicy}:
|
|
25
|
+
* the most-specific layer that defines a policy wins (booking >
|
|
26
|
+
* listing > category > supplier > operator default), no field-level
|
|
27
|
+
* merging — so the audit trail is "this whole policy applied".
|
|
28
|
+
*/
|
|
29
|
+
/** Default policy: 100% up-front, no deposit. Safe fallback for
|
|
30
|
+
* agencies that haven't configured anything yet. */
|
|
31
|
+
export const noDepositPolicy = {
|
|
32
|
+
deposit: { kind: "none" },
|
|
33
|
+
minDaysBeforeDepartureForDeposit: 0,
|
|
34
|
+
balanceDueDaysBeforeDeparture: 0,
|
|
35
|
+
balanceDueMinDaysFromNow: 0,
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Compute the customer-facing payment schedule for a booking.
|
|
39
|
+
*
|
|
40
|
+
* Always returns at least one row. When the policy resolves to no
|
|
41
|
+
* deposit (or the gate denies one), the single row is a `full`
|
|
42
|
+
* scheduled for today.
|
|
43
|
+
*/
|
|
44
|
+
export function computePaymentSchedule(input, policy) {
|
|
45
|
+
const total = Math.max(0, Math.round(input.totalCents));
|
|
46
|
+
const today = input.today ?? new Date();
|
|
47
|
+
const todayIso = isoDate(today);
|
|
48
|
+
if (total === 0) {
|
|
49
|
+
return [{ scheduleType: "full", amountCents: 0, currency: input.currency, dueDate: todayIso }];
|
|
50
|
+
}
|
|
51
|
+
if (policy.deposit.kind === "none") {
|
|
52
|
+
return [
|
|
53
|
+
{ scheduleType: "full", amountCents: total, currency: input.currency, dueDate: todayIso },
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
const departure = parseIsoDate(input.departureDate);
|
|
57
|
+
if (!departure) {
|
|
58
|
+
// Without a departure date we can't anchor the balance, so fall
|
|
59
|
+
// back to full upfront — the operator can still split manually
|
|
60
|
+
// via a booking-level override later.
|
|
61
|
+
return [
|
|
62
|
+
{ scheduleType: "full", amountCents: total, currency: input.currency, dueDate: todayIso },
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
const daysUntilDeparture = wholeDaysBetween(today, departure);
|
|
66
|
+
if (daysUntilDeparture < policy.minDaysBeforeDepartureForDeposit) {
|
|
67
|
+
return [
|
|
68
|
+
{ scheduleType: "full", amountCents: total, currency: input.currency, dueDate: todayIso },
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
const depositCents = clampCents(computeDepositCents(total, policy.deposit), 0, total);
|
|
72
|
+
const balanceCents = total - depositCents;
|
|
73
|
+
if (depositCents <= 0 || balanceCents <= 0) {
|
|
74
|
+
// Edge: a policy that resolves to 0% deposit or 100% deposit
|
|
75
|
+
// collapses to a single row rather than emitting a zero-cent
|
|
76
|
+
// partner.
|
|
77
|
+
return [
|
|
78
|
+
{ scheduleType: "full", amountCents: total, currency: input.currency, dueDate: todayIso },
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
const rawBalanceDue = addDays(departure, -policy.balanceDueDaysBeforeDeparture);
|
|
82
|
+
const earliestBalanceDue = addDays(today, policy.balanceDueMinDaysFromNow);
|
|
83
|
+
const balanceDue = rawBalanceDue.getTime() > earliestBalanceDue.getTime() ? rawBalanceDue : earliestBalanceDue;
|
|
84
|
+
return [
|
|
85
|
+
{
|
|
86
|
+
scheduleType: "deposit",
|
|
87
|
+
amountCents: depositCents,
|
|
88
|
+
currency: input.currency,
|
|
89
|
+
dueDate: todayIso,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
scheduleType: "balance",
|
|
93
|
+
amountCents: balanceCents,
|
|
94
|
+
currency: input.currency,
|
|
95
|
+
dueDate: isoDate(balanceDue),
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
function computeDepositCents(total, rule) {
|
|
100
|
+
if (rule.kind === "percent") {
|
|
101
|
+
const pct = clampNumber(rule.percent ?? 0, 0, 100);
|
|
102
|
+
return Math.round((total * pct) / 100);
|
|
103
|
+
}
|
|
104
|
+
if (rule.kind === "fixed_cents") {
|
|
105
|
+
return Math.max(0, Math.round(rule.amountCents ?? 0));
|
|
106
|
+
}
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
/** True when this policy is empty / "inherit from parent". */
|
|
110
|
+
export function isPaymentPolicyEmpty(policy) {
|
|
111
|
+
if (!policy)
|
|
112
|
+
return true;
|
|
113
|
+
if (policy.deposit.kind === "none")
|
|
114
|
+
return true;
|
|
115
|
+
if (policy.deposit.kind === "percent" &&
|
|
116
|
+
(policy.deposit.percent === undefined || policy.deposit.percent === 0)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (policy.deposit.kind === "fixed_cents" &&
|
|
120
|
+
(policy.deposit.amountCents === undefined || policy.deposit.amountCents === 0)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Most-specific-wins cascade. Returns both the policy and which
|
|
127
|
+
* layer it came from so contracts and ops UIs can show the trace.
|
|
128
|
+
*
|
|
129
|
+
* A layer is "set" when it's not null/undefined AND not effectively
|
|
130
|
+
* empty (deposit kind === "none" with no other meaningful fields).
|
|
131
|
+
* That way operators who declare an explicit "no deposit" policy on
|
|
132
|
+
* a supplier override their parent's "50% deposit" — they pass an
|
|
133
|
+
* explicit `deposit: { kind: "none" }` AND set non-zero day fields
|
|
134
|
+
* to mark the layer as intentional.
|
|
135
|
+
*
|
|
136
|
+
* For v1 we rely on null/undefined to mean "inherit". The settings
|
|
137
|
+
* API stores `null` for "use parent". An explicit "none" policy
|
|
138
|
+
* needs to be modeled with a different deposit kind later if it
|
|
139
|
+
* proves useful.
|
|
140
|
+
*/
|
|
141
|
+
export function resolveEffectivePaymentPolicy(layers) {
|
|
142
|
+
if (layers.bookingPolicy)
|
|
143
|
+
return { policy: layers.bookingPolicy, source: "booking" };
|
|
144
|
+
if (layers.listingPolicy)
|
|
145
|
+
return { policy: layers.listingPolicy, source: "listing" };
|
|
146
|
+
if (layers.categoryPolicy)
|
|
147
|
+
return { policy: layers.categoryPolicy, source: "category" };
|
|
148
|
+
if (layers.supplierPolicy)
|
|
149
|
+
return { policy: layers.supplierPolicy, source: "supplier" };
|
|
150
|
+
return { policy: layers.operatorDefault, source: "operator_default" };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Predicate the storefront UI uses to decide whether to surface the
|
|
154
|
+
* "deposit + balance" copy or just "pay full now". Returns true when
|
|
155
|
+
* the policy + departure date resolve to a single full-payment row.
|
|
156
|
+
*/
|
|
157
|
+
export function policyShouldRequireFullPayment(policy, departureDate, today = new Date()) {
|
|
158
|
+
if (policy.deposit.kind === "none")
|
|
159
|
+
return true;
|
|
160
|
+
const departure = parseIsoDate(departureDate);
|
|
161
|
+
if (!departure)
|
|
162
|
+
return true;
|
|
163
|
+
return wholeDaysBetween(today, departure) < policy.minDaysBeforeDepartureForDeposit;
|
|
164
|
+
}
|
|
165
|
+
// ─────────────────────────────────────────────────────────────────
|
|
166
|
+
// Helpers
|
|
167
|
+
// ─────────────────────────────────────────────────────────────────
|
|
168
|
+
function parseIsoDate(value) {
|
|
169
|
+
if (!value)
|
|
170
|
+
return null;
|
|
171
|
+
const trimmed = value.length >= 10 ? value.slice(0, 10) : value;
|
|
172
|
+
const parsed = new Date(`${trimmed}T00:00:00Z`);
|
|
173
|
+
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
174
|
+
}
|
|
175
|
+
function isoDate(d) {
|
|
176
|
+
return d.toISOString().slice(0, 10);
|
|
177
|
+
}
|
|
178
|
+
function wholeDaysBetween(from, to) {
|
|
179
|
+
const fromMs = Date.UTC(from.getUTCFullYear(), from.getUTCMonth(), from.getUTCDate());
|
|
180
|
+
const toMs = Date.UTC(to.getUTCFullYear(), to.getUTCMonth(), to.getUTCDate());
|
|
181
|
+
return Math.floor((toMs - fromMs) / (24 * 60 * 60 * 1000));
|
|
182
|
+
}
|
|
183
|
+
function addDays(d, days) {
|
|
184
|
+
const next = new Date(d.getTime());
|
|
185
|
+
next.setUTCDate(next.getUTCDate() + days);
|
|
186
|
+
return next;
|
|
187
|
+
}
|
|
188
|
+
function clampCents(value, min, max) {
|
|
189
|
+
return Math.max(min, Math.min(max, Math.round(value)));
|
|
190
|
+
}
|
|
191
|
+
function clampNumber(value, min, max) {
|
|
192
|
+
return Math.max(min, Math.min(max, value));
|
|
193
|
+
}
|
|
@@ -73,13 +73,13 @@ export declare function createFinanceAdminDocumentRoutes(options?: FinanceDocume
|
|
|
73
73
|
updatedAt: string;
|
|
74
74
|
status: "pending" | "failed" | "ready" | "stale";
|
|
75
75
|
format: "json" | "pdf" | "html" | "xml";
|
|
76
|
+
errorMessage: string | null;
|
|
76
77
|
templateId: string | null;
|
|
77
78
|
language: string | null;
|
|
78
79
|
invoiceId: string;
|
|
79
80
|
storageKey: string | null;
|
|
80
81
|
fileSize: number | null;
|
|
81
82
|
checksum: string | null;
|
|
82
|
-
errorMessage: string | null;
|
|
83
83
|
generatedAt: string | null;
|
|
84
84
|
};
|
|
85
85
|
};
|
|
@@ -144,13 +144,13 @@ export declare function createFinanceAdminDocumentRoutes(options?: FinanceDocume
|
|
|
144
144
|
updatedAt: string;
|
|
145
145
|
status: "pending" | "failed" | "ready" | "stale";
|
|
146
146
|
format: "json" | "pdf" | "html" | "xml";
|
|
147
|
+
errorMessage: string | null;
|
|
147
148
|
templateId: string | null;
|
|
148
149
|
language: string | null;
|
|
149
150
|
invoiceId: string;
|
|
150
151
|
storageKey: string | null;
|
|
151
152
|
fileSize: number | null;
|
|
152
153
|
checksum: string | null;
|
|
153
|
-
errorMessage: string | null;
|
|
154
154
|
generatedAt: string | null;
|
|
155
155
|
};
|
|
156
156
|
};
|
package/dist/routes-public.d.ts
CHANGED
|
@@ -221,7 +221,7 @@ export declare function createPublicFinanceRoutes(options?: PublicFinanceRouteOp
|
|
|
221
221
|
invoiceId: string;
|
|
222
222
|
invoiceNumber: string;
|
|
223
223
|
invoiceType: "invoice" | "proforma" | "credit_note";
|
|
224
|
-
status: "pending" | "
|
|
224
|
+
status: "pending" | "failed" | "completed" | "refunded";
|
|
225
225
|
paymentMethod: "other" | "voucher" | "wallet" | "bank_transfer" | "credit_card" | "debit_card" | "cash" | "cheque" | "direct_bill";
|
|
226
226
|
amountCents: number;
|
|
227
227
|
currency: string;
|
|
@@ -282,7 +282,7 @@ export declare function createPublicFinanceRoutes(options?: PublicFinanceRouteOp
|
|
|
282
282
|
id: string;
|
|
283
283
|
bookingPaymentScheduleId: string | null;
|
|
284
284
|
guaranteeType: "other" | "voucher" | "bank_transfer" | "credit_card" | "deposit" | "preauth" | "card_on_file" | "agency_letter";
|
|
285
|
-
status: "pending" | "active" | "
|
|
285
|
+
status: "pending" | "active" | "failed" | "expired" | "cancelled" | "released";
|
|
286
286
|
currency: string | null;
|
|
287
287
|
amountCents: number | null;
|
|
288
288
|
provider: string | null;
|
|
@@ -328,7 +328,7 @@ export declare function createPublicFinanceRoutes(options?: PublicFinanceRouteOp
|
|
|
328
328
|
invoiceId: string | null;
|
|
329
329
|
bookingPaymentScheduleId: string | null;
|
|
330
330
|
bookingGuaranteeId: string | null;
|
|
331
|
-
status: "pending" | "
|
|
331
|
+
status: "pending" | "failed" | "expired" | "cancelled" | "paid" | "requires_redirect" | "processing" | "authorized";
|
|
332
332
|
provider: string | null;
|
|
333
333
|
providerSessionId: string | null;
|
|
334
334
|
providerPaymentId: string | null;
|
|
@@ -385,7 +385,7 @@ export declare function createPublicFinanceRoutes(options?: PublicFinanceRouteOp
|
|
|
385
385
|
invoiceId: string | null;
|
|
386
386
|
bookingPaymentScheduleId: string | null;
|
|
387
387
|
bookingGuaranteeId: string | null;
|
|
388
|
-
status: "pending" | "
|
|
388
|
+
status: "pending" | "failed" | "expired" | "cancelled" | "paid" | "requires_redirect" | "processing" | "authorized";
|
|
389
389
|
provider: string | null;
|
|
390
390
|
providerSessionId: string | null;
|
|
391
391
|
providerPaymentId: string | null;
|
|
@@ -455,7 +455,7 @@ export declare function createPublicFinanceRoutes(options?: PublicFinanceRouteOp
|
|
|
455
455
|
invoiceId: string | null;
|
|
456
456
|
bookingPaymentScheduleId: string | null;
|
|
457
457
|
bookingGuaranteeId: string | null;
|
|
458
|
-
status: "pending" | "
|
|
458
|
+
status: "pending" | "failed" | "expired" | "cancelled" | "paid" | "requires_redirect" | "processing" | "authorized";
|
|
459
459
|
provider: string | null;
|
|
460
460
|
providerSessionId: string | null;
|
|
461
461
|
providerPaymentId: string | null;
|
|
@@ -521,7 +521,7 @@ export declare function createPublicFinanceRoutes(options?: PublicFinanceRouteOp
|
|
|
521
521
|
invoiceId: string | null;
|
|
522
522
|
bookingPaymentScheduleId: string | null;
|
|
523
523
|
bookingGuaranteeId: string | null;
|
|
524
|
-
status: "pending" | "
|
|
524
|
+
status: "pending" | "failed" | "expired" | "cancelled" | "paid" | "requires_redirect" | "processing" | "authorized";
|
|
525
525
|
provider: string | null;
|
|
526
526
|
providerSessionId: string | null;
|
|
527
527
|
providerPaymentId: string | null;
|
|
@@ -777,7 +777,7 @@ export declare const publicFinanceRoutes: import("hono/hono-base").HonoBase<Env,
|
|
|
777
777
|
invoiceId: string;
|
|
778
778
|
invoiceNumber: string;
|
|
779
779
|
invoiceType: "invoice" | "proforma" | "credit_note";
|
|
780
|
-
status: "pending" | "
|
|
780
|
+
status: "pending" | "failed" | "completed" | "refunded";
|
|
781
781
|
paymentMethod: "other" | "voucher" | "wallet" | "bank_transfer" | "credit_card" | "debit_card" | "cash" | "cheque" | "direct_bill";
|
|
782
782
|
amountCents: number;
|
|
783
783
|
currency: string;
|
|
@@ -838,7 +838,7 @@ export declare const publicFinanceRoutes: import("hono/hono-base").HonoBase<Env,
|
|
|
838
838
|
id: string;
|
|
839
839
|
bookingPaymentScheduleId: string | null;
|
|
840
840
|
guaranteeType: "other" | "voucher" | "bank_transfer" | "credit_card" | "deposit" | "preauth" | "card_on_file" | "agency_letter";
|
|
841
|
-
status: "pending" | "active" | "
|
|
841
|
+
status: "pending" | "active" | "failed" | "expired" | "cancelled" | "released";
|
|
842
842
|
currency: string | null;
|
|
843
843
|
amountCents: number | null;
|
|
844
844
|
provider: string | null;
|
|
@@ -884,7 +884,7 @@ export declare const publicFinanceRoutes: import("hono/hono-base").HonoBase<Env,
|
|
|
884
884
|
invoiceId: string | null;
|
|
885
885
|
bookingPaymentScheduleId: string | null;
|
|
886
886
|
bookingGuaranteeId: string | null;
|
|
887
|
-
status: "pending" | "
|
|
887
|
+
status: "pending" | "failed" | "expired" | "cancelled" | "paid" | "requires_redirect" | "processing" | "authorized";
|
|
888
888
|
provider: string | null;
|
|
889
889
|
providerSessionId: string | null;
|
|
890
890
|
providerPaymentId: string | null;
|
|
@@ -941,7 +941,7 @@ export declare const publicFinanceRoutes: import("hono/hono-base").HonoBase<Env,
|
|
|
941
941
|
invoiceId: string | null;
|
|
942
942
|
bookingPaymentScheduleId: string | null;
|
|
943
943
|
bookingGuaranteeId: string | null;
|
|
944
|
-
status: "pending" | "
|
|
944
|
+
status: "pending" | "failed" | "expired" | "cancelled" | "paid" | "requires_redirect" | "processing" | "authorized";
|
|
945
945
|
provider: string | null;
|
|
946
946
|
providerSessionId: string | null;
|
|
947
947
|
providerPaymentId: string | null;
|
|
@@ -1011,7 +1011,7 @@ export declare const publicFinanceRoutes: import("hono/hono-base").HonoBase<Env,
|
|
|
1011
1011
|
invoiceId: string | null;
|
|
1012
1012
|
bookingPaymentScheduleId: string | null;
|
|
1013
1013
|
bookingGuaranteeId: string | null;
|
|
1014
|
-
status: "pending" | "
|
|
1014
|
+
status: "pending" | "failed" | "expired" | "cancelled" | "paid" | "requires_redirect" | "processing" | "authorized";
|
|
1015
1015
|
provider: string | null;
|
|
1016
1016
|
providerSessionId: string | null;
|
|
1017
1017
|
providerPaymentId: string | null;
|
|
@@ -1077,7 +1077,7 @@ export declare const publicFinanceRoutes: import("hono/hono-base").HonoBase<Env,
|
|
|
1077
1077
|
invoiceId: string | null;
|
|
1078
1078
|
bookingPaymentScheduleId: string | null;
|
|
1079
1079
|
bookingGuaranteeId: string | null;
|
|
1080
|
-
status: "pending" | "
|
|
1080
|
+
status: "pending" | "failed" | "expired" | "cancelled" | "paid" | "requires_redirect" | "processing" | "authorized";
|
|
1081
1081
|
provider: string | null;
|
|
1082
1082
|
providerSessionId: string | null;
|
|
1083
1083
|
providerPaymentId: string | null;
|