/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; 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 { EnvironmentMode, EnvironmentMode$inboundSchema, EnvironmentMode$outboundSchema, } from "./environmentmode.js"; import { OrderStatus, OrderStatus$inboundSchema, OrderStatus$outboundSchema, } from "./orderstatus.js"; import { OrderType, OrderType$inboundSchema, OrderType$outboundSchema, } from "./ordertype.js"; export type OrderEntity = { /** * Unique identifier for the object. */ id: string; /** * String representing the environment. */ mode: EnvironmentMode; /** * String representing the object's type. Objects of the same type share the same value. */ object: string; /** * The customer who placed the order. */ customer?: string | null | undefined; /** * The product associated with the order. */ product: string; /** * The transaction ID of the order */ transaction?: string | null | undefined; /** * The discount ID of the order */ discount?: string | null | undefined; /** * The total amount of the order in cents. 1000 = $10.00 */ amount: number; /** * The subtotal of the order in cents. 1000 = $10.00 */ subTotal?: number | undefined; /** * The tax amount of the order in cents. 1000 = $10.00 */ taxAmount?: number | undefined; /** * The discount amount of the order in cents. 1000 = $10.00 */ discountAmount?: number | undefined; /** * The amount due for the order in cents. 1000 = $10.00 */ amountDue?: number | undefined; /** * The amount paid for the order in cents. 1000 = $10.00 */ amountPaid?: number | undefined; /** * Three-letter ISO currency code, in uppercase. Must be a supported currency. */ currency: string; /** * The amount in the foreign currency, if applicable. */ fxAmount?: number | null | undefined; /** * Three-letter ISO code of the foreign currency, if applicable. */ fxCurrency?: string | null | undefined; /** * The exchange rate used for converting between currencies, if applicable. */ fxRate?: number | null | undefined; /** * Current status of the order. */ status: OrderStatus; /** * The type of order. This can specify whether it's a regular purchase, subscription, etc. */ type: OrderType; /** * The affiliate associated with the order, if applicable. */ affiliate?: string | null | undefined; /** * Creation date of the order */ createdAt: Date; /** * Last updated date of the order */ updatedAt: Date; }; /** @internal */ export const OrderEntity$inboundSchema: z.ZodType< OrderEntity, z.ZodTypeDef, unknown > = z.object({ id: z.string(), mode: EnvironmentMode$inboundSchema, object: z.string(), customer: z.nullable(z.string()).optional(), product: z.string(), transaction: z.nullable(z.string()).optional(), discount: z.nullable(z.string()).optional(), amount: z.number(), sub_total: z.number().optional(), tax_amount: z.number().optional(), discount_amount: z.number().optional(), amount_due: z.number().optional(), amount_paid: z.number().optional(), currency: z.string(), fx_amount: z.nullable(z.number()).optional(), fx_currency: z.nullable(z.string()).optional(), fx_rate: z.nullable(z.number()).optional(), status: OrderStatus$inboundSchema, type: OrderType$inboundSchema, affiliate: z.nullable(z.string()).optional(), created_at: z.string().datetime({ offset: true }).transform(v => new Date(v)), updated_at: z.string().datetime({ offset: true }).transform(v => new Date(v)), }).transform((v) => { return remap$(v, { "sub_total": "subTotal", "tax_amount": "taxAmount", "discount_amount": "discountAmount", "amount_due": "amountDue", "amount_paid": "amountPaid", "fx_amount": "fxAmount", "fx_currency": "fxCurrency", "fx_rate": "fxRate", "created_at": "createdAt", "updated_at": "updatedAt", }); }); /** @internal */ export type OrderEntity$Outbound = { id: string; mode: string; object: string; customer?: string | null | undefined; product: string; transaction?: string | null | undefined; discount?: string | null | undefined; amount: number; sub_total?: number | undefined; tax_amount?: number | undefined; discount_amount?: number | undefined; amount_due?: number | undefined; amount_paid?: number | undefined; currency: string; fx_amount?: number | null | undefined; fx_currency?: string | null | undefined; fx_rate?: number | null | undefined; status: string; type: string; affiliate?: string | null | undefined; created_at: string; updated_at: string; }; /** @internal */ export const OrderEntity$outboundSchema: z.ZodType< OrderEntity$Outbound, z.ZodTypeDef, OrderEntity > = z.object({ id: z.string(), mode: EnvironmentMode$outboundSchema, object: z.string(), customer: z.nullable(z.string()).optional(), product: z.string(), transaction: z.nullable(z.string()).optional(), discount: z.nullable(z.string()).optional(), amount: z.number(), subTotal: z.number().optional(), taxAmount: z.number().optional(), discountAmount: z.number().optional(), amountDue: z.number().optional(), amountPaid: z.number().optional(), currency: z.string(), fxAmount: z.nullable(z.number()).optional(), fxCurrency: z.nullable(z.string()).optional(), fxRate: z.nullable(z.number()).optional(), status: OrderStatus$outboundSchema, type: OrderType$outboundSchema, affiliate: z.nullable(z.string()).optional(), createdAt: z.date().transform(v => v.toISOString()), updatedAt: z.date().transform(v => v.toISOString()), }).transform((v) => { return remap$(v, { subTotal: "sub_total", taxAmount: "tax_amount", discountAmount: "discount_amount", amountDue: "amount_due", amountPaid: "amount_paid", fxAmount: "fx_amount", fxCurrency: "fx_currency", fxRate: "fx_rate", createdAt: "created_at", updatedAt: "updated_at", }); }); export function orderEntityToJSON(orderEntity: OrderEntity): string { return JSON.stringify(OrderEntity$outboundSchema.parse(orderEntity)); } export function orderEntityFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OrderEntity$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OrderEntity' from JSON`, ); }