import {z} from 'zod' export type CreateApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdCaptureArgs = {workflowCode: string, executionId: string, 'x-idempotency-key': string, body: {amount?: {value: string, currency: string} | undefined, reason?: ('BetterPrice' | 'CustomerDontNeed' | 'DamagedProduct' | 'Duplicate' | 'FraudulentProduct' | 'LateDelivery' | 'NoReason' | 'ProductMismatchDescription' | 'WrongProduct' | 'WrongProductSpecification') | undefined, reasonDescription?: string | undefined, 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, final?: boolean | undefined}}; export type CreateApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdCaptureOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdCaptureResponse = z.object({name: z.literal("capture"), 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()})]), refund: z.union([z.string(), z.object({href: z.string(), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional()})])}), reason: z.enum(["BetterPrice", "CustomerDontNeed", "DamagedProduct", "Duplicate", "FraudulentProduct", "LateDelivery", "NoReason", "ProductMismatchDescription", "WrongProduct", "WrongProductSpecification"]).optional(), reasonDescription: z.string().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 }; /** * Capture a payment * * POST /merchant/workflows/{workflowCode}/executions/{executionId}/capture */ export const createApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdCapture = async (args: CreateApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdCaptureArgs, options?: CreateApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdCaptureOptions) => { 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))}/capture${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(createApiMerchantWorkflowsWorkflowCodeExecutionsExecutionIdCaptureResponse, await res.json()) };