/** * Represents the last used payment method. */ export class LastUsedMethod { public id?: string; public type?: LastUsedMethodType; constructor(params?: { id?: string; type?: LastUsedMethodType }) { this.id = params?.id; this.type = params?.type; } } export function lastUsedMethodFromJson(json: any): LastUsedMethod { if (!json || typeof json !== 'object') { // Return an empty instance or handle error as needed return new LastUsedMethod(); } const { id, type } = json; return new LastUsedMethod({ id: typeof id === 'string' ? id : undefined, type: typeof type === 'string' ? lastUsedMethodTypeFromJson(type as LastUsedMethodTypeString) : undefined, }); } /** * Enum that represents possible last-used-method types in * canonical uppercase snake case. */ export enum LastUsedMethodType { CustomerBalance = 'CUSTOMER_BALANCE', SavedCard = 'SAVED_CARD', PaymentMethod = 'PAYMENT_METHOD', } /** * Type union listing all possible string representations * that might appear in JSON for LastUsedMethodType. */ export type LastUsedMethodTypeString = | 'customer_balance' | 'saved_card' | 'payment_method'; /** * Converts a JSON string value into a LastUsedMethodType enum member. * Throws an error if the value is unrecognized. */ export function lastUsedMethodTypeFromJson( json: LastUsedMethodTypeString ): LastUsedMethodType { const _jsonMap: Record = { customer_balance: LastUsedMethodType.CustomerBalance, saved_card: LastUsedMethodType.SavedCard, payment_method: LastUsedMethodType.PaymentMethod, }; const method = _jsonMap[json]; if (method !== undefined) { return method; } throw new Error(`Unsupported LastUsedMethodType JSON value: ${json}`); }