import {z} from 'zod' export type CustomerActionRequest = {customerId: string, transactionId: string, txHash?: string | undefined, permitSignature?: string | undefined, flag?: string | undefined, paymentReceiptUploadId?: string | undefined}; export type CreateApiTransactionsOfframpCustomerApproveArgs = {body: CustomerActionRequest}; export type CreateApiTransactionsOfframpCustomerApproveOptions = {baseUrl?: string | undefined, HMACAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionsSvcTransactionType = z.enum(["ONRAMP", "OFFRAMP"]); export const transactionsSvcTradeMode = z.enum(["P2P", "IP", "OTC"]); export const transactionsSvcOfferDTO = z.object({offerId: z.string().optional(), partnerId: z.string(), transactionType: transactionsSvcTransactionType, rate: z.number(), networkId: z.string(), fiatSymbol: z.string().optional(), fiatAmount: z.number().optional(), token: z.string(), tokenAmount: z.number(), usdAmount: z.number().optional(), partnerDisplayName: z.string().optional(), adNote: z.string().optional(), instantPayEnabled: z.boolean(), instantPayPaymentAccountId: z.string().optional(), customPayinProvider: z.string().optional(), tradeMode: transactionsSvcTradeMode.optional()}); export const transactionsSvcWalletDTO = z.object({walletAddress: z.string().optional(), networkId: z.string().optional(), walletName: z.string().optional()}); export const transactionOrderStatus = z.enum(["INITIATED", "DEPOSITED", "CONFIRMED", "COMPLETED", "PENDING", "CANCELLED", "IN_DISPUTE", "AWAITING_ACCEPTANCE"]); export const timeoutDTO = z.object({name: z.enum(["APPROVE_TRANSACTION", "MAKE_DEPOSIT", "CONFIRM_DEPOSIT", "FLAG_DISPUTE", "ACKNOWLEDGE_TRANSACTION"]).optional(), startTime: z.string().optional(), duration: z.number().optional(), timeLeft: z.number().int().optional()}); export const userType = z.enum(["CUSTOMER", "PARTNER"]); export const fee = z.object({asToken: z.string(), asFiat: z.number()}); export const instantPayProcessingStatus = z.enum(["PENDING_IP_REPORT", "IN_PROGRESS", "FAILURE", "SUCCESS"]); export const thirdpartyOrderInfoDTO = z.object({businessId: z.string(), tradeId: z.string().optional(), product: z.string().optional(), blockchainOrderId: z.number().int().optional(), externalOrderReference: z.string().optional()}); export const tradeContext = z.enum(["STANDARD_TRADE", "INTERNAL_RAIL"]); export const transactionDTO = z.object({id: z.string(), reference: z.string(), customerId: z.string(), customerName: z.string().optional(), offer: transactionsSvcOfferDTO.optional(), escrowAddress: z.string().optional(), paymentChannelId: z.string().optional(), paymentMethod: z.object({}).optional(), buyerPaymentMethod: z.object({}).optional(), customerWallet: transactionsSvcWalletDTO.optional(), tokenAddress: z.string().optional(), status: transactionOrderStatus, createdAt: z.string().optional(), initiatedAt: z.string().optional(), depositedAt: z.string().optional(), confirmedAt: z.string().optional(), completedAt: z.string().optional(), cancelledAt: z.string().optional(), cancellationReason: z.string().optional(), disputeId: z.string().optional(), timeout: timeoutDTO.optional(), lockHash: z.string().optional(), confirmationHash: z.string().optional(), cancellationHash: z.string().optional(), isPartnerAcknowledged: z.boolean().optional(), defaultingParty: userType.optional(), rating: z.number().optional(), isCexOrder: z.boolean().optional(), fee: fee, instantPayProcessingStatus: instantPayProcessingStatus.optional(), tradeValue: z.number().optional(), merchantTokenValue: z.number().optional(), customerTokenValue: z.number().optional(), payableAmount: z.number().optional(), thirdpartyOrderInfo: thirdpartyOrderInfoDTO.optional(), isNoKyc: z.boolean().optional(), paymentReceiptUploadId: z.string().optional(), suppressCustomerNotifications: z.boolean().optional(), chatUnavailable: z.boolean().optional(), tradeContext: tradeContext.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 }; /** * Customer approves withdrawal from wallet * * POST /transactions/offramp/customer-approve */ export const createApiTransactionsOfframpCustomerApprove = async (args: CreateApiTransactionsOfframpCustomerApproveArgs, options?: CreateApiTransactionsOfframpCustomerApproveOptions) => { const {baseUrl = "https://external.dev.onboardpay.co", fetch: fetchFn = fetch, HMACAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HMACAuth !== undefined) headers.set("x-api-key", HMACAuth) const url = `${baseUrl.replace(/\/+$/, '')}/transactions/offramp/customer-approve${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(transactionDTO, await res.json()) };