import {z} from 'zod' export type UpdateApiApiV1PaymentLinksLinkIdActivateArgs = {linkId: string}; export type UpdateApiApiV1PaymentLinksLinkIdActivateOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const linkType = z.enum(["one_time", "multiple"]); export const cryptoCurrency = z.enum(["usdc", "usdt", "pyusd", "eurc", "brett", "dai", "btc", "eth", "matic", "bnb", "sol", "busd", "trx", "food", "bonk", "wif", "goat", "spx", "truf", "pengu"]); export const customFieldType = z.enum(["text", "numeric", "dropdown"]); export const customFieldLabelType = z.literal("custom"); export const customFieldLabelDto = z.object({type: customFieldLabelType.optional(), custom: z.string()}); export const paymentLinkCustomFieldsDto = z.object({key: z.string(), type: customFieldType, label: customFieldLabelDto, optional: z.boolean()}); export const paymentLinkCustomFieldDto = z.object({fields: z.array(paymentLinkCustomFieldsDto).optional()}); export const submitType = z.enum(["pay", "book", "donate"]); export const afterCompletionLink = z.enum(["redirect", "hosted_confirmation"]); export const paymentLinkChainDto = z.object({chainId: z.number(), isPreferred: z.boolean()}); export const interval = z.enum(["day", "week", "month", "year"]); export const priceType = z.enum(["one_time", "recurring", "streaming"]); export const paymentLinkDto = z.object({id: z.string(), createdAt: z.string().optional(), updatedAt: z.string().optional(), organizationId: z.string(), type: linkType, amount: z.number().int().optional(), currency: cryptoCurrency.optional(), currencies: z.array(cryptoCurrency).optional(), preferredCurrency: cryptoCurrency.optional(), title: z.string(), description: z.string().optional(), image: z.string().optional(), publicImage: z.string().optional(), tags: z.array(z.string()), isActive: z.boolean().optional(), nameCollection: z.boolean(), emailCollection: z.boolean(), phoneNumberCollection: z.boolean(), shippingAddressCollection: z.boolean(), billingAddressCollection: z.boolean(), customFields: paymentLinkCustomFieldDto.optional(), submitType: submitType, afterCompletion: afterCompletionLink, afterCompletionRedirectUrl: z.string().optional(), afterCompletionConfirmMsg: z.string().optional(), suggestedCurrency: cryptoCurrency.optional(), suggestedAmounts: z.array(z.string()).optional(), productId: z.string().optional(), allowedChains: z.array(paymentLinkChainDto).optional(), interval: interval.optional(), intervalCount: z.number().optional(), priceType: priceType, allowPromotionCodes: z.boolean().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 }; /** * Activate a payment link * * PUT /api/v1/payment-links/{linkId}/activate */ export const updateApiApiV1PaymentLinksLinkIdActivate = async (args: UpdateApiApiV1PaymentLinksLinkIdActivateArgs, options?: UpdateApiApiV1PaymentLinksLinkIdActivateOptions) => { const {baseUrl = "https://api.copperx.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/payment-links/${encodeURIComponent(String(args.linkId))}/activate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paymentLinkDto, await res.json()) };