/* * 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 { CardScheme, CardScheme$inboundSchema } from "./cardscheme.js"; import { Method, Method$inboundSchema } from "./method.js"; import { Mode, Mode$inboundSchema } from "./mode.js"; import { PaymentMethodDetailsCard, PaymentMethodDetailsCard$inboundSchema, } from "./paymentmethoddetailscard.js"; import { PaymentMethodStatus, PaymentMethodStatus$inboundSchema, } from "./paymentmethodstatus.js"; /** * Payment Method * * @remarks * * A stored payment method. */ export type PaymentMethod = { /** * Always `payment-method`. */ type: "payment-method"; /** * The optional URL that the buyer needs to be redirected to to further authorize their payment. */ approvalUrl?: string | null | undefined; /** * The 2-letter ISO code of the country this payment method can be used for. If this value is null the payment method may be used in multiple countries. */ country?: string | null | undefined; /** * The ISO-4217 currency code that this payment method can be used for. If this value is null the payment method may be used for multiple currencies. */ currency?: string | null | undefined; /** * Details for credit or debit card payment method. */ details?: PaymentMethodDetailsCard | null | undefined; /** * The expiration date for the payment method. */ expirationDate?: string | null | undefined; /** * The unique hash derived from the payment method identifier (e.g. card number). */ fingerprint?: string | null | undefined; /** * A label for the card or the account. For a paypal payment method this is the user's email address. For a card it is the last 4 digits of the card. */ label?: string | null | undefined; /** * The date and time when this card was last replaced by the account updater. */ lastReplacedAt?: Date | null | undefined; method: Method; /** * The mode to use with this payment method. */ mode?: Mode | null | undefined; /** * The scheme of the card. Only applies to card payments. */ scheme?: CardScheme | null | undefined; /** * The ID for the payment method. */ id: string; /** * The ID of the merchant account this buyer belongs to. */ merchantAccountId: string; /** * Additional schemes of the card besides the primary scheme. Only applies to card payment methods. */ additionalSchemes?: Array | null | undefined; /** * The timestamp when this payment method was last used in a transaction for client initiated transactions. */ citLastUsedAt?: Date | null | undefined; /** * The number of times this payment method has been used in transactions for client initiated transactions. */ citUsageCount: number; /** * Whether this card has a pending replacement that hasn't been applied yet. */ hasReplacement: boolean; /** * The timestamp when this payment method was last used in a transaction. */ lastUsedAt?: Date | null | undefined; /** * The number of times this payment method has been used in transactions. */ usageCount: number; /** * The scheme transaction identifier stored against this payment method. */ schemeTransactionId: string | null; /** * The scheme associated with scheme_transaction_id. Only applies to card payments. */ schemeTransactionIdScheme: CardScheme | null; /** * The transaction link identifier stored against this payment method. */ transactionLinkId?: string | null | undefined; /** * The optional buyer for which this payment method has been stored. */ buyer?: Buyer | null | undefined; /** * The merchant reference that can be used to match the payment method against your own records. */ externalIdentifier?: string | null | undefined; status: PaymentMethodStatus; /** * The date and time when this payment method was first created in our system. */ createdAt: Date; /** * The date and time when this payment method was last updated in our system. */ updatedAt: Date; }; /** @internal */ export const PaymentMethod$inboundSchema: z.ZodType< PaymentMethod, z.ZodTypeDef, unknown > = z.object({ type: z.literal("payment-method").default("payment-method"), approval_url: z.nullable(z.string()).optional(), country: z.nullable(z.string()).optional(), currency: z.nullable(z.string()).optional(), details: z.nullable(PaymentMethodDetailsCard$inboundSchema).optional(), expiration_date: z.nullable(z.string()).optional(), fingerprint: z.nullable(z.string()).optional(), label: z.nullable(z.string()).optional(), last_replaced_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), method: Method$inboundSchema, mode: z.nullable(Mode$inboundSchema).optional(), scheme: z.nullable(CardScheme$inboundSchema).optional(), id: z.string(), merchant_account_id: z.string(), additional_schemes: z.nullable(z.array(CardScheme$inboundSchema)).optional(), cit_last_used_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), cit_usage_count: z.number().int(), has_replacement: z.boolean(), last_used_at: z.nullable( z.string().datetime({ offset: true }).transform(v => new Date(v)), ).optional(), usage_count: z.number().int(), scheme_transaction_id: z.nullable(z.string()), scheme_transaction_id_scheme: z.nullable(CardScheme$inboundSchema), transaction_link_id: z.nullable(z.string()).optional(), buyer: z.nullable(Buyer$inboundSchema).optional(), external_identifier: z.nullable(z.string()).optional(), status: PaymentMethodStatus$inboundSchema, created_at: z.string().datetime({ offset: true }).transform(v => new Date(v)), updated_at: z.string().datetime({ offset: true }).transform(v => new Date(v)), }).transform((v) => { return remap$(v, { "approval_url": "approvalUrl", "expiration_date": "expirationDate", "last_replaced_at": "lastReplacedAt", "merchant_account_id": "merchantAccountId", "additional_schemes": "additionalSchemes", "cit_last_used_at": "citLastUsedAt", "cit_usage_count": "citUsageCount", "has_replacement": "hasReplacement", "last_used_at": "lastUsedAt", "usage_count": "usageCount", "scheme_transaction_id": "schemeTransactionId", "scheme_transaction_id_scheme": "schemeTransactionIdScheme", "transaction_link_id": "transactionLinkId", "external_identifier": "externalIdentifier", "created_at": "createdAt", "updated_at": "updatedAt", }); }); export function paymentMethodFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => PaymentMethod$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'PaymentMethod' from JSON`, ); }