/* * 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 { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { ProductPriceMeter, ProductPriceMeter$inboundSchema, ProductPriceMeter$Outbound, ProductPriceMeter$outboundSchema, } from "./productpricemeter.js"; import { ProductPriceSource, ProductPriceSource$inboundSchema, ProductPriceSource$outboundSchema, } from "./productpricesource.js"; import { TaxBehaviorOption, TaxBehaviorOption$inboundSchema, TaxBehaviorOption$outboundSchema, } from "./taxbehavioroption.js"; /** * A metered, usage-based, price for a product, with a fixed unit price. */ export type ProductPriceMeteredUnit = { /** * Creation timestamp of the object. */ createdAt: Date; /** * Last modification timestamp of the object. */ modifiedAt: Date | null; /** * The ID of the price. */ id: string; source: ProductPriceSource; amountType: "metered_unit"; /** * The currency in which the customer will be charged. */ priceCurrency: string; /** * The tax behavior of the price. If null, it defaults to the organization's default tax behavior. */ taxBehavior: TaxBehaviorOption | null; /** * Whether the price is archived and no longer available. */ isArchived: boolean; /** * The ID of the product owning the price. */ productId: string; /** * The price per unit in cents. */ unitAmount: string; /** * The maximum amount in cents that can be charged, regardless of the number of units consumed. */ capAmount: number | null; /** * The ID of the meter associated to the price. */ meterId: string; /** * A meter associated to a metered price. */ meter: ProductPriceMeter; }; /** @internal */ export const ProductPriceMeteredUnit$inboundSchema: z.ZodMiniType< ProductPriceMeteredUnit, unknown > = z.pipe( z.object({ created_at: z.pipe( z.iso.datetime({ offset: true }), z.transform(v => new Date(v)), ), modified_at: z.nullable( z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))), ), id: z.string(), source: ProductPriceSource$inboundSchema, amount_type: z.literal("metered_unit"), price_currency: z.string(), tax_behavior: z.nullable(TaxBehaviorOption$inboundSchema), is_archived: z.boolean(), product_id: z.string(), unit_amount: z.string(), cap_amount: z.nullable(z.int()), meter_id: z.string(), meter: ProductPriceMeter$inboundSchema, }), z.transform((v) => { return remap$(v, { "created_at": "createdAt", "modified_at": "modifiedAt", "amount_type": "amountType", "price_currency": "priceCurrency", "tax_behavior": "taxBehavior", "is_archived": "isArchived", "product_id": "productId", "unit_amount": "unitAmount", "cap_amount": "capAmount", "meter_id": "meterId", }); }), ); /** @internal */ export type ProductPriceMeteredUnit$Outbound = { created_at: string; modified_at: string | null; id: string; source: string; amount_type: "metered_unit"; price_currency: string; tax_behavior: string | null; is_archived: boolean; product_id: string; unit_amount: string; cap_amount: number | null; meter_id: string; meter: ProductPriceMeter$Outbound; }; /** @internal */ export const ProductPriceMeteredUnit$outboundSchema: z.ZodMiniType< ProductPriceMeteredUnit$Outbound, ProductPriceMeteredUnit > = z.pipe( z.object({ createdAt: z.pipe(z.date(), z.transform(v => v.toISOString())), modifiedAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))), id: z.string(), source: ProductPriceSource$outboundSchema, amountType: z.literal("metered_unit"), priceCurrency: z.string(), taxBehavior: z.nullable(TaxBehaviorOption$outboundSchema), isArchived: z.boolean(), productId: z.string(), unitAmount: z.string(), capAmount: z.nullable(z.int()), meterId: z.string(), meter: ProductPriceMeter$outboundSchema, }), z.transform((v) => { return remap$(v, { createdAt: "created_at", modifiedAt: "modified_at", amountType: "amount_type", priceCurrency: "price_currency", taxBehavior: "tax_behavior", isArchived: "is_archived", productId: "product_id", unitAmount: "unit_amount", capAmount: "cap_amount", meterId: "meter_id", }); }), ); export function productPriceMeteredUnitToJSON( productPriceMeteredUnit: ProductPriceMeteredUnit, ): string { return JSON.stringify( ProductPriceMeteredUnit$outboundSchema.parse(productPriceMeteredUnit), ); } export function productPriceMeteredUnitFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ProductPriceMeteredUnit$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ProductPriceMeteredUnit' from JSON`, ); }