import {z} from 'zod' export type UUID = string; export type Locale = 'ja' | 'en' | 'ko'; export type UpdatePaymentMethodRequest = {locale?: Locale | undefined, 'shared_payment_method_data.open_time'?: string | undefined, 'shared_payment_method_data.close_time'?: string | undefined, 'shared_payment_method_data.privacy_policy_url'?: string | undefined, 'shared_payment_method_data.terms_of_service_url'?: string | undefined, 'shared_payment_method_data.pci_compliance_proofs'?: Array | undefined, 'shared_payment_method_data.shareholder_registers'?: Array | undefined, 'shared_payment_method_data.has_processed_cc_before'?: boolean | undefined, 'shared_payment_method_data.processes_card_info'?: boolean | undefined, 'shared_payment_method_data.conducts_door_to_door_sales'?: boolean | undefined, 'shared_payment_method_data.conducts_telemarketing'?: boolean | undefined, 'shared_payment_method_data.conducts_mlm_scheme'?: boolean | undefined, 'shared_payment_method_data.conducts_business_opportunity_scheme'?: boolean | undefined, 'shared_payment_method_data.provides_specified_continuous_services'?: boolean | undefined, 'shared_payment_method_data.violated_consumer_contract_act'?: boolean | undefined, 'shared_payment_method_data.violated_commercial_transaction_act'?: boolean | undefined, 'linepay.accepted_line_tos'?: boolean | undefined, 'linepay.fields'?: string | undefined, 'paypay.accepted_paypay_tos'?: boolean | undefined, 'paypay.fields'?: string | undefined, 'merpay.accepted_merpay_tos'?: boolean | undefined, 'merpay.fields'?: string | undefined, 'convenience_store.expected_number_of_payments'?: number | undefined, 'convenience_store.fields'?: string | undefined, 'seven_eleven.site_is_public'?: boolean | undefined, 'seven_eleven.no_direct_delivery_from_producer'?: boolean | undefined, 'seven_eleven.no_ticket_sales'?: boolean | undefined, 'seven_eleven.correct_flow_for_order_items'?: boolean | undefined, 'seven_eleven.delivery_within_two_months'?: boolean | undefined, 'seven_eleven.all_items_are_cheaper_than_konbini_limit'?: boolean | undefined, 'seven_eleven.display_sales_permit_number'?: boolean | undefined, 'seven_eleven.order_fee_is_displayed'?: boolean | undefined, 'seven_eleven.no_international_transaction'?: boolean | undefined, 'seven_eleven.provided_info_matches_sctl'?: boolean | undefined, 'seven_eleven.sctl_page_has_phone_number'?: boolean | undefined, 'seven_eleven.product_pages_are_public'?: boolean | undefined, 'seven_eleven.have_sold_as_regular_price'?: boolean | undefined, 'seven_eleven.note'?: string | undefined, 'seven_eleven.fields'?: string | undefined, 'visa_mastercard_credit_card.access_restrictions'?: boolean | undefined, 'visa_mastercard_credit_card.mfa_implementation'?: boolean | undefined, 'visa_mastercard_credit_card.account_lock'?: boolean | undefined, 'visa_mastercard_credit_card.public_directories'?: boolean | undefined, 'visa_mastercard_credit_card.file_extension_restrictions'?: boolean | undefined, 'visa_mastercard_credit_card.vulnerability_assessments'?: boolean | undefined, 'visa_mastercard_credit_card.sql_injection_and_xss'?: boolean | undefined, 'visa_mastercard_credit_card.source_code_review'?: boolean | undefined, 'visa_mastercard_credit_card.anti_virus_software'?: boolean | undefined, 'visa_mastercard_credit_card.fields'?: string | undefined, 'jcb_amex_diners_credit_card.access_restrictions'?: boolean | undefined, 'jcb_amex_diners_credit_card.mfa_implementation'?: boolean | undefined, 'jcb_amex_diners_credit_card.account_lock'?: boolean | undefined, 'jcb_amex_diners_credit_card.public_directories'?: boolean | undefined, 'jcb_amex_diners_credit_card.file_extension_restrictions'?: boolean | undefined, 'jcb_amex_diners_credit_card.vulnerability_assessments'?: boolean | undefined, 'jcb_amex_diners_credit_card.sql_injection_and_xss'?: boolean | undefined, 'jcb_amex_diners_credit_card.source_code_review'?: boolean | undefined, 'jcb_amex_diners_credit_card.anti_virus_software'?: boolean | undefined, 'jcb_amex_diners_credit_card.fields'?: string | undefined}; export type PatchApiLiveApplicationMerchantIdPaymentMethodsPaymentMethodArgs = {merchant_id: UUID, payment_method: string, body: UpdatePaymentMethodRequest}; export type PatchApiLiveApplicationMerchantIdPaymentMethodsPaymentMethodOptions = {baseUrl?: string | undefined, apiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string().min(25).max(25); export const paymentMethodApplicationStatus = z.enum(["submitted", "accepted", "declined"]); export const field = z.object({field_type: z.string(), field: z.string(), field_name: z.string(), field_properties: z.object({external_links: z.array(z.string()).optional(), minLength: z.number().int().optional(), format: z.string().optional(), pattern: z.string().optional(), minimum: z.number().int().optional(), maximum: z.number().int().optional(), enum: z.object({}).optional(), items: z.object({}).optional()}), position: z.number().int(), optional: z.boolean()}); export const erroredField = z.object({field_type: z.string(), field: z.string(), field_name: z.string(), field_properties: z.object({external_links: z.array(z.string()).optional(), minLength: z.number().int().optional(), format: z.string().optional(), pattern: z.string().optional(), minimum: z.number().int().optional(), maximum: z.number().int().optional(), enum: z.object({}).optional(), items: z.object({}).optional()}), position: z.number().int(), optional: z.boolean(), value: z.union([z.string(), z.boolean(), z.number().int()]), error: z.array(z.string())}); export const paymentMethodApplication = z.object({merchant_id: uUID, status: paymentMethodApplicationStatus, payments_enabled: z.boolean(), payouts_enabled: z.boolean(), requested_fields: z.array(field), newly_requested_fields: z.array(field), errored_fields: z.array(erroredField)}); 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 }; /** * Live Application: Update Payment Method * * PATCH /live_application/{merchant_id}/payment_methods/{payment_method} */ export const patchApiLiveApplicationMerchantIdPaymentMethodsPaymentMethod = async (args: PatchApiLiveApplicationMerchantIdPaymentMethodsPaymentMethodArgs, options?: PatchApiLiveApplicationMerchantIdPaymentMethodsPaymentMethodOptions) => { const {baseUrl = "https://komoju.com/api/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKey.username}:${apiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/live_application/${encodeURIComponent(String(args.merchant_id))}/payment_methods/${encodeURIComponent(String(args.payment_method))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(paymentMethodApplication, await res.json()) };