/* * 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 { CaptureStatus, CaptureStatus$inboundSchema } from "./capturestatus.js"; import { CartItem, CartItem$inboundSchema } from "./cartitem.js"; import { Tracking, Tracking$inboundSchema } from "./tracking.js"; export type Capture = { /** * Always `capture`. */ type: "capture"; /** * The unique identifier for the capture. */ id: string; /** * The merchant account this capture belongs to. */ merchantAccountId: string; /** * The ID of the transaction associated with this capture. */ transactionId: string; /** * The payment service's unique ID for the capture. */ xid?: string | null | undefined; /** * The ISO 4217 currency code for this capture. */ currency: string; /** * The capture amount in the smallest currency unit. */ amount: number; status: CaptureStatus; /** * Whether this is marked as the final capture for the associated transaction. */ final: boolean; /** * The date and time this capture was created. */ createdAt: Date; /** * The date and time this capture was last updated. */ updatedAt: Date; /** * The date and time the capture was completed. */ capturedAt?: Date | null | undefined; /** * An external identifier that can be used to match the capture against your own records. */ externalIdentifier?: string | null | undefined; /** * The standardized error code set by Gr4vy. */ errorCode?: string | null | undefined; /** * The ISO response code. */ isoResponseCode?: string | null | undefined; /** * This is the response code received from the payment service. This can be set to any value and is not standardized across different payment services. */ rawResponseCode?: string | null | undefined; /** * This is the response description received from the payment service. This can be set to any value and is not standardized across different payment services. */ rawResponseDescription?: string | null | undefined; /** * The external identifier of the associated transaction. */ transactionExternalIdentifier?: string | null | undefined; /** * An array of cart items that represents the line items of this capture. */ cartItems?: Array | null | undefined; /** * The shipment tracking details associated with the capture. */ tracking?: Array | null | undefined; }; /** @internal */ export const Capture$inboundSchema: z.ZodType = z.object({ type: z.literal("capture").default("capture"), id: z.string(), merchant_account_id: z.string(), transaction_id: z.string(), xid: z.nullable(z.string()).optional(), currency: z.string(), amount: z.number().int(), status: CaptureStatus$inboundSchema, final: z.boolean(), created_at: z.string().datetime({ offset: true }).transform(v => new Date(v) ), updated_at: z.string().datetime({ offset: true }).transform(v => new Date(v) ), captured_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), external_identifier: z.nullable(z.string()).optional(), error_code: z.nullable(z.string()).optional(), iso_response_code: z.nullable(z.string()).optional(), raw_response_code: z.nullable(z.string()).optional(), raw_response_description: z.nullable(z.string()).optional(), transaction_external_identifier: z.nullable(z.string()).optional(), cart_items: z.nullable(z.array(CartItem$inboundSchema)).optional(), tracking: z.nullable(z.array(Tracking$inboundSchema)).optional(), }).transform((v) => { return remap$(v, { "merchant_account_id": "merchantAccountId", "transaction_id": "transactionId", "created_at": "createdAt", "updated_at": "updatedAt", "captured_at": "capturedAt", "external_identifier": "externalIdentifier", "error_code": "errorCode", "iso_response_code": "isoResponseCode", "raw_response_code": "rawResponseCode", "raw_response_description": "rawResponseDescription", "transaction_external_identifier": "transactionExternalIdentifier", "cart_items": "cartItems", }); }); export function captureFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Capture$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Capture' from JSON`, ); }