/* * 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 { ApiCommonSchemasCreator, ApiCommonSchemasCreator$inboundSchema, } from "./apicommonschemascreator.js"; import { RefundStatus, RefundStatus$inboundSchema } from "./refundstatus.js"; import { RefundTargetType, RefundTargetType$inboundSchema, } from "./refundtargettype.js"; export type Refund = { /** * Always `refund`. */ type: "refund"; /** * The unique identifier for the refund. */ id: string; /** * The ID of the transaction associated with this refund. */ transactionId: string; /** * The payment service's unique ID for the refund. */ paymentServiceRefundId?: string | null | undefined; status: RefundStatus; /** * The ISO 4217 currency code for this refund. Will always match that of the associated transaction. */ currency: string; /** * The amount of this refund, in the smallest currency unit (for example, cents or pence). */ amount: number; /** * The reason for this refund. Could be a multiline string. */ reason?: string | null | undefined; targetType: RefundTargetType; /** * The optional ID of the instrument that was refunded. This may be `null` if the instrument was not stored. */ targetId?: string | null | undefined; /** * The base62 encoded refund ID. This represents a shorter version of this refund's `id` which is sent to payment services, anti-fraud services, and other connectors. You can use this ID to reconcile a payment service's refund against our system. */ reconciliationId: string; /** * An external identifier that can be used to match the refund against your own records. */ externalIdentifier?: string | null | undefined; /** * The base62 encoded transaction ID. This represents a shorter version of the related transaction's `id` which is sent to payment services, anti-fraud services, and other connectors. You can use this ID to reconcile a payment service's transaction against our system. */ transactionReconciliationId: string; /** * An external identifier that can be used to match the transaction against your own records. */ transactionExternalIdentifier?: string | null | undefined; /** * The date this refund was created at. */ createdAt: Date; /** * The date this refund was last updated at. */ updatedAt: Date; /** * The user that created this resource */ creator?: ApiCommonSchemasCreator | null | undefined; /** * The standardized error code set by Gr4vy. */ errorCode?: 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 ISO 4217 currency code of this refund's settlement. */ settledCurrency?: string | null | undefined; /** * The net amount settled for this refund, in the smallest currency unit (for example, cents or pence). */ settledAmount: number; /** * Indicates whether this refund has been settled. */ settled: boolean; }; /** @internal */ export const Refund$inboundSchema: z.ZodType = z .object({ type: z.literal("refund").default("refund"), id: z.string(), transaction_id: z.string(), payment_service_refund_id: z.nullable(z.string()).optional(), status: RefundStatus$inboundSchema, currency: z.string(), amount: z.number().int(), reason: z.nullable(z.string()).optional(), target_type: RefundTargetType$inboundSchema, target_id: z.nullable(z.string()).optional(), reconciliation_id: z.string(), external_identifier: z.nullable(z.string()).optional(), transaction_reconciliation_id: z.string(), transaction_external_identifier: 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) ), creator: z.nullable(ApiCommonSchemasCreator$inboundSchema).optional(), error_code: z.nullable(z.string()).optional(), raw_response_code: z.nullable(z.string()).optional(), raw_response_description: z.nullable(z.string()).optional(), settled_currency: z.nullable(z.string()).optional(), settled_amount: z.number().int().default(0), settled: z.boolean(), }).transform((v) => { return remap$(v, { "transaction_id": "transactionId", "payment_service_refund_id": "paymentServiceRefundId", "target_type": "targetType", "target_id": "targetId", "reconciliation_id": "reconciliationId", "external_identifier": "externalIdentifier", "transaction_reconciliation_id": "transactionReconciliationId", "transaction_external_identifier": "transactionExternalIdentifier", "created_at": "createdAt", "updated_at": "updatedAt", "error_code": "errorCode", "raw_response_code": "rawResponseCode", "raw_response_description": "rawResponseDescription", "settled_currency": "settledCurrency", "settled_amount": "settledAmount", }); }); export function refundFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Refund$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Refund' from JSON`, ); }