evo360-types 1.3.639 → 1.3.644

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zProviderInvoiceLinksSchema = exports.zServiceTaxInfoSchema = exports.zServiceLineItemSchema = exports.zServiceInvoiceStateSchema = exports.zProviderServiceInvoiceStatusSchema = exports.zExternalLinkSchema = exports.zExternalObjectTypeSchema = exports.zInvoiceSourceRefSchema = exports.zInvoiceSourceTypeSchema = exports.zInvoiceTakerRefSchema = exports.zInvoiceTakerSnapshotSchema = exports.zInvoiceTakerSnapshotAddressSchema = exports.zTakerDocumentSchema = exports.zTakerTaxProfileSchema = exports.zTakerProviderRefsSchema = exports.zTakerAddressSchema = exports.zInvoiceTakerTypeSchema = exports.zServiceSchema = exports.zCustomerServiceTaxInfoSchema = exports.zIssuerTaxProfileSchema = exports.zIssuerNfseConfigSchema = exports.zIssuerMunicipalCredentialsRefSchema = exports.zIssuerTaxRegimeSchema = exports.zIssuerCompanyIdentitySchema = exports.zIssuerCompanyAddressSchema = exports.zTaxProfileSyncStateSchema = exports.zAsaasProviderSchema = exports.zAsaasProviderAsaasBlockSchema = exports.zAsaasProviderCapabilitiesSchema = exports.zAsaasPaymentsCapabilitiesSchema = exports.zAsaasNfseCapabilitiesSchema = exports.zAsaasEnvAuthConfigSchema = exports.zAsaasSubaccountInputSchema = exports.zAsaasAccountScopeSchema = exports.zAsaasWebhookConfigSchema = exports.zRetryPolicySchema = exports.zAsaasWebhookEventSchema = exports.zAsaasAccountScopeModeSchema = exports.zProviderRemoteRefsSchema = exports.zProviderFiscalInfoPayloadSchema = exports.zProviderCredentialsInputSchema = exports.zProviderCredentialsSecretRefsSchema = exports.zProviderMunicipalOptionsSnapshotSchema = exports.zProviderOptionItemSchema = exports.zProviderMunicipalAuthTypeSchema = exports.zFinopsProviderBaseSchema = exports.zProviderStatusSchema = exports.zFinopsActionSchema = exports.zFinopsProviderTypeSchema = exports.zProviderEnvSchema = void 0;
4
- exports.zNexFinopsContractAllowancesWriteSchema = exports.zNexFinopsUsageAlertDefaultsSchema = exports.zNexFinopsAlertThresholdSchema = exports.zNexFinopsContractAllowancesSchema = exports.zNexFinopsContractAllowanceSchema = exports.zNexVendasJourneyPaymentSchema = exports.zNexVendasJourneyPaymentSupersededSchema = exports.zNexVendasJourneyPaymentWebhookEventSchema = exports.zNexVendasJourneyBoletoSchema = exports.zNexVendasJourneyPaymentChooseSchema = exports.zNexVendasJourneyPaymentStateSchema = exports.zNexVendasJourneyPaymentKindSchema = exports.zNexVendasJourneyPaymentMethodSchema = exports.zNexFinopsContractAsaasInfoSchema = exports.zNexFinopsAsaasSubscriptionStatusSchema = exports.zNexFinopsPaymentMethodSchema = exports.zNexFinopsProposalSchema = exports.zNexFinopsProposalWriteSchema = exports.zNexFinopsProposalPrefillSchema = exports.zNexFinopsProposalLoyaltyPeriodSchema = exports.zNexFinopsProposalPaymentMethodSchema = exports.zNexFinopsProposalStatusSchema = exports.zServiceInvoiceSchema = exports.zPaymentLinkSchema = exports.zPaymentLinkDocumentStateSchema = exports.zAsaasPaymentLinkSubscriptionCycleSchema = exports.zAsaasPaymentLinkChargeTypeSchema = exports.zAsaasPaymentLinkBillingTypeSchema = exports.zProviderPayloadSnapshotSchema = exports.zProviderTraceSchema = exports.zProviderInvoiceErrorSchema = exports.zProviderInvoiceIdentifiersSchema = void 0;
3
+ exports.zServiceTaxInfoSchema = exports.zServiceLineItemSchema = exports.zServiceInvoiceStateSchema = exports.zProviderServiceInvoiceStatusSchema = exports.zExternalLinkSchema = exports.zExternalObjectTypeSchema = exports.zInvoiceSourceRefSchema = exports.zInvoiceSourceTypeSchema = exports.zInvoiceTakerRefSchema = exports.zInvoiceTakerSnapshotSchema = exports.zInvoiceTakerSnapshotAddressSchema = exports.zTakerDocumentSchema = exports.zTakerTaxProfileSchema = exports.zTakerProviderRefsSchema = exports.zTakerAddressSchema = exports.zInvoiceTakerTypeSchema = exports.zServiceSchema = exports.zCustomerServiceTaxInfoSchema = exports.zIssuerTaxProfileSchema = exports.zIssuerNfseConfigSchema = exports.zIssuerMunicipalCredentialsRefSchema = exports.zIssuerTaxRegimeSchema = exports.zIssuerCompanyIdentitySchema = exports.zIssuerCompanyAddressSchema = exports.zTaxProfileSyncStateSchema = exports.zAsaasProviderSchema = exports.zAsaasProviderAsaasBlockSchema = exports.zAsaasProviderCapabilitiesSchema = exports.zAsaasPaymentsCapabilitiesSchema = exports.zAsaasEnvFlagSchema = exports.zAsaasNfseCapabilitiesSchema = exports.zAsaasEnvAuthConfigSchema = exports.zAsaasSubaccountInputSchema = exports.zAsaasAccountScopeSchema = exports.zAsaasWebhookConfigSchema = exports.zRetryPolicySchema = exports.zAsaasWebhookEventSchema = exports.zAsaasAccountScopeModeSchema = exports.zProviderRemoteRefsSchema = exports.zProviderFiscalInfoPayloadSchema = exports.zProviderCredentialsInputSchema = exports.zProviderCredentialsSecretRefsSchema = exports.zProviderMunicipalOptionsSnapshotSchema = exports.zProviderOptionItemSchema = exports.zProviderMunicipalAuthTypeSchema = exports.zFinopsProviderBaseSchema = exports.zProviderStatusSchema = exports.zFinopsActionSchema = exports.zFinopsProviderTypeSchema = exports.zProviderEnvSchema = void 0;
4
+ exports.zNexFinopsPaymentMethodsDiscoverSchema = exports.zNexFinopsBillingCardChargeSchema = exports.zNexFinopsContractPaymentMethodsWriteSchema = exports.zNexFinopsPaymentMethodPatchSchema = exports.zNexFinopsPaymentMethodStatusSchema = exports.zNexFinopsPaymentMethodKindSchema = exports.zNexFinopsContractAllowancesWriteSchema = exports.zNexFinopsUsageAlertDefaultsSchema = exports.zNexFinopsAlertThresholdSchema = exports.zNexFinopsContractAllowancesSchema = exports.zNexFinopsContractAllowanceSchema = exports.zNexVendasJourneyPaymentSchema = exports.zNexVendasJourneyPaymentSupersededSchema = exports.zNexVendasJourneyPaymentWebhookEventSchema = exports.zNexVendasJourneyBoletoSchema = exports.zNexVendasJourneyPaymentChooseSchema = exports.zNexVendasJourneyPaymentStateSchema = exports.zNexVendasJourneyPaymentKindSchema = exports.zNexVendasJourneyPaymentMethodSchema = exports.zNexFinopsContractAsaasInfoSchema = exports.zNexFinopsAsaasSubscriptionStatusSchema = exports.zNexFinopsPaymentMethodSchema = exports.zNexFinopsProposalSchema = exports.zNexFinopsProposalWriteSchema = exports.zNexFinopsProposalPrefillSchema = exports.zNexFinopsProposalLoyaltyPeriodSchema = exports.zNexFinopsProposalPaymentMethodSchema = exports.zNexFinopsProposalStatusSchema = exports.zServiceInvoiceSchema = exports.zPaymentLinkSchema = exports.zPaymentLinkDocumentStateSchema = exports.zAsaasPaymentLinkSubscriptionCycleSchema = exports.zAsaasPaymentLinkChargeTypeSchema = exports.zAsaasPaymentLinkBillingTypeSchema = exports.zProviderPayloadSnapshotSchema = exports.zProviderTraceSchema = exports.zProviderInvoiceErrorSchema = exports.zProviderInvoiceIdentifiersSchema = exports.zProviderInvoiceLinksSchema = void 0;
5
5
  const zod_1 = require("zod");
6
6
  const zod_schemas_1 = require("../shared/zod-schemas");
7
7
  // ---- Provider enums and base ----
@@ -233,8 +233,18 @@ exports.zAsaasNfseCapabilitiesSchema = zod_1.z.object({
233
233
  allow_avulsa: zod_1.z.boolean(),
234
234
  allow_linked_to_payment: zod_1.z.boolean(),
235
235
  });
236
+ exports.zAsaasEnvFlagSchema = zod_1.z
237
+ .object({
238
+ sandbox: zod_1.z.boolean().optional(),
239
+ production: zod_1.z.boolean().optional(),
240
+ })
241
+ .strip();
236
242
  exports.zAsaasPaymentsCapabilitiesSchema = zod_1.z.object({
237
243
  enabled: zod_1.z.boolean(),
244
+ /** feat-253 — kill-switch do caminho A. */
245
+ card_subscription_adjust: exports.zAsaasEnvFlagSchema.optional(),
246
+ /** feat-253 — flag do caminho B (token). */
247
+ card_token: exports.zAsaasEnvFlagSchema.optional(),
238
248
  });
239
249
  exports.zAsaasProviderCapabilitiesSchema = zod_1.z.object({
240
250
  nfse: exports.zAsaasNfseCapabilitiesSchema,
@@ -913,3 +923,52 @@ exports.zNexFinopsContractAllowancesWriteSchema = zod_1.z
913
923
  alert_thresholds: zod_1.z.array(exports.zNexFinopsAlertThresholdSchema).optional().nullable(),
914
924
  })
915
925
  .strip();
926
+ // ---- Nexus FinOps — métodos de pagamento do cliente (feat-253) ----
927
+ //
928
+ // PCI: todos `.strip()`. Nenhum schema aceita número de cartão, CCV, dados do
929
+ // portador ou token — chave desconhecida é descartada antes de chegar ao use case.
930
+ exports.zNexFinopsPaymentMethodKindSchema = zod_1.z.enum([
931
+ "asaas_subscription",
932
+ "asaas_card_token",
933
+ ]);
934
+ exports.zNexFinopsPaymentMethodStatusSchema = zod_1.z.enum([
935
+ "active",
936
+ "failing",
937
+ "inactive",
938
+ "revoked",
939
+ ]);
940
+ /** `PATCH /payment-methods/:id` — o operador só renomeia ou liga/desliga. */
941
+ exports.zNexFinopsPaymentMethodPatchSchema = zod_1.z
942
+ .object({
943
+ label: zod_1.z.string().max(120).optional().nullable(),
944
+ status: zod_1.z.enum(["active", "inactive"]).optional(),
945
+ })
946
+ .strip();
947
+ /** `PUT /contracts/:id/payment-methods` — rota dedicada (o PUT genérico ignora estes campos). */
948
+ exports.zNexFinopsContractPaymentMethodsWriteSchema = zod_1.z
949
+ .object({
950
+ payment_method_ids: zod_1.z.array(zod_1.z.string().min(1).max(128)).max(10),
951
+ default_payment_method_id: zod_1.z.string().min(1).max(128).optional().nullable(),
952
+ })
953
+ .strip();
954
+ /** `POST /billings/:id/card-charge` (F2/F3). */
955
+ exports.zNexFinopsBillingCardChargeSchema = zod_1.z
956
+ .object({
957
+ action: zod_1.z.enum(["preview", "adjust", "revert", "charge_now"]),
958
+ expected_value: zod_1.z.number(),
959
+ asaas_payment_id: zod_1.z.string().min(1).max(128).optional(),
960
+ confirm: zod_1.z.boolean().optional(),
961
+ })
962
+ .strip();
963
+ /** `POST /payment-methods/discover` — sem `confirm` é dry-run. */
964
+ exports.zNexFinopsPaymentMethodsDiscoverSchema = zod_1.z
965
+ .object({
966
+ customer_id: zod_1.z.string().min(1).max(128).optional(),
967
+ confirm: zod_1.z
968
+ .object({
969
+ payment_method_ids: zod_1.z.array(zod_1.z.string().min(1).max(128)).max(500),
970
+ })
971
+ .strip()
972
+ .optional(),
973
+ })
974
+ .strip();
@@ -247,8 +247,19 @@ export const zAsaasNfseCapabilitiesSchema = z.object({
247
247
  allow_linked_to_payment: z.boolean(),
248
248
  });
249
249
 
250
+ export const zAsaasEnvFlagSchema = z
251
+ .object({
252
+ sandbox: z.boolean().optional(),
253
+ production: z.boolean().optional(),
254
+ })
255
+ .strip();
256
+
250
257
  export const zAsaasPaymentsCapabilitiesSchema = z.object({
251
258
  enabled: z.boolean(),
259
+ /** feat-253 — kill-switch do caminho A. */
260
+ card_subscription_adjust: zAsaasEnvFlagSchema.optional(),
261
+ /** feat-253 — flag do caminho B (token). */
262
+ card_token: zAsaasEnvFlagSchema.optional(),
252
263
  });
253
264
 
254
265
  export const zAsaasProviderCapabilitiesSchema = z.object({
@@ -1001,3 +1012,59 @@ export const zNexFinopsContractAllowancesWriteSchema = z
1001
1012
  alert_thresholds: z.array(zNexFinopsAlertThresholdSchema).optional().nullable(),
1002
1013
  })
1003
1014
  .strip();
1015
+
1016
+ // ---- Nexus FinOps — métodos de pagamento do cliente (feat-253) ----
1017
+ //
1018
+ // PCI: todos `.strip()`. Nenhum schema aceita número de cartão, CCV, dados do
1019
+ // portador ou token — chave desconhecida é descartada antes de chegar ao use case.
1020
+
1021
+ export const zNexFinopsPaymentMethodKindSchema = z.enum([
1022
+ "asaas_subscription",
1023
+ "asaas_card_token",
1024
+ ]);
1025
+
1026
+ export const zNexFinopsPaymentMethodStatusSchema = z.enum([
1027
+ "active",
1028
+ "failing",
1029
+ "inactive",
1030
+ "revoked",
1031
+ ]);
1032
+
1033
+ /** `PATCH /payment-methods/:id` — o operador só renomeia ou liga/desliga. */
1034
+ export const zNexFinopsPaymentMethodPatchSchema = z
1035
+ .object({
1036
+ label: z.string().max(120).optional().nullable(),
1037
+ status: z.enum(["active", "inactive"]).optional(),
1038
+ })
1039
+ .strip();
1040
+
1041
+ /** `PUT /contracts/:id/payment-methods` — rota dedicada (o PUT genérico ignora estes campos). */
1042
+ export const zNexFinopsContractPaymentMethodsWriteSchema = z
1043
+ .object({
1044
+ payment_method_ids: z.array(z.string().min(1).max(128)).max(10),
1045
+ default_payment_method_id: z.string().min(1).max(128).optional().nullable(),
1046
+ })
1047
+ .strip();
1048
+
1049
+ /** `POST /billings/:id/card-charge` (F2/F3). */
1050
+ export const zNexFinopsBillingCardChargeSchema = z
1051
+ .object({
1052
+ action: z.enum(["preview", "adjust", "revert", "charge_now"]),
1053
+ expected_value: z.number(),
1054
+ asaas_payment_id: z.string().min(1).max(128).optional(),
1055
+ confirm: z.boolean().optional(),
1056
+ })
1057
+ .strip();
1058
+
1059
+ /** `POST /payment-methods/discover` — sem `confirm` é dry-run. */
1060
+ export const zNexFinopsPaymentMethodsDiscoverSchema = z
1061
+ .object({
1062
+ customer_id: z.string().min(1).max(128).optional(),
1063
+ confirm: z
1064
+ .object({
1065
+ payment_method_ids: z.array(z.string().min(1).max(128)).max(500),
1066
+ })
1067
+ .strip()
1068
+ .optional(),
1069
+ })
1070
+ .strip();
@@ -1,4 +1,5 @@
1
1
  import type { IFireGlobalDoc } from '../../shared';
2
+ import type { NexFinopsPaymentMethodKind } from './payment-method';
2
3
  export type NexFinopsBillingStatus = 'draft' | 'issued' | 'paid' | 'overdue' | 'canceled';
3
4
  export type NexFinopsBillingAttachmentCategory = 'boleto' | 'invoice' | 'other';
4
5
  export interface INexFinopsBillingServiceItem {
@@ -28,7 +29,7 @@ export interface INexFinopsBillingBoletoTerms {
28
29
  mora_taxa: number;
29
30
  }
30
31
  export interface INexFinopsBillingPaymentOption {
31
- type: 'pix' | 'boleto' | 'payment_link';
32
+ type: 'pix' | 'boleto' | 'payment_link' | 'credit_card';
32
33
  provider_id?: string | null;
33
34
  external_id?: string | null;
34
35
  url?: string | null;
@@ -63,12 +64,61 @@ export interface INexFinopsBillingAttachment {
63
64
  category?: NexFinopsBillingAttachmentCategory;
64
65
  }
65
66
  export interface INexFinopsBillingPaidVia {
66
- kind: 'payment_link' | 'manual' | 'pix' | 'boleto';
67
+ kind: 'payment_link' | 'manual' | 'pix' | 'boleto' | 'credit_card';
67
68
  payment_link_id?: string | null;
68
69
  asaas_payment_id?: string | null;
69
70
  event?: string | null;
70
71
  received_at?: string | null;
71
72
  raw_status?: string | null;
73
+ /** feat-253: método de pagamento (cartão) que liquidou a cobrança. */
74
+ payment_method_id?: string | null;
75
+ /** feat-253: degrau do roteamento do webhook de cartão que casou o pagamento. Interno (não vai ao portal). */
76
+ matched_by?: 'card_payment_id' | 'external_reference' | 'subscription_competency' | null;
77
+ }
78
+ /** Resumo do método herdado — só bandeira e últimos 4 (PCI). */
79
+ export interface INexFinopsBillingPaymentMethodSnapshot {
80
+ kind: NexFinopsPaymentMethodKind;
81
+ brand: string | null;
82
+ last4: string | null;
83
+ subscription_id?: string | null;
84
+ }
85
+ export type NexFinopsBillingCardChargeMode = 'subscription_adjust'
86
+ /** Contingência A′. */
87
+ | 'subscription_value_update' | 'token_charge';
88
+ export type NexFinopsBillingCardChargeStatus = 'scheduled' | 'stale' | 'confirmed' | 'refused' | 'refunded' | 'chargeback' | 'canceled' | 'reverted';
89
+ export interface INexFinopsBillingCardChargeHistoryEntry {
90
+ at: string;
91
+ by: string | null;
92
+ action: 'adjust' | 'readjust' | 'revert' | 'charge' | 'event';
93
+ value?: number | null;
94
+ event?: string | null;
95
+ }
96
+ export interface INexFinopsBillingCardCharge {
97
+ mode: NexFinopsBillingCardChargeMode;
98
+ payment_method_id: string;
99
+ asaas_payment_id: string;
100
+ subscription_id?: string | null;
101
+ /** `dueDate` do `pay_` no Asaas (YYYY-MM-DD). */
102
+ due_date: string;
103
+ /** Caminho A: valor antes do ajuste. */
104
+ value_before?: number | null;
105
+ /** = `billing.total` no momento do ajuste. */
106
+ value_after: number;
107
+ status: NexFinopsBillingCardChargeStatus;
108
+ raw_status?: string | null;
109
+ adjusted_at: string;
110
+ adjusted_by: {
111
+ kind: 'user' | 'system';
112
+ id: string | null;
113
+ };
114
+ last_event?: string | null;
115
+ last_event_at?: string | null;
116
+ failure?: {
117
+ event: string;
118
+ description?: string | null;
119
+ } | null;
120
+ /** Capado em 30 entradas. */
121
+ history: INexFinopsBillingCardChargeHistoryEntry[];
72
122
  }
73
123
  export interface INexFinopsBilling extends IFireGlobalDoc {
74
124
  customer_id: string;
@@ -95,6 +145,12 @@ export interface INexFinopsBilling extends IFireGlobalDoc {
95
145
  contract_snapshot?: Record<string, unknown> | null;
96
146
  customer_snapshot?: Record<string, unknown> | null;
97
147
  notes?: string | null;
148
+ /** Método herdado do `default_payment_method_id` do contrato na geração (ou escolhido depois). */
149
+ payment_method_id?: string | null;
150
+ payment_method_snapshot?: INexFinopsBillingPaymentMethodSnapshot | null;
151
+ /** Todos os `pay_` do Asaas já associados (A e B) — chave do roteamento do webhook. Interno. */
152
+ card_payment_ids?: string[];
153
+ card_charge?: INexFinopsBillingCardCharge | null;
98
154
  }
99
155
  /**
100
156
  * Transições permitidas de status de cobrança.
@@ -1,4 +1,5 @@
1
1
  import type { IFireGlobalDoc } from '../../shared';
2
+ import type { NexFinopsPaymentMethodKind } from './payment-method';
2
3
 
3
4
  // ── Status ──
4
5
 
@@ -42,7 +43,7 @@ export interface INexFinopsBillingBoletoTerms {
42
43
  }
43
44
 
44
45
  export interface INexFinopsBillingPaymentOption {
45
- type: 'pix' | 'boleto' | 'payment_link';
46
+ type: 'pix' | 'boleto' | 'payment_link' | 'credit_card';
46
47
  provider_id?: string | null;
47
48
  external_id?: string | null;
48
49
  url?: string | null;
@@ -80,12 +81,72 @@ export interface INexFinopsBillingAttachment {
80
81
  }
81
82
 
82
83
  export interface INexFinopsBillingPaidVia {
83
- kind: 'payment_link' | 'manual' | 'pix' | 'boleto';
84
+ kind: 'payment_link' | 'manual' | 'pix' | 'boleto' | 'credit_card';
84
85
  payment_link_id?: string | null;
85
86
  asaas_payment_id?: string | null;
86
87
  event?: string | null;
87
88
  received_at?: string | null;
88
89
  raw_status?: string | null;
90
+ /** feat-253: método de pagamento (cartão) que liquidou a cobrança. */
91
+ payment_method_id?: string | null;
92
+ /** feat-253: degrau do roteamento do webhook de cartão que casou o pagamento. Interno (não vai ao portal). */
93
+ matched_by?: 'card_payment_id' | 'external_reference' | 'subscription_competency' | null;
94
+ }
95
+
96
+ // ── Cobrança no cartão (feat-253) ──
97
+
98
+ /** Resumo do método herdado — só bandeira e últimos 4 (PCI). */
99
+ export interface INexFinopsBillingPaymentMethodSnapshot {
100
+ kind: NexFinopsPaymentMethodKind;
101
+ brand: string | null;
102
+ last4: string | null;
103
+ subscription_id?: string | null;
104
+ }
105
+
106
+ export type NexFinopsBillingCardChargeMode =
107
+ | 'subscription_adjust'
108
+ /** Contingência A′. */
109
+ | 'subscription_value_update'
110
+ | 'token_charge';
111
+
112
+ export type NexFinopsBillingCardChargeStatus =
113
+ | 'scheduled'
114
+ | 'stale'
115
+ | 'confirmed'
116
+ | 'refused'
117
+ | 'refunded'
118
+ | 'chargeback'
119
+ | 'canceled'
120
+ | 'reverted';
121
+
122
+ export interface INexFinopsBillingCardChargeHistoryEntry {
123
+ at: string;
124
+ by: string | null;
125
+ action: 'adjust' | 'readjust' | 'revert' | 'charge' | 'event';
126
+ value?: number | null;
127
+ event?: string | null;
128
+ }
129
+
130
+ export interface INexFinopsBillingCardCharge {
131
+ mode: NexFinopsBillingCardChargeMode;
132
+ payment_method_id: string;
133
+ asaas_payment_id: string;
134
+ subscription_id?: string | null;
135
+ /** `dueDate` do `pay_` no Asaas (YYYY-MM-DD). */
136
+ due_date: string;
137
+ /** Caminho A: valor antes do ajuste. */
138
+ value_before?: number | null;
139
+ /** = `billing.total` no momento do ajuste. */
140
+ value_after: number;
141
+ status: NexFinopsBillingCardChargeStatus;
142
+ raw_status?: string | null;
143
+ adjusted_at: string;
144
+ adjusted_by: { kind: 'user' | 'system'; id: string | null };
145
+ last_event?: string | null;
146
+ last_event_at?: string | null;
147
+ failure?: { event: string; description?: string | null } | null;
148
+ /** Capado em 30 entradas. */
149
+ history: INexFinopsBillingCardChargeHistoryEntry[];
89
150
  }
90
151
 
91
152
  // ── Main Document ──
@@ -144,6 +205,15 @@ export interface INexFinopsBilling extends IFireGlobalDoc {
144
205
 
145
206
  // Observações
146
207
  notes?: string | null;
208
+
209
+ // ── Cartão (feat-253) ──
210
+
211
+ /** Método herdado do `default_payment_method_id` do contrato na geração (ou escolhido depois). */
212
+ payment_method_id?: string | null;
213
+ payment_method_snapshot?: INexFinopsBillingPaymentMethodSnapshot | null;
214
+ /** Todos os `pay_` do Asaas já associados (A e B) — chave do roteamento do webhook. Interno. */
215
+ card_payment_ids?: string[];
216
+ card_charge?: INexFinopsBillingCardCharge | null;
147
217
  }
148
218
 
149
219
  // ── Status transitions ──
@@ -139,6 +139,14 @@ export interface INexFinopsContract extends IFireGlobalDoc {
139
139
  /** Método com que o primeiro pagamento foi feito. `accepted_payment_methods` é a oferta; este é o fato. */
140
140
  payment_method?: NexFinopsPaymentMethod | null;
141
141
  asaas?: INexFinopsContractAsaasInfo | null;
142
+ /**
143
+ * Ids de `payment_methods` do MESMO customer habilitados neste contrato.
144
+ * Escrito só pela rota dedicada `PUT /contracts/:id/payment-methods`; o
145
+ * `PUT /contracts/:id` genérico ignora este campo.
146
+ */
147
+ payment_method_ids?: string[] | null;
148
+ /** Precisa estar em `payment_method_ids`. É o que a cobrança herda no `billingGenerate`. */
149
+ default_payment_method_id?: string | null;
142
150
  /**
143
151
  * Franquia incluída no ciclo, por métrica. A CHAVE é o id da métrica (ver
144
152
  * `NexFinopsMetricCatalog`) e é deliberadamente `string`: métrica nova é um
@@ -172,6 +172,17 @@ export interface INexFinopsContract extends IFireGlobalDoc {
172
172
  payment_method?: NexFinopsPaymentMethod | null;
173
173
  asaas?: INexFinopsContractAsaasInfo | null;
174
174
 
175
+ // ── Métodos de pagamento habilitados (feat-253) ──
176
+
177
+ /**
178
+ * Ids de `payment_methods` do MESMO customer habilitados neste contrato.
179
+ * Escrito só pela rota dedicada `PUT /contracts/:id/payment-methods`; o
180
+ * `PUT /contracts/:id` genérico ignora este campo.
181
+ */
182
+ payment_method_ids?: string[] | null;
183
+ /** Precisa estar em `payment_method_ids`. É o que a cobrança herda no `billingGenerate`. */
184
+ default_payment_method_id?: string | null;
185
+
175
186
  // ── Franquias e alertas de consumo (feat-150 F0) ──
176
187
 
177
188
  /**
@@ -0,0 +1,77 @@
1
+ import type { IFireGlobalDoc } from '../../shared';
2
+ import type { NexFinopsAsaasSubscriptionStatus } from './contract';
3
+ /**
4
+ * - `asaas_subscription` (caminho A): cartão capturado na página do Asaas, dentro
5
+ * de uma assinatura. Id do doc: `asub_<subscription_id>`.
6
+ * - `asaas_card_token` (caminho B): token de cartão do Asaas. Id do doc: `atok_<shortid>`.
7
+ */
8
+ export type NexFinopsPaymentMethodKind = 'asaas_subscription' | 'asaas_card_token';
9
+ /**
10
+ * - `active`: assinatura `ACTIVE` sem `deleted`, ou token válido.
11
+ * - `failing`: última captura recusada/reprovada; volta a `active` no próximo `PAYMENT_CONFIRMED`.
12
+ * - `inactive`: assinatura `INACTIVE`/`EXPIRED`/`deleted`, ou desativado pelo operador.
13
+ * - `revoked`: token invalidado pelo Asaas. Terminal — o cliente cadastra o cartão de novo.
14
+ */
15
+ export type NexFinopsPaymentMethodStatus = 'active' | 'failing' | 'inactive' | 'revoked';
16
+ export type NexFinopsPaymentMethodSource = 'discovery_contract_asaas' | 'discovery_payment_link' | 'manual_link' | 'asaas_capture';
17
+ export interface INexFinopsPaymentMethodProviderRef {
18
+ provider_id: string;
19
+ provider_type: 'asaas';
20
+ env: 'sandbox' | 'production';
21
+ /** `cus_` dono do cartão/assinatura (Q5) — pode ser ≠ `taker.provider_refs.remote_customer_id`. */
22
+ remote_customer_id: string;
23
+ }
24
+ export interface INexFinopsPaymentMethodSubscriptionInfo {
25
+ subscription_id: string;
26
+ /** Doc id do nosso payment_link (origem). */
27
+ payment_link_id?: string | null;
28
+ /** Checkout de vendas (`contract.asaas.checkout_id`). */
29
+ checkout_id?: string | null;
30
+ subscription_status?: NexFinopsAsaasSubscriptionStatus | null;
31
+ deleted?: boolean | null;
32
+ cycle?: string | null;
33
+ /** Valor BASE da assinatura. */
34
+ value?: number | null;
35
+ /** Data civil `YYYY-MM-DD`. */
36
+ next_due_date?: string | null;
37
+ }
38
+ /** PCI: só bandeira e últimos 4. */
39
+ export interface INexFinopsPaymentMethodCard {
40
+ brand: string | null;
41
+ last4: string | null;
42
+ }
43
+ export interface INexFinopsPaymentMethodSourceInfo {
44
+ kind: NexFinopsPaymentMethodSource;
45
+ contract_id?: string | null;
46
+ payment_link_id?: string | null;
47
+ journey_ref?: string | null;
48
+ /** Pagamento que originou o método (caminho B). */
49
+ asaas_payment_id?: string | null;
50
+ }
51
+ export interface INexFinopsPaymentMethodLastCharge {
52
+ asaas_payment_id: string;
53
+ status: string;
54
+ at: string;
55
+ error?: string | null;
56
+ }
57
+ export interface INexFinopsCustomerPaymentMethod extends IFireGlobalDoc {
58
+ customer_id: string;
59
+ kind: NexFinopsPaymentMethodKind;
60
+ status: NexFinopsPaymentMethodStatus;
61
+ label?: string | null;
62
+ /** PCI: só isto. Nunca número completo, CCV ou token. */
63
+ card: INexFinopsPaymentMethodCard;
64
+ provider: INexFinopsPaymentMethodProviderRef;
65
+ /** Só no kind `asaas_subscription`. */
66
+ asaas_subscription?: INexFinopsPaymentMethodSubscriptionInfo | null;
67
+ /** Kind `asaas_card_token`: existe `private/credential`. Único reflexo do token. */
68
+ has_credential?: boolean | null;
69
+ source: INexFinopsPaymentMethodSourceInfo;
70
+ last_synced_at?: string | null;
71
+ last_used_at?: string | null;
72
+ last_charge?: INexFinopsPaymentMethodLastCharge | null;
73
+ }
74
+ /** Prefixos determinísticos dos ids (idempotência da descoberta). */
75
+ export declare const NEX_FINOPS_PAYMENT_METHOD_ID_PREFIX: Record<NexFinopsPaymentMethodKind, string>;
76
+ /** Status em que o método pode ser herdado por uma cobrança. */
77
+ export declare const NEX_FINOPS_PAYMENT_METHOD_USABLE_STATUSES: readonly NexFinopsPaymentMethodStatus[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NEX_FINOPS_PAYMENT_METHOD_USABLE_STATUSES = exports.NEX_FINOPS_PAYMENT_METHOD_ID_PREFIX = void 0;
4
+ /** Prefixos determinísticos dos ids (idempotência da descoberta). */
5
+ exports.NEX_FINOPS_PAYMENT_METHOD_ID_PREFIX = {
6
+ asaas_subscription: 'asub_',
7
+ asaas_card_token: 'atok_',
8
+ };
9
+ /** Status em que o método pode ser herdado por uma cobrança. */
10
+ exports.NEX_FINOPS_PAYMENT_METHOD_USABLE_STATUSES = ['active', 'failing'];
@@ -0,0 +1,106 @@
1
+ import type { IFireGlobalDoc } from '../../shared';
2
+ import type { NexFinopsAsaasSubscriptionStatus } from './contract';
3
+
4
+ // ── Métodos de pagamento do cliente (feat-253) ──
5
+ //
6
+ // Coleção própria do nex-finops: `core/nexus/apps/nex-finops/payment_methods/{pmId}`.
7
+ // Fica FORA do customer porque o portal devolve o customer inteiro e a regra de
8
+ // `nex-customers/customers` não tem curinga de subcoleção.
9
+ //
10
+ // PCI: o doc só guarda bandeira + últimos 4. Número completo, CCV, dados do
11
+ // portador ou token de cartão NÃO têm campo aqui e não devem ganhar um. O token
12
+ // do caminho B mora em `payment_methods/{pmId}/private/credential`, sem leitura
13
+ // pelo cliente e sem tipo exportado para o front.
14
+
15
+ /**
16
+ * - `asaas_subscription` (caminho A): cartão capturado na página do Asaas, dentro
17
+ * de uma assinatura. Id do doc: `asub_<subscription_id>`.
18
+ * - `asaas_card_token` (caminho B): token de cartão do Asaas. Id do doc: `atok_<shortid>`.
19
+ */
20
+ export type NexFinopsPaymentMethodKind = 'asaas_subscription' | 'asaas_card_token';
21
+
22
+ /**
23
+ * - `active`: assinatura `ACTIVE` sem `deleted`, ou token válido.
24
+ * - `failing`: última captura recusada/reprovada; volta a `active` no próximo `PAYMENT_CONFIRMED`.
25
+ * - `inactive`: assinatura `INACTIVE`/`EXPIRED`/`deleted`, ou desativado pelo operador.
26
+ * - `revoked`: token invalidado pelo Asaas. Terminal — o cliente cadastra o cartão de novo.
27
+ */
28
+ export type NexFinopsPaymentMethodStatus = 'active' | 'failing' | 'inactive' | 'revoked';
29
+
30
+ export type NexFinopsPaymentMethodSource =
31
+ | 'discovery_contract_asaas'
32
+ | 'discovery_payment_link'
33
+ | 'manual_link'
34
+ | 'asaas_capture';
35
+
36
+ export interface INexFinopsPaymentMethodProviderRef {
37
+ provider_id: string;
38
+ provider_type: 'asaas';
39
+ env: 'sandbox' | 'production';
40
+ /** `cus_` dono do cartão/assinatura (Q5) — pode ser ≠ `taker.provider_refs.remote_customer_id`. */
41
+ remote_customer_id: string;
42
+ }
43
+
44
+ export interface INexFinopsPaymentMethodSubscriptionInfo {
45
+ subscription_id: string;
46
+ /** Doc id do nosso payment_link (origem). */
47
+ payment_link_id?: string | null;
48
+ /** Checkout de vendas (`contract.asaas.checkout_id`). */
49
+ checkout_id?: string | null;
50
+ subscription_status?: NexFinopsAsaasSubscriptionStatus | null;
51
+ deleted?: boolean | null;
52
+ cycle?: string | null;
53
+ /** Valor BASE da assinatura. */
54
+ value?: number | null;
55
+ /** Data civil `YYYY-MM-DD`. */
56
+ next_due_date?: string | null;
57
+ }
58
+
59
+ /** PCI: só bandeira e últimos 4. */
60
+ export interface INexFinopsPaymentMethodCard {
61
+ brand: string | null;
62
+ last4: string | null;
63
+ }
64
+
65
+ export interface INexFinopsPaymentMethodSourceInfo {
66
+ kind: NexFinopsPaymentMethodSource;
67
+ contract_id?: string | null;
68
+ payment_link_id?: string | null;
69
+ journey_ref?: string | null;
70
+ /** Pagamento que originou o método (caminho B). */
71
+ asaas_payment_id?: string | null;
72
+ }
73
+
74
+ export interface INexFinopsPaymentMethodLastCharge {
75
+ asaas_payment_id: string;
76
+ status: string;
77
+ at: string;
78
+ error?: string | null;
79
+ }
80
+
81
+ export interface INexFinopsCustomerPaymentMethod extends IFireGlobalDoc {
82
+ customer_id: string;
83
+ kind: NexFinopsPaymentMethodKind;
84
+ status: NexFinopsPaymentMethodStatus;
85
+ label?: string | null;
86
+ /** PCI: só isto. Nunca número completo, CCV ou token. */
87
+ card: INexFinopsPaymentMethodCard;
88
+ provider: INexFinopsPaymentMethodProviderRef;
89
+ /** Só no kind `asaas_subscription`. */
90
+ asaas_subscription?: INexFinopsPaymentMethodSubscriptionInfo | null;
91
+ /** Kind `asaas_card_token`: existe `private/credential`. Único reflexo do token. */
92
+ has_credential?: boolean | null;
93
+ source: INexFinopsPaymentMethodSourceInfo;
94
+ last_synced_at?: string | null;
95
+ last_used_at?: string | null;
96
+ last_charge?: INexFinopsPaymentMethodLastCharge | null;
97
+ }
98
+
99
+ /** Prefixos determinísticos dos ids (idempotência da descoberta). */
100
+ export const NEX_FINOPS_PAYMENT_METHOD_ID_PREFIX: Record<NexFinopsPaymentMethodKind, string> = {
101
+ asaas_subscription: 'asub_',
102
+ asaas_card_token: 'atok_',
103
+ };
104
+
105
+ /** Status em que o método pode ser herdado por uma cobrança. */
106
+ export const NEX_FINOPS_PAYMENT_METHOD_USABLE_STATUSES: readonly NexFinopsPaymentMethodStatus[] = ['active', 'failing'];
@@ -12,3 +12,5 @@ export declare const FINOPS_SERVICES_COLLECTION = "services";
12
12
  export declare const FINOPS_TAKERS_COLLECTION = "takers";
13
13
  export declare const FINOPS_INVOICES_COLLECTION = "invoices";
14
14
  export declare const FINOPS_PAYMENT_LINKS_COLLECTION = "payment_links";
15
+ /** feat-253 — métodos de pagamento do cliente (path: core/nexus/apps/nex-finops/payment_methods). */
16
+ export declare const FINOPS_PAYMENT_METHODS_COLLECTION = "payment_methods";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FINOPS_PAYMENT_LINKS_COLLECTION = exports.FINOPS_INVOICES_COLLECTION = exports.FINOPS_TAKERS_COLLECTION = exports.FINOPS_SERVICES_COLLECTION = exports.FINOPS_DICS_SERVICES_ID = exports.FINOPS_ISSUER_PROFILES_COLLECTION = exports.FINOPS_DICS_ISSUERS_ID = exports.FINOPS_PROVIDERS_COLLECTION = exports.FINOPS_DICS_COLLECTION = exports.EVO_FINOPS_APP = void 0;
3
+ exports.FINOPS_PAYMENT_METHODS_COLLECTION = exports.FINOPS_PAYMENT_LINKS_COLLECTION = exports.FINOPS_INVOICES_COLLECTION = exports.FINOPS_TAKERS_COLLECTION = exports.FINOPS_SERVICES_COLLECTION = exports.FINOPS_DICS_SERVICES_ID = exports.FINOPS_ISSUER_PROFILES_COLLECTION = exports.FINOPS_DICS_ISSUERS_ID = exports.FINOPS_PROVIDERS_COLLECTION = exports.FINOPS_DICS_COLLECTION = exports.EVO_FINOPS_APP = void 0;
4
4
  // evo-finops app identifier for Firestore paths
5
5
  exports.EVO_FINOPS_APP = "evo-finops";
6
6
  // Collection names for evo-finops
@@ -17,3 +17,5 @@ exports.FINOPS_SERVICES_COLLECTION = "services";
17
17
  exports.FINOPS_TAKERS_COLLECTION = "takers";
18
18
  exports.FINOPS_INVOICES_COLLECTION = "invoices";
19
19
  exports.FINOPS_PAYMENT_LINKS_COLLECTION = "payment_links";
20
+ /** feat-253 — métodos de pagamento do cliente (path: core/nexus/apps/nex-finops/payment_methods). */
21
+ exports.FINOPS_PAYMENT_METHODS_COLLECTION = "payment_methods";
@@ -16,3 +16,5 @@ export const FINOPS_TAKERS_COLLECTION = "takers";
16
16
  export const FINOPS_INVOICES_COLLECTION = "invoices";
17
17
  export const FINOPS_PAYMENT_LINKS_COLLECTION = "payment_links";
18
18
 
19
+ /** feat-253 — métodos de pagamento do cliente (path: core/nexus/apps/nex-finops/payment_methods). */
20
+ export const FINOPS_PAYMENT_METHODS_COLLECTION = "payment_methods";
@@ -4,6 +4,7 @@ export * from "./common/taker";
4
4
  export * from "./common/contract";
5
5
  export * from "./common/proposal";
6
6
  export * from "./common/billing";
7
+ export * from "./common/payment-method";
7
8
  export * from "./providers";
8
9
  export * from "./providers/provider_fiscal_types";
9
10
  export * from "./providers/asaas/asaas_provider";
@@ -21,6 +21,7 @@ __exportStar(require("./common/taker"), exports);
21
21
  __exportStar(require("./common/contract"), exports);
22
22
  __exportStar(require("./common/proposal"), exports);
23
23
  __exportStar(require("./common/billing"), exports);
24
+ __exportStar(require("./common/payment-method"), exports);
24
25
  __exportStar(require("./providers"), exports);
25
26
  __exportStar(require("./providers/provider_fiscal_types"), exports);
26
27
  __exportStar(require("./providers/asaas/asaas_provider"), exports);
@@ -6,6 +6,7 @@ export * from "./common/taker";
6
6
  export * from "./common/contract";
7
7
  export * from "./common/proposal";
8
8
  export * from "./common/billing";
9
+ export * from "./common/payment-method";
9
10
  export * from "./providers";
10
11
  export * from "./providers/provider_fiscal_types";
11
12
  export * from "./providers/asaas/asaas_provider";