import {z} from 'zod' export type PartnerId = number; export type BusinessUnitId = number; export type Name = string; export type TaxNumber = string; export type BeneficiaryTaxNumber = string; export type BeneficiaryName = string; export type GuarantorTaxNumber = string; export type GuarantorName = string; export type PayerTaxNumber = string; export type PayerName = string; export type MailToSend = string; export type PhoneToSend = string; export type Barcode = string; export type PrincipalValue = number; export type DiscountValue = number; export type ExtraValue = number; export type PaymentDate = number; export type DueDate = string; export type Tags = Array; export type Description = string; export type Identifier = string; export type RateValue = number; export type RateValueType = number; export type PaymentSubType = number; export type FeePayerFullName = string; export type FeePayerTaxNumber = string; export type FeePayerMail = string; export type FeePayerBank = string; export type FeePayerBankBranch = string; export type FeePayerBankAccount = string; export type FeePayerBankAccountDigit = string; export type FeePayerTradingName = string; export type FeePayerLegalName = string; export type FeePayerIdentityDocument = string; export type Banks = string; export type AccountType = 'CONTA_CORRENTE_INDIVIDUAL' | 'CONTA_CORRENTE_CONJUNTA' | 'CONTA_POUPANCA_CONJUNTA' | 'CONTA_POUPANCA_INDIVIDUAL'; export type Bank = {bank: Banks, type: AccountType, agency: string, account: string, pixKey?: string | undefined}; export type BankBranch = string; export type BankAccount = string; export type BankAccountDigit = string; export type JsonEntries = {Name?: string | undefined, TaxNumber?: string | undefined, Value?: number | undefined, Description?: string | undefined, Bank?: string | undefined, BankBranch?: string | undefined, BankAccount?: string | undefined, BankAccountDigit?: string | undefined}; export type GenerateBoletoOut = {Method: string, PartnerId: PartnerId, BusinessUnitId: BusinessUnitId, Name: Name, TaxNumber: TaxNumber, BeneficiaryTaxNumber?: BeneficiaryTaxNumber | undefined, BeneficiaryName?: BeneficiaryName | undefined, GuarantorTaxNumber?: GuarantorTaxNumber | undefined, GuarantorName?: GuarantorName | undefined, PayerTaxNumber?: PayerTaxNumber | undefined, PayerName?: PayerName | undefined, MailToSend?: MailToSend | undefined, PhoneToSend?: PhoneToSend | undefined, Barcode: Barcode, PrincipalValue?: PrincipalValue | undefined, DiscountValue?: DiscountValue | undefined, ExtraValue?: ExtraValue | undefined, PaymentDate: PaymentDate, DueDate: DueDate, Tags?: Tags | undefined, Description?: Description | undefined, Identifier?: Identifier | undefined, RateValue?: RateValue | undefined, RateValueType?: RateValueType | undefined, PaymentSubType?: PaymentSubType | undefined, FeePayerFullName?: FeePayerFullName | undefined, FeePayerTaxNumber?: FeePayerTaxNumber | undefined, FeePayerMail?: FeePayerMail | undefined, FeePayerBank?: FeePayerBank | undefined, FeePayerBankBranch?: FeePayerBankBranch | undefined, FeePayerBankAccount?: FeePayerBankAccount | undefined, FeePayerBankAccountDigit?: FeePayerBankAccountDigit | undefined, FeePayerTradingName?: FeePayerTradingName | undefined, FeePayerLegalName?: FeePayerLegalName | undefined, FeePayerIdentityDocument?: FeePayerIdentityDocument | undefined, Bank?: Bank | undefined, BankBranch?: BankBranch | undefined, BankAccount?: BankAccount | undefined, BankAccountDigit?: BankAccountDigit | undefined, Entries?: JsonEntries | undefined}; export type FromBank = string; export type FromBankBranch = string; export type FromBankAccount = string; export type FromBankAccountDigit = string; export type DARFType = number; export type GrossRevenueValue = number; export type GrossRevenuePercentage = string; export type CalculationPeriod = string; export type CodeRevenue = string; export type ContributorTaxNumber = string; export type ReferenceNumber = string; export type FineValue = number; export type InterestValue = number; export type GeneratePaymentDARF = {Method: string, PartnerId: PartnerId, BusinessUnitId: BusinessUnitId, TaxNumber: TaxNumber, FromBank?: FromBank | undefined, FromBankBranch?: FromBankBranch | undefined, FromBankAccount?: FromBankAccount | undefined, FromBankAccountDIgit?: FromBankAccountDigit | undefined, DARFType: DARFType, GrossRevenueValue?: GrossRevenueValue | undefined, GrossRevenuePercentage?: GrossRevenuePercentage | undefined, CalculationPeriod: CalculationPeriod, CodeRevenue: CodeRevenue, ContributorTaxNumber: ContributorTaxNumber, ReferenceNumber?: ReferenceNumber | undefined, DueDate?: DueDate | undefined, PrincipalValue: PrincipalValue, FineValue?: FineValue | undefined, InterestValue?: InterestValue | undefined, PaymentDate: PaymentDate, Tags?: Tags | undefined, Description?: Description | undefined, Identifier?: Identifier | undefined, RateValueType?: RateValueType | undefined}; export type FineInterestValue = number; export type OtherValues = number; export type PaymentCode = string; export type JurisdictionDate = string; export type ContributorDocumentType = number; export type GeneratePaymentGPS = {Method: string, PartnerId: PartnerId, BusinessUnitId: BusinessUnitId, TaxNumber: TaxNumber, ContributorTaxNumber: ContributorTaxNumber, PrincipalValue: PrincipalValue, FineInterestValue?: FineInterestValue | undefined, OtherValues?: OtherValues | undefined, RateValue?: RateValue | undefined, PaymentDate: PaymentDate, DueDate?: DueDate | undefined, Tags?: Tags | undefined, RateValueType?: RateValueType | undefined, Description?: Description | undefined, Identifier?: Identifier | undefined, PaymentCode: PaymentCode, ReferenceNumber?: ReferenceNumber | undefined, JurisdictionDate: JurisdictionDate, FromBank?: FromBank | undefined, FromBankBranch?: FromBankBranch | undefined, FromBankAccount?: FromBankAccount | undefined, FromBankAccountDigit?: FromBankAccountDigit | undefined, ContributorDocumentType?: ContributorDocumentType | undefined}; export type TotalValue = number; export type StateRegistration = string; export type ActiveDebit = string; export type QuoteNumberNotification = string; export type GareType = number; export type GeneratePaymentGARE = {Method: string, PartnerId: PartnerId, BusinessUnitId: BusinessUnitId, TaxNumber: TaxNumber, ContributorTaxNumber: ContributorTaxNumber, ReferenceNumber?: ReferenceNumber | undefined, PrincipalValue: PrincipalValue, FineValue?: FineValue | undefined, InterestValue?: InterestValue | undefined, TotalValue?: TotalValue | undefined, RateValue?: RateValue | undefined, DueDate?: DueDate | undefined, PaymentDate: PaymentDate, Tags?: Tags | undefined, CodeRevenue: CodeRevenue, StateRegistration: StateRegistration, ActiveDebit?: ActiveDebit | undefined, QuoteNumberNotification?: QuoteNumberNotification | undefined, RateValueType?: RateValueType | undefined, Description?: Description | undefined, Identifier?: Identifier | undefined, GareType?: GareType | undefined, FromBank?: FromBank | undefined, FromBankBranch?: FromBankBranch | undefined, FromBankAccount?: FromBankAccount | undefined, FromBankAccountDigit?: FromBankAccountDigit | undefined}; export type FgtsIdentifier = string; export type SocialConnectivityCode = number; export type SocialConnectivityDigit = number; export type GeneratePaymentsFGTS = {Method: string, PartnerId: PartnerId, BusinessUnitId: BusinessUnitId, TaxNumber: TaxNumber, ContributorTaxNumber: ContributorTaxNumber, PrincipalValue: PrincipalValue, CodeRevenue: CodeRevenue, Barcode: Barcode, FgtsIdentifier: FgtsIdentifier, SocialConnectivityCode: SocialConnectivityCode, SocialConnectivityDigit: SocialConnectivityDigit, PaymentDate: PaymentDate, Tags?: Tags | undefined, RateValueType?: RateValueType | undefined, Description?: Description | undefined, Identifier?: Identifier | undefined, FromBank?: FromBank | undefined, FromBankBranch?: FromBankBranch | undefined, FromBankAccount?: FromBankAccount | undefined, FromBankAccountDigit?: FromBankAccountDigit | undefined}; export type MonetaryValue = number; export type OriginDocument = number; export type GeneratePaymentDARJ = {Method: string, PartnerId?: PartnerId | undefined, BusinessUnitId?: BusinessUnitId | undefined, TaxNumber: TaxNumber, ContributorTaxNumber: ContributorTaxNumber, ReferenceNumber?: ReferenceNumber | undefined, PrincipalValue: PrincipalValue, FineValue?: FineValue | undefined, InterestValue?: InterestValue | undefined, MonetaryValue?: MonetaryValue | undefined, TotalValue?: TotalValue | undefined, RateValue?: RateValue | undefined, DueDate?: DueDate | undefined, PaymentDate: PaymentDate, Tags?: Tags | undefined, CodeRevenue: CodeRevenue, StateRegistration: StateRegistration, OriginDocument?: OriginDocument | undefined, RateValueType?: RateValueType | undefined, Description?: Description | undefined, Identifier?: Identifier | undefined, FromBank?: FromBank | undefined, FromBankBranch?: FromBankBranch | undefined, FromBankAccount?: FromBankAccount | undefined, FromBankAccountDigit?: FromBankAccountDigit | undefined}; export type GeneratePayments = {Method: string, PartnerId: PartnerId, BusinessUnitId: BusinessUnitId, JsonOperationBoletoOuts?: GenerateBoletoOut | undefined, JsonOperationDARFs?: GeneratePaymentDARF | undefined, JsonOperationGPSs?: GeneratePaymentGPS | undefined, JsonOperationGAREs?: GeneratePaymentGARE | undefined, JsonOperationFGTSs?: GeneratePaymentsFGTS | undefined, JsonOperationDARJs?: GeneratePaymentDARJ | undefined}; export type CreateApiGeneratePaymentsArgs = {body: GeneratePayments}; export type CreateApiGeneratePaymentsOptions = {baseUrl?: string | undefined, BASE64UsernamePassword?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiGeneratePaymentsResponse = z.object({success: z.string().optional(), Payments: 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 }; /** * Generate Payments * * POST /GeneratePayments */ export const createApiGeneratePayments = async (args: CreateApiGeneratePaymentsArgs, options?: CreateApiGeneratePaymentsOptions) => { const {baseUrl = "https://sandboxapi.fitbank.com.br/main/execute", fetch: fetchFn = fetch, BASE64UsernamePassword} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BASE64UsernamePassword !== undefined) headers.set('authorization', `Basic ${btoa(`${BASE64UsernamePassword.username}:${BASE64UsernamePassword.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/GeneratePayments${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(createApiGeneratePaymentsResponse, await res.json()) };