Ecossistema
API Types
Tipos TypeScript espelhando a API v1 — pagamentos, erros e envelopes de webhook. Ideal para backends Node e monorepos tipados.
Uso
npm i @hyzepay/api-types
# ou copie os tipos do bloco abaixo para o seu projetoimport type {
Payment,
PaymentStatus,
CreatePaymentBody,
PaymentResponse,
ApiError,
} from "@hyzepay/api-types";
async function create(body: CreatePaymentBody): Promise<Payment> {
const res = await fetch(`${BASE}/api/v1/payments`, {
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
const data = (await res.json()) as PaymentResponse | { error: ApiError };
if ("error" in data) throw new Error(data.error.message);
return data.payment;
}Principais tipos
Payment— recurso completo (status, pix, customer, metadata)PaymentStatus—pending | paid | expired | failed | refundedCreatePaymentBody— body do POSTWebhookEventV2— envelope Stripe-styleApiError—{ code, message, details }
Tipos inline
Se preferir não depender de package, copie:
export type PaymentStatus =
| "pending"
| "paid"
| "expired"
| "failed"
| "refunded";
export type CreatePaymentBody = {
amount_cents?: number;
amount?: number;
description?: string;
external_id?: string;
expires_in?: number;
customer?: {
name?: string;
email?: string;
document?: string;
phone?: string;
};
metadata?: Record<string, unknown>;
};
export type Payment = {
id: string;
status: PaymentStatus;
amount_cents: number;
amount_label: string;
currency: "BRL";
description: string | null;
external_id: string | null;
customer: CreatePaymentBody["customer"] | null;
pix: {
br_code: string | null;
qr_code_image: string | null;
payment_link_url: string | null;
expires_at: string | null;
};
checkout_url: string | null;
metadata: Record<string, unknown> | null;
correlation_id: string | null;
created_at: string;
updated_at: string | null;
paid_at: string | null;
};
export type PaymentResponse = {
payment: Payment;
created?: boolean;
};
export type ApiError = {
code: string;
message: string;
details?: unknown;
};Os tipos seguem snake_case da API. O backend também aceita camelCase no body de criação.