import {z} from 'zod' export type GetApiLifetimeIsaManagerLisaManagerReferenceNumberAccountsAccountIdTransactionsTransactionIdPaymentsArgs = {Accept: 'application/vnd.hmrc.2.0+json', Authorization: string, lisaManagerReferenceNumber: string, accountId: string, transactionId: string}; export type GetApiLifetimeIsaManagerLisaManagerReferenceNumberAccountsAccountIdTransactionsTransactionIdPaymentsOptions = {baseUrl?: string | undefined, userRestricted?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiLifetimeIsaManagerLisaManagerReferenceNumberAccountsAccountIdTransactionsTransactionIdPaymentsResponse = z.object({transactionId: z.string(), transactionType: z.enum(["Payment", "Debt"]).optional(), paymentDate: z.string().optional(), paymentDueDate: z.string().optional(), paymentStatus: z.enum(["Paid", "Pending", "Due", "Collected", "Cancelled", "Void", "Superseded", "Charge refund cancelled"]), paymentReference: z.string().optional(), paymentAmount: z.number().optional(), supersededBy: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get the payment details for a bonus claim or withdrawal charge * * GET /lifetime-isa/manager/{lisaManagerReferenceNumber}/accounts/{accountId}/transactions/{transactionId}/payments */ export const getApiLifetimeIsaManagerLisaManagerReferenceNumberAccountsAccountIdTransactionsTransactionIdPayments = async (args: GetApiLifetimeIsaManagerLisaManagerReferenceNumberAccountsAccountIdTransactionsTransactionIdPaymentsArgs, options?: GetApiLifetimeIsaManagerLisaManagerReferenceNumberAccountsAccountIdTransactionsTransactionIdPaymentsOptions) => { const {baseUrl = "https://test-api.service.hmrc.gov.uk", fetch: fetchFn = fetch, userRestricted} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (userRestricted !== undefined) headers.set('authorization', `Bearer ${userRestricted}`) const url = `${baseUrl.replace(/\/+$/, '')}/lifetime-isa/manager/${encodeURIComponent(String(args.lisaManagerReferenceNumber))}/accounts/${encodeURIComponent(String(args.accountId))}/transactions/${encodeURIComponent(String(args.transactionId))}/payments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiLifetimeIsaManagerLisaManagerReferenceNumberAccountsAccountIdTransactionsTransactionIdPaymentsResponse, await res.json()) };