import {z} from 'zod' export type WithdrawACardDisputeParameters = {explanation?: string | undefined}; export type CreateApiCardDisputesCardDisputeIdWithdrawArgs = {card_dispute_id: string, body: WithdrawACardDisputeParameters}; export type CreateApiCardDisputesCardDisputeIdWithdrawOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const cardDisputeFileAttachment = z.object({file_id: z.string()}); export const cardDisputeVisaNetworkEvent = z.object({attachment_files: z.array(cardDisputeFileAttachment), category: z.enum(["chargeback_accepted", "chargeback_submitted", "chargeback_timed_out", "merchant_prearbitration_decline_submitted", "merchant_prearbitration_received", "merchant_prearbitration_timed_out", "represented", "representment_timed_out", "user_prearbitration_accepted", "user_prearbitration_declined", "user_prearbitration_submitted", "user_prearbitration_timed_out", "user_withdrawal_submitted"]), chargeback_accepted: z.object({}).nullable().optional(), chargeback_submitted: z.object({}).nullable().optional(), chargeback_timed_out: z.object({}).nullable().optional(), created_at: z.string(), dispute_financial_transaction_id: z.string().nullable(), merchant_prearbitration_decline_submitted: z.object({}).nullable().optional(), merchant_prearbitration_received: z.object({cardholder_no_longer_disputes: z.object({explanation: z.string().nullable()}).nullable(), compelling_evidence: z.object({category: z.enum(["authorized_signer", "delivery", "delivery_at_place_of_employment", "digital_goods_download", "dynamic_currency_conversion_actively_chosen", "flight_manifest_and_purchase_itinerary", "household_member_signer", "legitimate_spend_across_payment_types_for_same_merchandise", "merchandise_use", "passenger_transport_ticket_use", "recurring_transaction_with_binding_contract_or_previous_undisputed_transaction", "signed_delivery_or_pickup_form", "signed_mail_order_phone_order_form", "travel_and_expense_loyalty_transaction", "travel_and_expense_subsequent_purchase"]), explanation: z.string().nullable()}).nullable(), credit_or_reversal_processed: z.object({amount: z.number().int(), currency: z.string(), explanation: z.string().nullable(), processed_at: z.string()}).nullable(), delayed_charge_transaction: z.object({explanation: z.string().nullable()}).nullable(), evidence_of_imprint: z.object({explanation: z.string().nullable()}).nullable(), invalid_dispute: z.object({explanation: z.string().nullable(), reason: z.enum(["other", "special_authorization_procedures_followed"])}).nullable(), non_fiat_currency_or_non_fungible_token_received: z.object({blockchain_transaction_hash: z.string(), destination_wallet_address: z.string(), prior_approved_transactions: z.string().nullable()}).nullable(), prior_undisputed_non_fraud_transactions: z.object({explanation: z.string().nullable()}).nullable(), reason: z.enum(["cardholder_no_longer_disputes", "compelling_evidence", "credit_or_reversal_processed", "delayed_charge_transaction", "evidence_of_imprint", "invalid_dispute", "non_fiat_currency_or_non_fungible_token_received", "prior_undisputed_non_fraud_transactions"])}).nullable().optional(), merchant_prearbitration_timed_out: z.object({}).nullable().optional(), represented: z.object({cardholder_no_longer_disputes: z.object({explanation: z.string().nullable()}).nullable(), credit_or_reversal_processed: z.object({amount: z.number().int(), currency: z.string(), explanation: z.string().nullable(), processed_at: z.string()}).nullable(), invalid_dispute: z.object({explanation: z.string().nullable(), reason: z.enum(["automatic_teller_machine_transaction_proof_provided", "balance_of_partial_prepayment_not_paid", "cardholder_canceled_before_expected_merchandise_receipt_date", "cardholder_canceled_before_expected_services_receipt_date", "cardholder_canceled_different_date", "cardholder_did_not_cancel_according_to_policy", "cardholder_received_merchandise", "country_code_correct", "credit_processed_correctly", "currency_correct", "dispute_is_for_quality", "dispute_is_for_visa_cash_back_transaction_portion", "disputed_amount_is_value_added_tax", "disputed_amount_is_value_added_tax_no_credit_receipt_provided", "limited_return_or_cancellation_policy_properly_disclosed", "merchandise_held_at_cardholder_customs_agency", "merchandise_matches_description", "merchandise_not_counterfeit", "merchandise_not_damaged", "merchandise_not_defective", "merchandise_provided_prior_to_cancellation_date", "merchandise_quality_matches_description", "merchandise_return_not_attempted", "merchant_not_notified_of_closed_account", "name_on_flight_manifest_matches_purchase", "no_credit_receipt_provided", "other", "processing_error_incorrect", "returned_mechandise_held_at_customs_agency_outside_merchant_country", "services_match_description", "services_provided_prior_to_cancellation_date", "services_used_after_cancellation_date", "terms_of_service_not_misrepresented", "transaction_code_correct"])}).nullable(), non_fiat_currency_or_non_fungible_token_as_described: z.object({}).nullable(), non_fiat_currency_or_non_fungible_token_received: z.object({blockchain_transaction_hash: z.string(), destination_wallet_address: z.string(), prior_approved_transactions: z.string().nullable()}).nullable(), proof_of_cash_disbursement: z.object({explanation: z.string().nullable()}).nullable(), reason: z.enum(["cardholder_no_longer_disputes", "credit_or_reversal_processed", "invalid_dispute", "non_fiat_currency_or_non_fungible_token_as_described", "non_fiat_currency_or_non_fungible_token_received", "proof_of_cash_disbursement", "reversal_issued"]), reversal_issued: z.object({explanation: z.string().nullable()}).nullable()}).nullable().optional(), representment_timed_out: z.object({}).nullable().optional(), user_prearbitration_accepted: z.object({}).nullable().optional(), user_prearbitration_declined: z.object({}).nullable().optional(), user_prearbitration_submitted: z.object({}).nullable().optional(), user_prearbitration_timed_out: z.object({}).nullable().optional(), user_withdrawal_submitted: z.object({}).nullable().optional()}).and(z.record(z.string(), z.unknown())); export const cardDisputeVisaUserSubmission = z.object({accepted_at: z.string().nullable(), amount: z.number().int().nullable(), attachment_files: z.array(cardDisputeFileAttachment), category: z.enum(["chargeback", "merchant_prearbitration_decline", "user_prearbitration"]), chargeback: z.object({authorization: z.object({account_status: z.enum(["account_closed", "credit_problem", "fraud"])}).nullable(), category: z.enum(["authorization", "consumer_canceled_merchandise", "consumer_canceled_recurring_transaction", "consumer_canceled_services", "consumer_counterfeit_merchandise", "consumer_credit_not_processed", "consumer_damaged_or_defective_merchandise", "consumer_merchandise_misrepresentation", "consumer_merchandise_not_as_described", "consumer_merchandise_not_received", "consumer_non_receipt_of_cash", "consumer_original_credit_transaction_not_accepted", "consumer_quality_merchandise", "consumer_quality_services", "consumer_services_misrepresentation", "consumer_services_not_as_described", "consumer_services_not_received", "fraud", "processing_error"]), consumer_canceled_merchandise: z.object({cardholder_cancellation: z.object({canceled_at: z.string(), canceled_prior_to_ship_date: z.enum(["canceled_prior_to_ship_date", "not_canceled_prior_to_ship_date"]), cancellation_policy_provided: z.enum(["not_provided", "provided"]), reason: z.string()}).nullable(), merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), not_returned: z.object({}).nullable(), purchase_explanation: z.string(), received_or_expected_at: z.string(), return_attempted: z.object({attempt_explanation: z.string(), attempt_reason: z.enum(["merchant_not_responding", "no_return_authorization_provided", "no_return_instructions", "requested_not_to_return", "return_not_accepted"]), attempted_at: z.string(), merchandise_disposition: z.string()}).nullable(), return_outcome: z.enum(["not_returned", "returned", "return_attempted"]), returned: z.object({merchant_received_return_at: z.string().nullable(), other_explanation: z.string().nullable(), return_method: z.enum(["dhl", "face_to_face", "fedex", "other", "postal_service", "ups"]), returned_at: z.string(), tracking_number: z.string().nullable()}).nullable()}).nullable(), consumer_canceled_recurring_transaction: z.object({cancellation_target: z.enum(["account", "transaction"]), merchant_contact_methods: z.object({application_name: z.string().nullable(), call_center_phone_number: z.string().nullable(), email_address: z.string().nullable(), in_person_address: z.string().nullable(), mailing_address: z.string().nullable(), text_phone_number: z.string().nullable()}), other_form_of_payment_explanation: z.string().nullable(), transaction_or_account_canceled_at: z.string()}).nullable(), consumer_canceled_services: z.object({cardholder_cancellation: z.object({canceled_at: z.string(), cancellation_policy_provided: z.enum(["not_provided", "provided"]), reason: z.string()}), contracted_at: z.string(), guaranteed_reservation: z.object({explanation: z.enum(["cardholder_canceled_prior_to_service", "cardholder_cancellation_attempt_within_24_hours_of_confirmation", "merchant_billed_no_show"])}).nullable(), merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), other: z.object({}).nullable(), purchase_explanation: z.string(), service_type: z.enum(["guaranteed_reservation", "other", "timeshare"]), timeshare: z.object({}).nullable()}).nullable(), consumer_counterfeit_merchandise: z.object({counterfeit_explanation: z.string(), disposition_explanation: z.string(), order_explanation: z.string(), received_at: z.string()}).nullable(), consumer_credit_not_processed: z.object({canceled_or_returned_at: z.string().nullable(), credit_expected_at: z.string().nullable()}).nullable(), consumer_damaged_or_defective_merchandise: z.object({merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), not_returned: z.object({}).nullable(), order_and_issue_explanation: z.string(), received_at: z.string(), return_attempted: z.object({attempt_explanation: z.string(), attempt_reason: z.enum(["merchant_not_responding", "no_return_authorization_provided", "no_return_instructions", "requested_not_to_return", "return_not_accepted"]), attempted_at: z.string(), merchandise_disposition: z.string()}).nullable(), return_outcome: z.enum(["not_returned", "returned", "return_attempted"]), returned: z.object({merchant_received_return_at: z.string().nullable(), other_explanation: z.string().nullable(), return_method: z.enum(["dhl", "face_to_face", "fedex", "other", "postal_service", "ups"]), returned_at: z.string(), tracking_number: z.string().nullable()}).nullable()}).nullable(), consumer_merchandise_misrepresentation: z.object({merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), misrepresentation_explanation: z.string(), not_returned: z.object({}).nullable(), purchase_explanation: z.string(), received_at: z.string(), return_attempted: z.object({attempt_explanation: z.string(), attempt_reason: z.enum(["merchant_not_responding", "no_return_authorization_provided", "no_return_instructions", "requested_not_to_return", "return_not_accepted"]), attempted_at: z.string(), merchandise_disposition: z.string()}).nullable(), return_outcome: z.enum(["not_returned", "returned", "return_attempted"]), returned: z.object({merchant_received_return_at: z.string().nullable(), other_explanation: z.string().nullable(), return_method: z.enum(["dhl", "face_to_face", "fedex", "other", "postal_service", "ups"]), returned_at: z.string(), tracking_number: z.string().nullable()}).nullable()}).nullable(), consumer_merchandise_not_as_described: z.object({merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), received_at: z.string(), return_attempted: z.object({attempt_explanation: z.string(), attempt_reason: z.enum(["merchant_not_responding", "no_return_authorization_provided", "no_return_instructions", "requested_not_to_return", "return_not_accepted"]), attempted_at: z.string(), merchandise_disposition: z.string()}).nullable(), return_outcome: z.enum(["returned", "return_attempted"]), returned: z.object({merchant_received_return_at: z.string().nullable(), other_explanation: z.string().nullable(), return_method: z.enum(["dhl", "face_to_face", "fedex", "other", "postal_service", "ups"]), returned_at: z.string(), tracking_number: z.string().nullable()}).nullable()}).nullable(), consumer_merchandise_not_received: z.object({cancellation_outcome: z.enum(["cardholder_cancellation_prior_to_expected_receipt", "merchant_cancellation", "no_cancellation"]), cardholder_cancellation_prior_to_expected_receipt: z.object({canceled_at: z.string(), reason: z.string().nullable()}).nullable(), delayed: z.object({explanation: z.string(), not_returned: z.object({}).nullable(), return_attempted: z.object({attempted_at: z.string()}).nullable(), return_outcome: z.enum(["not_returned", "returned", "return_attempted"]), returned: z.object({merchant_received_return_at: z.string(), returned_at: z.string()}).nullable()}).nullable(), delivered_to_wrong_location: z.object({agreed_location: z.string()}).nullable(), delivery_issue: z.enum(["delayed", "delivered_to_wrong_location"]), last_expected_receipt_at: z.string(), merchant_cancellation: z.object({canceled_at: z.string()}).nullable(), merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), no_cancellation: z.object({}).nullable(), purchase_info_and_explanation: z.string()}).nullable(), consumer_non_receipt_of_cash: z.object({}).nullable(), consumer_original_credit_transaction_not_accepted: z.object({explanation: z.string(), reason: z.enum(["prohibited_by_local_laws_or_regulation", "recipient_refused"])}).nullable(), consumer_quality_merchandise: z.object({expected_at: z.string(), merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), not_returned: z.object({}).nullable(), ongoing_negotiations: z.object({explanation: z.string(), issuer_first_notified_at: z.string(), started_at: z.string()}).nullable(), purchase_info_and_quality_issue: z.string(), received_at: z.string(), return_attempted: z.object({attempt_explanation: z.string(), attempt_reason: z.enum(["merchant_not_responding", "no_return_authorization_provided", "no_return_instructions", "requested_not_to_return", "return_not_accepted"]), attempted_at: z.string(), merchandise_disposition: z.string()}).nullable(), return_outcome: z.enum(["not_returned", "returned", "return_attempted"]), returned: z.object({merchant_received_return_at: z.string().nullable(), other_explanation: z.string().nullable(), return_method: z.enum(["dhl", "face_to_face", "fedex", "other", "postal_service", "ups"]), returned_at: z.string(), tracking_number: z.string().nullable()}).nullable()}).nullable(), consumer_quality_services: z.object({cardholder_cancellation: z.object({accepted_by_merchant: z.enum(["accepted", "not_accepted"]), canceled_at: z.string(), reason: z.string()}), cardholder_paid_to_have_work_redone: z.enum(["did_not_pay_to_have_work_redone", "paid_to_have_work_redone"]).nullable(), non_fiat_currency_or_non_fungible_token_related_and_not_matching_description: z.enum(["not_related", "related"]), ongoing_negotiations: z.object({explanation: z.string(), issuer_first_notified_at: z.string(), started_at: z.string()}).nullable(), purchase_info_and_quality_issue: z.string(), restaurant_food_related: z.enum(["not_related", "related"]).nullable(), services_received_at: z.string()}).nullable(), consumer_services_misrepresentation: z.object({cardholder_cancellation: z.object({accepted_by_merchant: z.enum(["accepted", "not_accepted"]), canceled_at: z.string(), reason: z.string()}), merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), misrepresentation_explanation: z.string(), purchase_explanation: z.string(), received_at: z.string()}).nullable(), consumer_services_not_as_described: z.object({cardholder_cancellation: z.object({accepted_by_merchant: z.enum(["accepted", "not_accepted"]), canceled_at: z.string(), reason: z.string()}), explanation: z.string(), merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), received_at: z.string()}).nullable(), consumer_services_not_received: z.object({cancellation_outcome: z.enum(["cardholder_cancellation_prior_to_expected_receipt", "merchant_cancellation", "no_cancellation"]), cardholder_cancellation_prior_to_expected_receipt: z.object({canceled_at: z.string(), reason: z.string().nullable()}).nullable(), last_expected_receipt_at: z.string(), merchant_cancellation: z.object({canceled_at: z.string()}).nullable(), merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), no_cancellation: z.object({}).nullable(), purchase_info_and_explanation: z.string()}).nullable(), fraud: z.object({fraud_type: z.enum(["account_or_credentials_takeover", "card_not_received_as_issued", "fraudulent_application", "fraudulent_use_of_account_number", "incorrect_processing", "issuer_reported_counterfeit", "lost", "manipulation_of_account_holder", "merchant_misrepresentation", "miscellaneous", "stolen"])}).nullable(), processing_error: z.object({duplicate_transaction: z.object({other_transaction_id: z.string()}).nullable(), error_reason: z.enum(["duplicate_transaction", "incorrect_amount", "paid_by_other_means"]), incorrect_amount: z.object({expected_amount: z.number().int()}).nullable(), merchant_resolution_attempted: z.enum(["attempted", "prohibited_by_local_law"]), paid_by_other_means: z.object({other_form_of_payment_evidence: z.enum(["canceled_check", "card_transaction", "cash_receipt", "other", "statement", "voucher"]), other_transaction_id: z.string().nullable()}).nullable()}).nullable()}).nullable().optional(), created_at: z.string(), explanation: z.string().nullable(), further_information_requested_at: z.string().nullable(), further_information_requested_reason: z.string().nullable(), merchant_prearbitration_decline: z.object({reason: z.string()}).nullable().optional(), status: z.enum(["abandoned", "accepted", "further_information_requested", "pending_reviewing"]), updated_at: z.string(), user_prearbitration: z.object({category_change: z.object({category: z.enum(["authorization", "consumer_canceled_merchandise", "consumer_canceled_recurring_transaction", "consumer_canceled_services", "consumer_counterfeit_merchandise", "consumer_credit_not_processed", "consumer_damaged_or_defective_merchandise", "consumer_merchandise_misrepresentation", "consumer_merchandise_not_as_described", "consumer_merchandise_not_received", "consumer_non_receipt_of_cash", "consumer_original_credit_transaction_not_accepted", "consumer_quality_merchandise", "consumer_quality_services", "consumer_services_misrepresentation", "consumer_services_not_as_described", "consumer_services_not_received", "fraud", "processing_error"]), reason: z.string()}).nullable(), reason: z.string()}).nullable().optional()}); export const cardDisputeVisa = z.object({network_events: z.array(cardDisputeVisaNetworkEvent), required_user_submission_category: z.enum(["chargeback", "merchant_prearbitration_decline", "user_prearbitration"]).nullable(), user_submissions: z.array(cardDisputeVisaUserSubmission)}); export const cardDispute = z.object({account_id: z.string(), amount: z.number().int(), card_id: z.string(), created_at: z.string(), disputed_transaction_id: z.string(), id: z.string(), idempotency_key: z.string().nullable(), loss: z.object({lost_at: z.string(), reason: z.enum(["user_withdrawn", "loss"])}).nullable(), network: z.enum(["visa", "pulse"]), rejection: z.object({explanation: z.string(), rejected_at: z.string()}).nullable(), status: z.enum(["user_submission_required", "pending_user_submission_reviewing", "pending_user_submission_submitting", "pending_user_withdrawal_submitting", "pending_response", "lost", "won", "rejected"]), type: z.literal("card_dispute"), user_submission_required_by: z.string().nullable(), visa: cardDisputeVisa.nullable(), win: z.object({won_at: z.string()}).nullable(), withdrawal: z.object({explanation: z.string().nullable()}).nullable()}); 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 }; /** * Withdraw a Card Dispute * * POST /card_disputes/{card_dispute_id}/withdraw */ export const createApiCardDisputesCardDisputeIdWithdraw = async (args: CreateApiCardDisputesCardDisputeIdWithdrawArgs, options?: CreateApiCardDisputesCardDisputeIdWithdrawOptions) => { const {baseUrl = "https://api.increase.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/card_disputes/${encodeURIComponent(String(args.card_dispute_id))}/withdraw${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(cardDispute, await res.json()) };