import {z} from 'zod' export type GetApiApiPricingV2PricingPlanMerchantNumberArgs = {merchantNumber: string, effectiveDate?: string | undefined, outof100?: boolean | undefined, useDisplayFees?: boolean | undefined}; export type GetApiApiPricingV2PricingPlanMerchantNumberOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const planFee = z.object({clearentPricingFeeID: z.number().int().optional(), pricingFeeDescription: z.string().nullable().optional(), rate: z.number().nullable().optional(), fee: z.number().nullable().optional(), payInMonth1: z.number().int().nullable().optional(), payInMonth2: z.number().int().nullable().optional()}); export const businessPricingPlan = z.object({pricingFees: z.array(planFee).nullable().optional(), pricingPlanID: z.number().int().optional(), pricingPlanTemplateID: z.number().int().optional(), merchantNumber: z.string().nullable().optional(), discountQualificationRangeID: z.number().int().nullable().optional(), signatureDebitDiscountQualificationRangeID: z.number().int().nullable().optional(), pricingTypeCode: z.string().optional(), isAdvancedPricing: z.boolean().optional(), isEMF: z.boolean().optional(), isDailySettle: z.boolean().optional(), includeAssessments: z.boolean().optional(), effectiveStartDateTimeUTC: z.string().nullable().optional(), effectiveEndDateTimeUTC: z.string().nullable().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 pricing plan * * GET /api/pricing/v2/PricingPlan/{merchantNumber} */ export const getApiApiPricingV2PricingPlanMerchantNumber = async (args: GetApiApiPricingV2PricingPlanMerchantNumberArgs, options: GetApiApiPricingV2PricingPlanMerchantNumberOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.effectiveDate != null) query.append("effectiveDate", String(args.effectiveDate)) if (args.outof100 != null) query.append("outof100", String(args.outof100)) if (args.useDisplayFees != null) query.append("useDisplayFees", String(args.useDisplayFees)) const url = `${baseUrl.replace(/\/+$/, '')}/api/pricing/v2/PricingPlan/${encodeURIComponent(String(args.merchantNumber))}${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(businessPricingPlan, await res.json()) };