/* * 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 { Buyer, Buyer$inboundSchema } from "./buyer.js"; import { GiftCardService, GiftCardService$inboundSchema, } from "./giftcardservice.js"; export type GiftCard = { /** * Always `gift-card`. */ type: "gift-card"; /** * The ID for the gift card. */ id: string; /** * The ID of the merchant account this buyer belongs to. */ merchantAccountId: string; giftCardService: GiftCardService; /** * 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 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 buyer for which this gift card is stored. */ buyer?: Buyer | null | undefined; /** * The date this gift card record was created at. */ createdAt: Date; /** * The date this gift card record was last updated at. */ updatedAt: Date; /** * 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 GiftCard$inboundSchema: z.ZodType< GiftCard, z.ZodTypeDef, unknown > = z.object({ type: z.literal("gift-card").default("gift-card"), id: z.string(), merchant_account_id: z.string(), gift_card_service: GiftCardService$inboundSchema, bin: z.string(), sub_bin: z.string(), last4: z.string(), expiration_date: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), buyer: z.nullable(Buyer$inboundSchema).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)), 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", "gift_card_service": "giftCardService", "sub_bin": "subBin", "expiration_date": "expirationDate", "created_at": "createdAt", "updated_at": "updatedAt", "last_used_at": "lastUsedAt", "usage_count": "usageCount", "cit_last_used_at": "citLastUsedAt", "cit_usage_count": "citUsageCount", }); }); export function giftCardFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GiftCard$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GiftCard' from JSON`, ); }