import {z} from 'zod' export type GetApiPaymentLinksPaymentLinkIdPaymentsArgs = {from?: string | undefined, limit?: (number | null) | undefined, sort?: string | undefined, testmode?: boolean | undefined}; export type GetApiPaymentLinksPaymentLinkIdPaymentsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPaymentLinksPaymentLinkIdPaymentsResponse = z.object({count: z.number().int().gte(0).lte(250), _embedded: z.object({payments: z.array(z.object({resource: z.string(), id: z.string(), mode: z.string(), description: z.string().max(255), amount: z.object({currency: z.string(), value: z.string()}), amountRefunded: z.object({currency: z.string(), value: z.string()}).optional(), amountRemaining: z.object({currency: z.string(), value: z.string()}).optional(), amountCaptured: z.object({currency: z.string(), value: z.string()}).optional(), amountChargedBack: z.object({currency: z.string(), value: z.string()}).optional(), settlementAmount: z.object({currency: z.string(), value: z.string()}).optional(), redirectUrl: z.string().nullable().optional(), cancelUrl: z.string().nullable().optional(), webhookUrl: z.string().nullable().optional(), lines: z.array(z.object({type: z.string().optional(), description: z.string(), quantity: z.number().int().gte(1), quantityUnit: z.string().optional(), unitPrice: z.object({currency: z.string(), value: z.string()}), discountAmount: z.object({currency: z.string(), value: z.string()}).optional(), totalAmount: z.object({currency: z.string(), value: z.string()}), vatRate: z.string().optional(), vatAmount: z.object({currency: z.string(), value: z.string()}).optional(), sku: z.string().max(64).optional(), categories: z.array(z.enum(["eco", "gift", "meal", "sport_culture", "additional", "consume"])).optional(), imageUrl: z.string().optional(), productUrl: z.string().optional(), recurring: z.object({description: z.string().optional(), interval: z.string(), amount: z.object({currency: z.string(), value: z.string()}).optional(), times: z.number().int().optional(), startDate: z.string().nullable().optional()}).optional()})).nullable().optional(), billingAddress: z.object({title: z.string().optional(), givenName: z.string().optional(), familyName: z.string().optional(), organizationName: z.string().optional(), streetAndNumber: z.string().optional(), streetAdditional: z.string().optional(), postalCode: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), city: z.string().optional(), region: z.string().optional(), country: z.string().optional()}).optional(), shippingAddress: z.object({title: z.string().optional(), givenName: z.string().optional(), familyName: z.string().optional(), organizationName: z.string().optional(), streetAndNumber: z.string().optional(), streetAdditional: z.string().optional(), postalCode: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), city: z.string().optional(), region: z.string().optional(), country: z.string().optional()}).optional(), locale: z.string().nullable().optional(), countryCode: z.string().min(2).max(2).nullable().optional(), method: z.string().nullable().optional(), issuer: z.string().nullable().optional(), restrictPaymentMethodsToCountry: z.string().nullable().optional(), metadata: z.union([z.string(), z.number(), z.record(z.string(), z.unknown()), z.array(z.string())]).nullable().optional(), captureMode: z.string().nullable().optional(), captureDelay: z.string().nullable().optional(), captureBefore: z.string().nullable().optional(), applicationFee: z.object({amount: z.object({currency: z.string(), value: z.string()}), description: z.string().max(255)}).nullable().optional(), routing: z.array(z.object({resource: z.string(), id: z.string(), mode: z.string(), amount: z.object({currency: z.string(), value: z.string()}), destination: z.object({type: z.string(), organizationId: z.string()}), createdAt: z.string(), releaseDate: z.string().nullable().optional(), _links: z.object({self: z.object({href: z.string(), type: z.string()}), payment: z.object({href: z.string(), type: z.string()})})})).nullable().optional(), sequenceType: z.string(), subscriptionId: z.string().nullable().optional(), mandateId: z.string().nullable().optional(), customerId: z.string().nullable().optional(), profileId: z.string(), settlementId: z.string().nullable().optional(), orderId: z.string().nullable().optional(), status: z.string(), statusReason: z.object({code: z.string(), message: z.string()}).nullable().optional(), isCancelable: z.boolean().nullable().optional(), details: z.object({}).nullable().optional(), createdAt: z.string(), authorizedAt: z.string().nullable().optional(), paidAt: z.string().nullable().optional(), canceledAt: z.string().nullable().optional(), expiresAt: z.string().nullable().optional(), expiredAt: z.string().nullable().optional(), failedAt: z.string().nullable().optional(), dueDate: z.string().nullable().optional(), storeCredentials: z.boolean().optional(), testmode: z.boolean().nullable().optional(), _links: z.object({self: z.object({href: z.string(), type: z.string()}), checkout: z.object({href: z.string(), type: z.string()}).optional(), changePaymentState: z.object({href: z.string().optional(), type: z.string().optional()}).nullable().optional(), dashboard: z.object({href: z.string(), type: z.string()}), refunds: z.object({href: z.string(), type: z.string()}).optional(), chargebacks: z.object({href: z.string(), type: z.string()}).optional(), captures: z.object({href: z.string(), type: z.string()}).optional(), settlement: z.object({href: z.string(), type: z.string()}).optional(), customer: z.object({href: z.string(), type: z.string()}).optional(), mandate: z.object({href: z.string(), type: z.string()}).optional(), subscription: z.object({href: z.string(), type: z.string()}).optional(), order: z.object({href: z.string(), type: z.string()}).optional()})})).optional()}), _links: z.object({self: z.object({href: z.string(), type: z.string()}), previous: z.object({href: z.string().optional(), type: z.string().optional()}).nullable(), next: z.object({href: z.string().optional(), type: z.string().optional()}).nullable(), documentation: z.object({href: z.string(), type: z.string()})})}); 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 payment link payments * * GET /payment-links/{paymentLinkId}/payments * * Also accepts auth: advancedAccessToken, oAuth */ export const getApiPaymentLinksPaymentLinkIdPayments = async (args: GetApiPaymentLinksPaymentLinkIdPaymentsArgs, options?: GetApiPaymentLinksPaymentLinkIdPaymentsOptions) => { const {baseUrl = "https://api.mollie.com/v2", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/hal+json") if (args.from != null) query.append("from", String(args.from)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.testmode != null) query.append("testmode", String(args.testmode)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/payment-links/${encodeURIComponent(String(args.paymentLinkId))}/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(getApiPaymentLinksPaymentLinkIdPaymentsResponse, await res.json()) };