/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { remap as remap$ } from "../../lib/primitives.js"; import { CreateInvoiceLineItemRequest, CreateInvoiceLineItemRequest$Outbound, CreateInvoiceLineItemRequest$outboundSchema, } from "./create-invoice-line-item-request.js"; import { InvoiceBillingReason, InvoiceBillingReason$outboundSchema, } from "./invoice-billing-reason.js"; import { InvoiceCoupon, InvoiceCoupon$Outbound, InvoiceCoupon$outboundSchema, } from "./invoice-coupon.js"; import { InvoiceLineItemCoupon, InvoiceLineItemCoupon$Outbound, InvoiceLineItemCoupon$outboundSchema, } from "./invoice-line-item-coupon.js"; import { InvoiceStatus, InvoiceStatus$outboundSchema, } from "./invoice-status.js"; import { InvoiceType, InvoiceType$outboundSchema } from "./invoice-type.js"; import { PaymentStatus, PaymentStatus$outboundSchema, } from "./payment-status.js"; import { TaxRateOverride, TaxRateOverride$Outbound, TaxRateOverride$outboundSchema, } from "./tax-rate-override.js"; import { TaxRateResponse, TaxRateResponse$Outbound, TaxRateResponse$outboundSchema, } from "./tax-rate-response.js"; export type CreateInvoiceRequest = { /** * amount_due is the total amount that needs to be paid for this invoice */ amountDue: string; /** * amount_paid is the amount that has been paid towards this invoice */ amountPaid?: string | undefined; /** * billing_period is the period this invoice covers (e.g., "monthly", "yearly") */ billingPeriod?: string | undefined; billingReason?: InvoiceBillingReason | undefined; /** * coupons */ coupons?: Array | undefined; /** * currency is the three-letter ISO currency code (e.g., USD, EUR) for the invoice */ currency: string; /** * customer_id is the unique identifier of the customer this invoice belongs to */ customerId: string; /** * description is an optional text description of the invoice */ description?: string | undefined; /** * due_date is the date by which payment is expected */ dueDate?: Date | undefined; /** * force_sync_invoice, when true, attempts to synchronously sync this invoice to * * @remarks * Moyasar (if enabled) before returning, instead of relying solely on the async * Kafka + Temporal vendor-sync pipeline. Only honored by CreateOneOffInvoice. * Best-effort: sync failures do not fail invoice creation. */ forceSyncInvoice?: boolean | undefined; /** * idempotency_key is an optional key used to prevent duplicate invoice creation */ idempotencyKey?: string | undefined; /** * Invoice Coupons */ invoiceCoupons?: Array | undefined; /** * invoice_number is an optional human-readable identifier for the invoice */ invoiceNumber?: string | undefined; /** * invoice_pdf_url is the URL where customers can download the PDF version of this invoice */ invoicePdfUrl?: string | undefined; invoiceStatus?: InvoiceStatus | undefined; invoiceType?: InvoiceType | undefined; /** * issue_date overrides the user-facing date of the invoice. * * @remarks * Defaults to created_at if not provided. */ issueDate?: Date | undefined; /** * Invoice Line Item Coupons */ lineItemCoupons?: Array | undefined; /** * line_items contains the individual items that make up this invoice */ lineItems?: Array | undefined; metadata?: { [k: string]: string } | undefined; paymentStatus?: PaymentStatus | undefined; /** * period_end is the end date of the billing period */ periodEnd?: Date | undefined; /** * period_start is the start date of the billing period */ periodStart?: Date | undefined; /** * prepared_tax_rates contains the tax rates pre-resolved by the caller (e.g., billing service) */ preparedTaxRates?: Array | undefined; /** * subscription_id is the optional unique identifier of the subscription associated with this invoice */ subscriptionId?: string | undefined; /** * subtotal is the amount before taxes and discounts are applied */ subtotal: string; /** * tax_rate_overrides is the tax rate overrides to be applied to the invoice */ taxRateOverrides?: Array | undefined; /** * tax_rates */ taxRates?: Array | undefined; /** * total is the total amount of the invoice including taxes and discounts */ total: string; /** * total_prepaid_applied is the total amount of prepaid applied to this invoice. */ totalPrepaidApplied?: string | undefined; }; /** @internal */ export type CreateInvoiceRequest$Outbound = { amount_due: string; amount_paid?: string | undefined; billing_period?: string | undefined; billing_reason?: string | undefined; coupons?: Array | undefined; currency: string; customer_id: string; description?: string | undefined; due_date?: string | undefined; force_sync_invoice?: boolean | undefined; idempotency_key?: string | undefined; invoice_coupons?: Array | undefined; invoice_number?: string | undefined; invoice_pdf_url?: string | undefined; invoice_status?: string | undefined; invoice_type?: string | undefined; issue_date?: string | undefined; line_item_coupons?: Array | undefined; line_items?: Array | undefined; metadata?: { [k: string]: string } | undefined; payment_status?: string | undefined; period_end?: string | undefined; period_start?: string | undefined; prepared_tax_rates?: Array | undefined; subscription_id?: string | undefined; subtotal: string; tax_rate_overrides?: Array | undefined; tax_rates?: Array | undefined; total: string; total_prepaid_applied?: string | undefined; }; /** @internal */ export const CreateInvoiceRequest$outboundSchema: z.ZodMiniType< CreateInvoiceRequest$Outbound, CreateInvoiceRequest > = z.pipe( z.object({ amountDue: z.string(), amountPaid: z.optional(z.string()), billingPeriod: z.optional(z.string()), billingReason: z.optional(InvoiceBillingReason$outboundSchema), coupons: z.optional(z.array(z.string())), currency: z.string(), customerId: z.string(), description: z.optional(z.string()), dueDate: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), forceSyncInvoice: z.optional(z.boolean()), idempotencyKey: z.optional(z.string()), invoiceCoupons: z.optional(z.array(InvoiceCoupon$outboundSchema)), invoiceNumber: z.optional(z.string()), invoicePdfUrl: z.optional(z.string()), invoiceStatus: z.optional(InvoiceStatus$outboundSchema), invoiceType: z.optional(InvoiceType$outboundSchema), issueDate: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), lineItemCoupons: z.optional(z.array(InvoiceLineItemCoupon$outboundSchema)), lineItems: z.optional(z.array(CreateInvoiceLineItemRequest$outboundSchema)), metadata: z.optional(z.record(z.string(), z.string())), paymentStatus: z.optional(PaymentStatus$outboundSchema), periodEnd: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), periodStart: z.optional( z.pipe(z.date(), z.transform(v => v.toISOString())), ), preparedTaxRates: z.optional(z.array(TaxRateResponse$outboundSchema)), subscriptionId: z.optional(z.string()), subtotal: z.string(), taxRateOverrides: z.optional(z.array(TaxRateOverride$outboundSchema)), taxRates: z.optional(z.array(z.string())), total: z.string(), totalPrepaidApplied: z.optional(z.string()), }), z.transform((v) => { return remap$(v, { amountDue: "amount_due", amountPaid: "amount_paid", billingPeriod: "billing_period", billingReason: "billing_reason", customerId: "customer_id", dueDate: "due_date", forceSyncInvoice: "force_sync_invoice", idempotencyKey: "idempotency_key", invoiceCoupons: "invoice_coupons", invoiceNumber: "invoice_number", invoicePdfUrl: "invoice_pdf_url", invoiceStatus: "invoice_status", invoiceType: "invoice_type", issueDate: "issue_date", lineItemCoupons: "line_item_coupons", lineItems: "line_items", paymentStatus: "payment_status", periodEnd: "period_end", periodStart: "period_start", preparedTaxRates: "prepared_tax_rates", subscriptionId: "subscription_id", taxRateOverrides: "tax_rate_overrides", taxRates: "tax_rates", totalPrepaidApplied: "total_prepaid_applied", }); }), ); export function createInvoiceRequestToJSON( createInvoiceRequest: CreateInvoiceRequest, ): string { return JSON.stringify( CreateInvoiceRequest$outboundSchema.parse(createInvoiceRequest), ); }