import {z} from 'zod' export type MarkPaymentAsRefundedDto = {markRefundedComment?: string | undefined}; export type CreateApiApiV1PaymentIntentsPaymentIntentIdMarkAsRefundArgs = {paymentIntentId: string, body: MarkPaymentAsRefundedDto}; export type CreateApiApiV1PaymentIntentsPaymentIntentIdMarkAsRefundOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const currency = z.enum(["usdc", "usdt", "pyusd", "eurc", "brett", "dai", "btc", "eth", "matic", "bnb", "sol", "busd", "trx", "food", "bonk", "wif", "goat", "spx", "truf", "pengu", "usd", "inr"]); export const paymentIntentStatus = z.enum(["requires_payment_method", "requires_confirmation", "requires_action", "processing", "requires_capture", "canceled", "succeeded"]); export const superTokenDto = z.object({address: z.string(), decimals: z.number(), symbol: z.string()}); export const assetDto = z.object({id: z.string(), name: z.string(), chainId: z.number(), address: z.string(), currency: currency, symbol: z.string(), decimals: z.number(), coingeckoId: z.string().optional(), superToken: superTokenDto.optional(), isEIP5827Supported: z.boolean()}); export const paymentMethodType = z.enum(["superfluid", "wallet", "allowance_based_recurring", "stripe", "binance_pay"]); export const addressDetailDto = z.object({line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postalCode: z.string().optional(), country: z.string().optional()}); export const fullAddressDetailDto = z.object({name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), organizationName: z.string().optional(), address: addressDetailDto.optional()}); export const paymentMethodDto = z.object({id: z.string(), createdAt: z.string().optional(), updatedAt: z.string().optional(), assetId: z.string(), asset: assetDto, type: paymentMethodType, accountAddress: z.string().optional(), billingDetails: fullAddressDetailDto.optional(), customerId: z.string().optional(), options: z.object({}).optional()}); export const transactionType = z.enum(["incoming", "outgoing", "event", "transfer"]); export const chainType = z.enum(["evm", "solana", "tron", "stripe", "binance_pay"]); export const chainSlimDto = z.object({id: z.number(), name: z.string(), icon: z.string(), currency: currency, blockExplorerTransactionUrl: z.string(), blockExplorerName: z.string(), type: chainType, isBeta: z.boolean()}); export const checkoutSessionAssetDto = z.object({id: z.string(), name: z.string(), address: z.string(), chainId: z.number(), currency: currency, symbol: z.string(), decimals: z.number(), coingeckoId: z.string().optional(), isPublic: z.boolean(), superToken: superTokenDto.optional(), chain: chainSlimDto}); export const transactionDto = z.object({type: transactionType, transactionRelayId: z.string().optional(), transactionHash: z.string().optional(), nonce: z.number().optional(), gasLimit: z.number().optional(), validUntil: z.string().optional(), fromAddress: z.string(), toAddress: z.string(), currency: currency, createdAt: z.string().optional(), amount: z.number().int().optional(), amountRaw: z.string(), assetId: z.string(), asset: checkoutSessionAssetDto, transactionUrl: z.string().optional()}); export const paymentReceiptDto = z.object({id: z.string(), createdAt: z.string().optional(), updatedAt: z.string().optional(), organizationId: z.string(), paymentIntentId: z.string(), name: z.string().optional(), receiptNumber: z.string(), uri: z.string().optional()}); export const stripeDataDto = z.object({paymentIntentId: z.string().optional(), receiptUrl: z.string().optional(), cardLast4: z.string().optional(), displayName: z.string().optional()}); export const paymentIntentDto = z.object({id: z.string(), createdAt: z.string().optional(), updatedAt: z.string().optional(), organizationId: z.string(), amount: z.number().int().optional(), amountReceived: z.number().int().optional(), currency: currency.optional(), status: paymentIntentStatus, paymentMethodId: z.string(), description: z.string().optional(), paymentMethod: paymentMethodDto.optional(), paymentMethodTypes: z.array(paymentMethodType).optional(), transferAccountAddress: z.string().optional(), transactions: z.array(transactionDto), paymentReceipt: paymentReceiptDto.optional(), canceledAt: z.string().optional(), cancellationReason: z.string().optional(), stripe: stripeDataDto.optional(), isMarkRefunded: z.boolean().nullable().optional(), markRefundedAt: z.string().nullable().optional(), markRefundedComment: 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 }; /** * Mark payment as refunded * * POST /api/v1/payment-intents/{paymentIntentId}/mark-as-refund */ export const createApiApiV1PaymentIntentsPaymentIntentIdMarkAsRefund = async (args: CreateApiApiV1PaymentIntentsPaymentIntentIdMarkAsRefundArgs, options?: CreateApiApiV1PaymentIntentsPaymentIntentIdMarkAsRefundOptions) => { const {baseUrl = "https://api.copperx.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/payment-intents/${encodeURIComponent(String(args.paymentIntentId))}/mark-as-refund${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(paymentIntentDto, await res.json()) };