import {z} from 'zod' export type LegacyCouponPaymentRequest = {couponCode: string}; export type CreateApiApiV1PartnerResidencyApplicationsIdPayCouponArgs = {id: string, 'Idempotency-Key': string, body: LegacyCouponPaymentRequest}; export type CreateApiApiV1PartnerResidencyApplicationsIdPayCouponOptions = {baseUrl?: string | undefined, partnerKey?: string | undefined, fetch?: typeof fetch | undefined}; export const partnerResidencyApplication = z.object({id: z.string(), version: z.number().int().gt(0), statusId: z.enum(["Draft", "Pending Review", "Approved", "Rejected"]), applicationVersion: z.string(), submittedAt: z.string().nullable(), createdAt: z.string(), approvedAt: z.string().nullable(), rejectedAt: z.string().nullable(), residentPermitNumber: z.string().nullable(), referralCode: z.string().nullable(), applicationData: z.object({residencyType: z.enum(["limited_e_resident", "e_resident", "resident_annual", "null"]).nullable(), aoc: z.object({aocId: z.string().nullable(), signed: z.boolean(), signedByName: z.string().nullable(), signedAt: z.string().nullable(), agentAuthorized: z.boolean()}), personalDetails: z.object({givenName: z.string(), surname: z.string(), email: z.string(), dateOfBirth: z.string(), sex: z.string(), countryOfBirth: z.string().min(2).max(2).nullable(), citizenships: z.array(z.string().min(2).max(2)), alternateNamesAttestation: z.boolean(), alternateNames: z.string().nullable(), criminalBackgroundAttestation: z.boolean(), proofOfAddressUploadId: z.string().nullable(), address: z.object({line1: z.string().nullable(), line2: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), postalCode: z.string().nullable(), country: z.string().min(2).max(2).nullable()}), phoneNumber: z.string().nullable()}).nullable(), information: z.object({residencyReason: z.string().nullable(), referralSource: z.string().nullable()})}), applicantPortalAccess: z.object({email: z.string().nullable(), hasLoggedIn: z.boolean(), lastLogin: z.string().nullable(), claimLinkSent: z.boolean(), claimLinkSentAt: z.string().nullable()}), nextSteps: z.object({agreementUrl: z.string().nullable(), proofOfAddressRequired: z.boolean(), paymentRequired: z.boolean(), verificationRequired: z.boolean(), verificationInstructions: z.string().nullable(), submitReady: z.boolean()})}); export const createApiApiV1PartnerResidencyApplicationsIdPayCouponResponse = z.object({data: partnerResidencyApplication}); 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 }; /** * Deprecated partner coupon-payment alias * * POST /api/v1/partner/residency_applications/{id}/pay/coupon */ export const createApiApiV1PartnerResidencyApplicationsIdPayCoupon = async (args: CreateApiApiV1PartnerResidencyApplicationsIdPayCouponArgs, options?: CreateApiApiV1PartnerResidencyApplicationsIdPayCouponOptions) => { const {baseUrl = "https://portal.eprospera.com", fetch: fetchFn = fetch, partnerKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (partnerKey !== undefined) headers.set('authorization', `Bearer ${partnerKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/partner/residency_applications/${encodeURIComponent(String(args.id))}/pay/coupon${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1PartnerResidencyApplicationsIdPayCouponResponse, await res.json()) };