import {z} from 'zod' export type RoutableConnectors = 'absa_sanlam' | 'authipay' | 'adyenplatform' | 'stripe_billing_test' | 'phonypay' | 'fauxpay' | 'pretendpay' | 'stripe_test' | 'adyen_test' | 'checkout_test' | 'paypal_test' | 'aci' | 'adyen' | 'affirm' | 'airwallex' | 'amazonpay' | 'archipel' | 'authorizedotnet' | 'bankofamerica' | 'barclaycard' | 'billwerk' | 'bitpay' | 'bambora' | 'blackhawknetwork' | 'bamboraapac' | 'bluesnap' | 'calida' | 'boku' | 'braintree' | 'breadpay' | 'cashtocode' | 'celero' | 'chargebee' | 'custombilling' | 'checkbook' | 'checkout' | 'coinbase' | 'coingate' | 'cryptopay' | 'cybersource' | 'cybersourcedecisionmanager' | 'datatrans' | 'deutschebank' | 'digitalvirgo' | 'dlocal' | 'dwolla' | 'ebanx' | 'elavon' | 'envoy' | 'facilitapay' | 'finix' | 'fiserv' | 'fiservemea' | 'fiservcommercehub' | 'fiuu' | 'flexiti' | 'forte' | 'getnet' | 'gigadat' | 'givepayments' | 'globalpay' | 'globepay' | 'gocardless' | 'hipay' | 'helcim' | 'hyperpg' | 'iatapay' | 'imerchantsolutions' | 'inespay' | 'interpayments' | 'itaubank' | 'jpmorgan' | 'klarna' | 'loonio' | 'mifinity' | 'mollie' | 'moneris' | 'multisafepay' | 'nexinets' | 'nexixpay' | 'nmi' | 'nomupay' | 'noon' | 'nordea' | 'novalnet' | 'nuvei' | 'opennode' | 'paybox' | 'payme' | 'payload' | 'payone' | 'paypal' | 'paysafe' | 'paystack' | 'paytm' | 'payconex' | 'payu' | 'peachpayments' | 'payjustnow' | 'payjustnowinstore' | 'phonepe' | 'placetopay' | 'powertranz' | 'prophetpay' | 'rapyd' | 'razorpay' | 'recurly' | 'redsys' | 'revolv3' | 'riskified' | 'santander' | 'shift4' | 'signifyd' | 'silverflow' | 'square' | 'stax' | 'stripe' | 'stripebilling' | 'tesouro' | 'truelayer' | 'trustly' | 'trustpay' | 'trustpayments' | 'tokenio' | 'tsys' | 'tsys_transit' | 'volt' | 'wellsfargo' | 'wise' | 'worldline' | 'worldpay' | 'worldpaymodular' | 'worldpayvantiv' | 'worldpayxml' | 'xendit' | 'zen' | 'zift' | 'plaid' | 'zsl' | 'juspaythreedsserver' | 'ctp_mastercard' | 'ctp_visa' | 'netcetera' | 'cardinal' | 'threedsecureio'; export type RoutableConnectorChoice = {connector: RoutableConnectors, merchant_connector_id?: (string | null) | undefined}; export type CreateApiRoutingDefaultProfileProfileIdArgs = {profile_id: string, body: Array}; export type CreateApiRoutingDefaultProfileProfileIdOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const profileDefaultRoutingConfig = z.object({profile_id: 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 }; /** * Routing - Update Default For Profile * * POST /routing/default/profile/{profile_id} * * Also accepts auth: jwt_key */ export const createApiRoutingDefaultProfileProfileId = async (args: CreateApiRoutingDefaultProfileProfileIdArgs, options: CreateApiRoutingDefaultProfileProfileIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/routing/default/profile/${encodeURIComponent(String(args.profile_id))}${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(profileDefaultRoutingConfig, await res.json()) };