import {z} from 'zod' export type CreateApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdAuthorizeArgs = {workflowCode: string, executionId: string, 'x-idempotency-key': string, body: {amount: {value: string, currency: string}, meta?: ({order?: ({reference?: string | undefined, description?: string | undefined, softDescriptor?: string | undefined, storeId?: string | undefined, placement?: ({country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, city?: string | undefined}) | undefined, deliveryAddress?: ({street?: string | undefined, doorNumber?: string | undefined, complement?: string | undefined, area?: string | undefined, city?: string | undefined, postalCode?: string | undefined, state?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, latitude?: number | undefined, longitude?: number | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, alias?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined}) | undefined, deliveryAddressPreference?: ('noShipping' | 'userPreSpecified' | 'allowProviderOverride') | undefined, deliveryDate?: string | undefined, billingAddress?: ({street?: string | undefined, doorNumber?: string | undefined, complement?: string | undefined, area?: string | undefined, city?: string | undefined, postalCode?: string | undefined, state?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, latitude?: number | undefined, longitude?: number | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, alias?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined}) | undefined, shippingType?: ('pickup' | 'physical' | 'hybrid' | 'digital') | undefined, shipping?: {value: string, currency: string} | undefined, totalDiscount?: {value: string, currency: string} | undefined, totalTax?: {value: string, currency: string} | undefined, lines?: (Array<{name?: string | undefined, description?: string | undefined, product?: ({type?: ('physical' | 'digital' | 'service') | undefined}) | undefined, type?: ('lineItem' | 'discount' | 'tax') | undefined, quantity?: number | undefined, unitPrice?: {value: string, currency: string} | undefined, total?: {value: string, currency: string} | undefined, taxPercentage?: {value: string} | undefined, totalDiscount?: {value: string, currency: string} | undefined, totalTax?: {value: string, currency: string} | undefined, id?: string | undefined, links?: ({productUrl?: string | undefined, imageUrl?: string | undefined}) | undefined, travelTicket?: ({ticketId?: string | undefined, passengers?: (Array<{name?: string | undefined, lastName?: string | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, passengerType?: ('adult' | 'child' | 'infant' | 'senior') | undefined, email?: string | undefined}>) | undefined, routes?: (Array<{legs?: (Array<{legId?: string | undefined, departure?: ({city?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, time?: string | undefined}) | undefined, arrival?: ({city?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, time?: string | undefined}) | undefined}>) | undefined}>) | undefined}) | undefined}>) | undefined, total?: {value: string, currency: string} | undefined, processingType?: ('Regular' | 'Subscription' | 'CardOnFile' | 'UnscheduledCardOnFile' | 'MOTO' | 'InPerson') | undefined, createdAt?: string | undefined, pendingStateDuration?: string | undefined, fundsTransfer?: ({type?: ('disbursement' | 'personToPerson' | 'accountToAccount' | 'topUp' | 'purchase' | 'cash' | 'walletLoad') | undefined, purpose?: ('donation' | 'education' | 'emergency' | 'expatriation' | 'familySupport' | 'financialServices' | 'gifts' | 'income' | 'insurance' | 'investment' | 'itServices' | 'leisure' | 'loanPayment' | 'medical' | 'business' | 'crypto' | 'assets' | 'prepaid' | 'crowdLending' | 'debitCard' | 'giftCard' | 'gaming' | 'highRiskSecurities' | 'salary' | 'pension' | 'royalities' | 'savings' | 'travelAndTourism' | 'other') | undefined, recipient?: ({account?: ({type?: ('bankAccount' | 'card' | 'wallet' | 'storedValueWallet' | 'stagedDigitalWallet' | 'merchantWallet' | 'email' | 'phone' | 'socialNetwork') | undefined, identifierType?: ('iban' | 'swift' | 'routingNumber') | undefined, iban?: string | undefined, accountNumber?: string | undefined, bankCode?: string | undefined, routingNumber?: string | undefined, reference?: string | undefined}) | undefined, customer?: ({reference?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined, type?: string | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, birthDate?: string | undefined, language?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, identityCardNumber?: string | undefined, identityCardType?: string | undefined, createdAt?: string | undefined}) | undefined, address?: ({street?: string | undefined, doorNumber?: string | undefined, complement?: string | undefined, area?: string | undefined, city?: string | undefined, postalCode?: string | undefined, state?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, latitude?: number | undefined, longitude?: number | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, alias?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined}) | undefined}) | undefined, sender?: ({customer?: ({reference?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined, type?: string | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, birthDate?: string | undefined, language?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, identityCardNumber?: string | undefined, identityCardType?: string | undefined, createdAt?: string | undefined}) | undefined, address?: ({street?: string | undefined, doorNumber?: string | undefined, complement?: string | undefined, area?: string | undefined, city?: string | undefined, postalCode?: string | undefined, state?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, latitude?: number | undefined, longitude?: number | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, alias?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined}) | undefined, type?: ('individual' | 'corporate' | 'instrument') | undefined, companyName?: string | undefined}) | undefined}) | undefined}) | undefined, customer?: ({reference?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined, type?: string | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, birthDate?: string | undefined, language?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, identityCardNumber?: string | undefined, identityCardType?: string | undefined, createdAt?: string | undefined}) | undefined, clientContext?: ({ipAddress?: string | undefined, userAgent?: string | undefined, acceptHeader?: string | undefined, clientType?: ('desktop' | 'mobile' | 'app') | undefined, osType?: ('ios' | 'android') | undefined, osVersion?: string | undefined, deviceFingerprint?: string | undefined, javaEnabled?: boolean | undefined, javaScriptEnabled?: boolean | undefined, cookiesAccepted?: boolean | undefined, language?: string | undefined, colorDepth?: number | undefined, screenHeight?: number | undefined, screenWidth?: number | undefined, timeZoneOffset?: number | undefined, origin?: string | undefined, host?: string | undefined}) | undefined, vendor?: ({reference?: string | undefined, name?: string | undefined, address?: ({street?: string | undefined, doorNumber?: string | undefined, complement?: string | undefined, area?: string | undefined, city?: string | undefined, postalCode?: string | undefined, state?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, latitude?: number | undefined, longitude?: number | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, alias?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined}) | undefined, device?: ({reference?: string | undefined}) | undefined, subMerchants?: (Array<{id?: string | undefined, name?: string | undefined, address?: ({street?: string | undefined, doorNumber?: string | undefined, complement?: string | undefined, area?: string | undefined, city?: string | undefined, postalCode?: string | undefined, state?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, latitude?: number | undefined, longitude?: number | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, alias?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined}) | undefined, amount?: {value: string, currency: string} | undefined}>) | undefined}) | undefined, risk?: ({score?: string | undefined, skipPaymentProviderRules?: boolean | undefined, force3DS?: boolean | undefined, threeDSMode?: ('Skip' | 'Force' | 'Default') | undefined, allowNative3DS?: boolean | undefined, sessionId?: string | undefined, exemptionIndicator?: ('lowValue' | 'transactionRiskAnalysis' | 'secureCorporate' | 'trustedBeneficiary' | 'trustedBeneficiaryPrompt' | 'dataShare') | undefined}) | undefined, subscription?: ({chargeFrequency?: string | undefined, expiration?: string | undefined}) | undefined, tags?: {[key: string]: string} | undefined} | {[key: string]: unknown}) | undefined, returnInfo: {success: string, cancel?: string | undefined, error?: string | undefined, pending?: string | undefined}, paymentComposition: Array<{paymentMethodCode?: ('alexBankMa7fazty' | 'amazonPay' | 'applePay' | 'audi2pay' | 'alfa' | 'alipay' | 'bankTransfer' | 'card' | 'capitecPay' | 'cibSmartWallet' | 'easypaisa' | 'etisalatCash' | 'fawryMobileWallet' | 'fawryPay' | 'googlePay' | 'jazzCash' | 'mercadoPago' | 'monoDirectDebit' | 'nbePhoneCash' | 'orangeCash' | 'oPayWallet' | 'pagaWallet' | 'payflex' | 'payjustnow' | 'payPal' | 'pix' | 'konnect' | 'qnbEWallet' | 'wafaCashWallet' | 'weCash' | 'genericRedirect' | 'eftPro' | 'upi' | 'cashFreeWallet' | 'paytmMWallet' | 'netBanking' | 'meezaWallet' | 'vodafoneCash' | 'alipayQRCode' | 'sepaDirectDebit' | 'dcb' | 'bankAccount' | 'modo' | 'ach' | 'payzoneCash' | 'revolutPay' | 'lean' | 'tabby' | 'boleto' | 'oxxo' | 'spei' | 'promptPay' | 'qris' | 'momoVN' | 'vietQR' | 'konbini' | 'touchNGo' | 'gCash' | 'maya' | 'pse' | 'pagoEfectivo' | 'napas' | 'duitNowQR' | 'grabPay' | 'shopeePay' | 'nequi' | 'picPay' | 'ovo' | 'trueMoney') | undefined, integrationType: 'api' | 'hpp' | 'inperson', amount: {value: string, currency: string}, paymentInstrumentId?: string | undefined, paymentInstrumentData?: ({paymentToken?: string | undefined, providerData?: ({[key: string]: unknown} | null) | undefined, vaultToken?: string | undefined, vaultProviderConfigId?: (string | null) | undefined, card?: ({[key: string]: unknown} | null) | undefined, encryptedData?: (string | null) | undefined, encryptedDataType?: ('card' | 'networkToken' | null) | undefined, futureUsage?: ('Subscription' | 'CardOnFile' | 'UnscheduledCardOnFile' | null) | undefined, merchantReference?: (string | null) | undefined, billingAddress?: ({street?: string | undefined, doorNumber?: string | undefined, complement?: string | undefined, area?: string | undefined, city?: string | undefined, postalCode?: string | undefined, state?: string | undefined, country?: ({code: string, iso3?: string | undefined, name?: string | undefined}) | undefined, latitude?: number | undefined, longitude?: number | undefined, phone?: ({countryCode?: string | undefined, number: string}) | undefined, alias?: string | undefined, name?: string | undefined, lastName?: string | undefined, email?: string | undefined} | null) | undefined, qrCode?: (string | null) | undefined, eci?: string | undefined, network?: ('unspecified' | 'visa' | 'visadankort' | 'mastercard' | 'amex' | 'diners' | 'discover' | 'unionpay' | 'unionpayuzcard' | 'maestro' | 'maestrobancontact' | 'hipercard' | 'jcb' | 'jcblankapay' | 'argencard' | 'aura' | 'belkart' | 'bpfuelcard' | 'cabal' | 'carnet' | 'cirrus' | 'chjonesfuelcard' | 'uzcard' | 'codensa' | 'dankort' | 'dinacard' | 'duet' | 'ebt' | 'eftpos' | 'elo' | 'euroshellfuelcard' | 'gecapital' | 'bc' | 'hrgstore' | 'humo' | 'lankapay' | 'lukoilfuelcard' | 'bancontact' | 'meeza' | 'newday' | 'mir' | 'ourocard' | 'pagobancomat' | 'paypak' | 'paypal' | 'phhfuelcard' | 'prostir' | 'rupay' | 'sbercard' | 'sodexo' | 'starrewards' | 'cencosud' | 'naranja' | 'troy' | 'uatp' | 'ukfuelcard' | 'verve' | 'voyager' | 'vpay' | 'wex' | 'cmi' | 'atm' | 'bankcard' | 'localbrand' | 'loyalty' | 'privatelabel' | 'fuelcard' | 'redfuelcard' | 'redliquidfuelcard') | undefined, preferredScheme?: ('unspecified' | 'visa' | 'visadankort' | 'mastercard' | 'amex' | 'diners' | 'discover' | 'unionpay' | 'unionpayuzcard' | 'maestro' | 'maestrobancontact' | 'hipercard' | 'jcb' | 'jcblankapay' | 'argencard' | 'aura' | 'belkart' | 'bpfuelcard' | 'cabal' | 'carnet' | 'cirrus' | 'chjonesfuelcard' | 'uzcard' | 'codensa' | 'dankort' | 'dinacard' | 'duet' | 'ebt' | 'eftpos' | 'elo' | 'euroshellfuelcard' | 'gecapital' | 'bc' | 'hrgstore' | 'humo' | 'lankapay' | 'lukoilfuelcard' | 'bancontact' | 'meeza' | 'newday' | 'mir' | 'ourocard' | 'pagobancomat' | 'paypak' | 'paypal' | 'phhfuelcard' | 'prostir' | 'rupay' | 'sbercard' | 'sodexo' | 'starrewards' | 'cencosud' | 'naranja' | 'troy' | 'uatp' | 'ukfuelcard' | 'verve' | 'voyager' | 'vpay' | 'wex' | 'cmi' | 'atm' | 'bankcard' | 'localbrand' | 'loyalty' | 'privatelabel' | 'fuelcard' | 'redfuelcard' | 'redliquidfuelcard') | undefined, displayName?: string | undefined, default?: (boolean | null) | undefined} | {[key: string]: unknown}) | undefined, storeInstrument?: boolean | undefined, enrollInstrumentToNetworkOffers?: boolean | undefined, installments?: ({count?: number | undefined} | {[key: string]: unknown} | null) | undefined}>}}; export type CreateApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdAuthorizeOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdAuthorizeResponse = z.object({name: z.literal("authorize"), actionId: z.string(), workspaceId: z.string().optional(), executedAt: z.string(), links: z.object({execution: z.union([z.string(), z.object({href: z.string(), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional()})]), consumerWait: z.union([z.string(), z.object({href: z.string(), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional()})]), capture: z.union([z.string(), z.object({href: z.string(), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional()})]).optional(), cancel: z.union([z.string(), z.object({href: z.string(), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional()})]), refund: z.union([z.string(), z.object({href: z.string(), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional()})]).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 }; /** * Authorize a payment * * POST /merchant/workflows/{workflowCode}/executions/{executionId}/authorize */ export const createApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdAuthorize = async (args: CreateApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdAuthorizeArgs, options?: CreateApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdAuthorizeOptions) => { const {baseUrl = "https://api.staging.payrails.io", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-idempotency-key'] != null) headers.set("x-idempotency-key", String(args['x-idempotency-key'])) if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/merchant/workflows/${encodeURIComponent(String(args.workflowCode))}/executions/${encodeURIComponent(String(args.executionId))}/authorize${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(createApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdAuthorizeResponse, await res.json()) };