/* * 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 { ProductType, ProductType$inboundSchema, ProductType$outboundSchema, } from "./producttype.js"; export type CartItem = { /** * The name of the cart item. The value you set for this property may be truncated if the maximum length accepted by a payment service provider is less than 255 characters. */ name: string; /** * The quantity of this item in the cart. This value cannot be negative or zero. */ quantity: number; /** * The amount for an individual item represented as a monetary amount in the smallest currency unit for the given currency, for example `1299` USD cents represents `$12.99`. The amount sent through to the payment processor as unitary amount will be calculated to include the discount and tax values sent as part of this cart item. */ unitAmount: number; /** * The amount discounted for this item represented as a monetary amount in the smallest currency unit for the given currency, for example `1299` USD cents represents `$12.99`. */ discountAmount?: number | null | undefined; /** * The tax amount for this item represented as a monetary amount in the smallest currency unit for the given currency, for example `1299` USD cents represents `$12.99`. */ taxAmount?: number | null | undefined; /** * An external identifier for the cart item. This can be set to any value and is not sent to the payment service. */ externalIdentifier?: string | null | undefined; /** * The SKU or product code for the item. */ sku?: string | null | undefined; /** * The UPC for the item. */ upc?: string | null | undefined; /** * The product URL for the item. */ productUrl?: string | null | undefined; /** * The URL for the image of the item. */ imageUrl?: string | null | undefined; /** * A list of strings containing product categories for the item. */ categories?: Array | null | undefined; /** * A list of strings containing product subcategories for the item. */ subcategories?: Array | null | undefined; /** * The brand of the item. */ brand?: string | null | undefined; /** * The product type of the cart item. */ productType?: ProductType | null | undefined; /** * The seller country of the cart item. */ sellerCountry?: string | null | undefined; /** * Whether the item is exempt of tax. */ taxExempt?: boolean | null | undefined; /** * The unit of measure or the unit of measure code. */ unitOfMeasure?: string | null | undefined; /** * Item commodity code. Generally a UNSPSC code. */ commodityCode?: string | null | undefined; /** * Brief item description. */ description?: string | null | undefined; /** * Item import or export duties represented as a monetary amount in the smallest currency unit for the given currency, for example `1299` cents to create an authorization for `$12.99` */ dutyAmount?: number | null | undefined; /** * Freight/shipping amount represented as a monetary amount in the smallest currency unit for the given currency, for example `1299` cents to create an authorization for `$12.99` */ shippingAmount?: number | null | undefined; }; /** @internal */ export const CartItem$inboundSchema: z.ZodType< CartItem, z.ZodTypeDef, unknown > = z.object({ name: z.string(), quantity: z.number().int(), unit_amount: z.number().int(), discount_amount: z.nullable(z.number().int()).optional(), tax_amount: z.nullable(z.number().int()).optional(), external_identifier: z.nullable(z.string()).optional(), sku: z.nullable(z.string()).optional(), upc: z.nullable(z.string()).optional(), product_url: z.nullable(z.string()).optional(), image_url: z.nullable(z.string()).optional(), categories: z.nullable(z.array(z.string())).optional(), subcategories: z.nullable(z.array(z.string())).optional(), brand: z.nullable(z.string()).optional(), product_type: z.nullable(ProductType$inboundSchema).optional(), seller_country: z.nullable(z.string()).optional(), tax_exempt: z.nullable(z.boolean()).optional(), unit_of_measure: z.nullable(z.string()).optional(), commodity_code: z.nullable(z.string()).optional(), description: z.nullable(z.string()).optional(), duty_amount: z.nullable(z.number().int()).optional(), shipping_amount: z.nullable(z.number().int()).optional(), }).transform((v) => { return remap$(v, { "unit_amount": "unitAmount", "discount_amount": "discountAmount", "tax_amount": "taxAmount", "external_identifier": "externalIdentifier", "product_url": "productUrl", "image_url": "imageUrl", "product_type": "productType", "seller_country": "sellerCountry", "tax_exempt": "taxExempt", "unit_of_measure": "unitOfMeasure", "commodity_code": "commodityCode", "duty_amount": "dutyAmount", "shipping_amount": "shippingAmount", }); }); /** @internal */ export type CartItem$Outbound = { name: string; quantity: number; unit_amount: number; discount_amount?: number | null | undefined; tax_amount?: number | null | undefined; external_identifier?: string | null | undefined; sku?: string | null | undefined; upc?: string | null | undefined; product_url?: string | null | undefined; image_url?: string | null | undefined; categories?: Array | null | undefined; subcategories?: Array | null | undefined; brand?: string | null | undefined; product_type?: string | null | undefined; seller_country?: string | null | undefined; tax_exempt?: boolean | null | undefined; unit_of_measure?: string | null | undefined; commodity_code?: string | null | undefined; description?: string | null | undefined; duty_amount?: number | null | undefined; shipping_amount?: number | null | undefined; }; /** @internal */ export const CartItem$outboundSchema: z.ZodType< CartItem$Outbound, z.ZodTypeDef, CartItem > = z.object({ name: z.string(), quantity: z.number().int(), unitAmount: z.number().int(), discountAmount: z.nullable(z.number().int()).optional(), taxAmount: z.nullable(z.number().int()).optional(), externalIdentifier: z.nullable(z.string()).optional(), sku: z.nullable(z.string()).optional(), upc: z.nullable(z.string()).optional(), productUrl: z.nullable(z.string()).optional(), imageUrl: z.nullable(z.string()).optional(), categories: z.nullable(z.array(z.string())).optional(), subcategories: z.nullable(z.array(z.string())).optional(), brand: z.nullable(z.string()).optional(), productType: z.nullable(ProductType$outboundSchema).optional(), sellerCountry: z.nullable(z.string()).optional(), taxExempt: z.nullable(z.boolean()).optional(), unitOfMeasure: z.nullable(z.string()).optional(), commodityCode: z.nullable(z.string()).optional(), description: z.nullable(z.string()).optional(), dutyAmount: z.nullable(z.number().int()).optional(), shippingAmount: z.nullable(z.number().int()).optional(), }).transform((v) => { return remap$(v, { unitAmount: "unit_amount", discountAmount: "discount_amount", taxAmount: "tax_amount", externalIdentifier: "external_identifier", productUrl: "product_url", imageUrl: "image_url", productType: "product_type", sellerCountry: "seller_country", taxExempt: "tax_exempt", unitOfMeasure: "unit_of_measure", commodityCode: "commodity_code", dutyAmount: "duty_amount", shippingAmount: "shipping_amount", }); }); export function cartItemToJSON(cartItem: CartItem): string { return JSON.stringify(CartItem$outboundSchema.parse(cartItem)); } export function cartItemFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CartItem$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CartItem' from JSON`, ); }