/* * 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 { GiftCardErrorCode, GiftCardErrorCode$inboundSchema, } from "./giftcarderrorcode.js"; export type GiftCardSummary = { /** * Always `gift-card`. */ type: "gift-card"; /** * The ID for the gift card. */ id?: string | null | undefined; /** * The ID of the merchant account this buyer belongs to. */ merchantAccountId: string; /** * The first 6 digits of the full gift card number. */ bin: string; /** * The 3 digits after the `bin` of the full gift card number. */ subBin: string; /** * The last 4 digits for the gift card. */ last4: string; /** * The ISO-4217 currency code that this gift card has a balance for. */ currency?: string | null | undefined; /** * The date and time when this gift card expires. This is a full date/time and may be more accurate than the actual expiry date received by the gift card service. */ expirationDate?: Date | null | undefined; /** * The amount remaining on the balance for this gift card according to the gift card service. This may be `null` if the balance could not be fetched. */ balance?: number | null | undefined; /** * If the last balance update failed, this will contain the internal code for this error. */ balanceErrorCode?: GiftCardErrorCode | null | undefined; /** * If the last balance update failed, this will contain the the raw error code received from the gift card provider. */ balanceRawErrorCode?: string | null | undefined; /** * If the last balance update failed, this will contain the the raw error message received from the gift card provider. */ balanceRawErrorMessage?: string | null | undefined; /** * The timestamp when this gift card was last used in a transaction. */ lastUsedAt?: Date | null | undefined; /** * The number of times this gift card has been used in transactions. */ usageCount: number; /** * The timestamp when this gift card was last used in a transaction for client initiated transactions. */ citLastUsedAt?: Date | null | undefined; /** * The number of times this gift card has been used in transactions for client initiated transactions. */ citUsageCount: number; }; /** @internal */ export const GiftCardSummary$inboundSchema: z.ZodType< GiftCardSummary, z.ZodTypeDef, unknown > = z.object({ type: z.literal("gift-card").default("gift-card"), id: z.nullable(z.string()).optional(), merchant_account_id: z.string(), bin: z.string(), sub_bin: z.string(), last4: z.string(), currency: z.nullable(z.string()).optional(), expiration_date: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), balance: z.nullable(z.number().int()).optional(), balance_error_code: z.nullable(GiftCardErrorCode$inboundSchema).optional(), balance_raw_error_code: z.nullable(z.string()).optional(), balance_raw_error_message: z.nullable(z.string()).optional(), last_used_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), usage_count: z.number().int(), cit_last_used_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), cit_usage_count: z.number().int(), }).transform((v) => { return remap$(v, { "merchant_account_id": "merchantAccountId", "sub_bin": "subBin", "expiration_date": "expirationDate", "balance_error_code": "balanceErrorCode", "balance_raw_error_code": "balanceRawErrorCode", "balance_raw_error_message": "balanceRawErrorMessage", "last_used_at": "lastUsedAt", "usage_count": "usageCount", "cit_last_used_at": "citLastUsedAt", "cit_usage_count": "citUsageCount", }); }); export function giftCardSummaryFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GiftCardSummary$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GiftCardSummary' from JSON`, ); }