tychat-contracts 1.0.85 → 1.0.87
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.
- package/dist/billing/list-billings-query.dto.d.ts +3 -0
- package/dist/billing/list-billings-query.dto.d.ts.map +1 -1
- package/dist/billing/list-billings-query.dto.js +21 -0
- package/dist/cashback/cashback-balance-response.dto.d.ts +15 -0
- package/dist/cashback/cashback-balance-response.dto.d.ts.map +1 -0
- package/dist/cashback/cashback-balance-response.dto.js +64 -0
- package/dist/cashback/cashback-config-response.dto.d.ts +19 -0
- package/dist/cashback/cashback-config-response.dto.d.ts.map +1 -0
- package/dist/cashback/cashback-config-response.dto.js +80 -0
- package/dist/cashback/cashback-enums.d.ts +32 -0
- package/dist/cashback/cashback-enums.d.ts.map +1 -0
- package/dist/cashback/cashback-enums.js +37 -0
- package/dist/cashback/cashback-kafka-payloads.d.ts +83 -0
- package/dist/cashback/cashback-kafka-payloads.d.ts.map +1 -0
- package/dist/cashback/cashback-kafka-payloads.js +2 -0
- package/dist/cashback/cashback-kafka-topics.d.ts +18 -0
- package/dist/cashback/cashback-kafka-topics.d.ts.map +1 -0
- package/dist/cashback/cashback-kafka-topics.js +23 -0
- package/dist/cashback/index.d.ts +8 -0
- package/dist/cashback/index.d.ts.map +1 -0
- package/dist/cashback/index.js +23 -0
- package/dist/cashback/referral-code-response.dto.d.ts +21 -0
- package/dist/cashback/referral-code-response.dto.d.ts.map +1 -0
- package/dist/cashback/referral-code-response.dto.js +90 -0
- package/dist/cashback/use-referral-code-response.dto.d.ts +9 -0
- package/dist/cashback/use-referral-code-response.dto.d.ts.map +1 -0
- package/dist/cashback/use-referral-code-response.dto.js +34 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/payment-gateway/create-gateway-payment.dto.d.ts +1 -1
- package/dist/payment-gateway/create-gateway-payment.dto.d.ts.map +1 -1
- package/dist/payment-gateway/create-gateway-payment.dto.js +3 -3
- package/dist/payment-gateway/index.d.ts +5 -0
- package/dist/payment-gateway/index.d.ts.map +1 -1
- package/dist/payment-gateway/index.js +5 -0
- package/dist/payment-gateway/initiate-billing-payment-response.dto.d.ts +13 -0
- package/dist/payment-gateway/initiate-billing-payment-response.dto.d.ts.map +1 -0
- package/dist/payment-gateway/initiate-billing-payment-response.dto.js +48 -0
- package/dist/payment-gateway/initiate-billing-payment.mapper.d.ts +7 -0
- package/dist/payment-gateway/initiate-billing-payment.mapper.d.ts.map +1 -0
- package/dist/payment-gateway/initiate-billing-payment.mapper.js +17 -0
- package/dist/payment-gateway/payment-gateway-routing-matrix.d.ts +3 -0
- package/dist/payment-gateway/payment-gateway-routing-matrix.d.ts.map +1 -0
- package/dist/payment-gateway/payment-gateway-routing-matrix.js +15 -0
- package/dist/payment-gateway/payment-gateway-routing.dto.d.ts +14 -0
- package/dist/payment-gateway/payment-gateway-routing.dto.d.ts.map +1 -0
- package/dist/payment-gateway/payment-gateway-routing.dto.js +89 -0
- package/dist/payment-gateway/platform-configuration.topics.d.ts +3 -0
- package/dist/payment-gateway/platform-configuration.topics.d.ts.map +1 -0
- package/dist/payment-gateway/platform-configuration.topics.js +5 -0
- package/package.json +1 -1
- package/src/billing/list-billings-query.dto.ts +22 -0
- package/src/cashback/cashback-balance-response.dto.ts +33 -0
- package/src/cashback/cashback-config-response.dto.ts +43 -0
- package/src/cashback/cashback-enums.ts +33 -0
- package/src/cashback/cashback-kafka-payloads.ts +102 -0
- package/src/cashback/cashback-kafka-topics.ts +23 -0
- package/src/cashback/index.ts +7 -0
- package/src/cashback/referral-code-response.dto.ts +49 -0
- package/src/cashback/use-referral-code-response.dto.ts +15 -0
- package/src/index.ts +1 -0
- package/src/payment-gateway/create-gateway-payment.dto.ts +5 -4
- package/src/payment-gateway/index.ts +5 -0
- package/src/payment-gateway/initiate-billing-payment-response.dto.ts +25 -0
- package/src/payment-gateway/initiate-billing-payment.mapper.ts +19 -0
- package/src/payment-gateway/payment-gateway-routing-matrix.ts +18 -0
- package/src/payment-gateway/payment-gateway-routing.dto.ts +84 -0
- package/src/payment-gateway/platform-configuration.topics.ts +2 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './cashback-enums';
|
|
2
|
+
export * from './cashback-kafka-topics';
|
|
3
|
+
export * from './cashback-kafka-payloads';
|
|
4
|
+
export * from './cashback-config-response.dto';
|
|
5
|
+
export * from './referral-code-response.dto';
|
|
6
|
+
export * from './use-referral-code-response.dto';
|
|
7
|
+
export * from './cashback-balance-response.dto';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
+
import { CashbackDiscountTypeDto, CashbackExpirationTypeDto } from './cashback-enums';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Response DTO for a referral code
|
|
6
|
+
*/
|
|
7
|
+
export class ReferralCodeResponseDto {
|
|
8
|
+
@ApiProperty({ description: 'Referral code ID (UUID)' })
|
|
9
|
+
id: string;
|
|
10
|
+
|
|
11
|
+
@ApiProperty({ description: 'Patient ID who owns this code' })
|
|
12
|
+
patientId: string;
|
|
13
|
+
|
|
14
|
+
@ApiProperty({ description: 'The 8-character referral code', example: 'ABCD1234' })
|
|
15
|
+
code: string;
|
|
16
|
+
|
|
17
|
+
@ApiProperty({ description: 'Cashback percentage snapshot' })
|
|
18
|
+
cashbackPercentage: number;
|
|
19
|
+
|
|
20
|
+
@ApiProperty({ description: 'Discount type snapshot', enum: CashbackDiscountTypeDto })
|
|
21
|
+
discountType: CashbackDiscountTypeDto;
|
|
22
|
+
|
|
23
|
+
@ApiProperty({ description: 'Discount value snapshot' })
|
|
24
|
+
discountValue: number;
|
|
25
|
+
|
|
26
|
+
@ApiProperty({ description: 'Expiration type snapshot', enum: CashbackExpirationTypeDto })
|
|
27
|
+
expirationType: CashbackExpirationTypeDto;
|
|
28
|
+
|
|
29
|
+
@ApiPropertyOptional({ description: 'Expiration days snapshot' })
|
|
30
|
+
expirationDays?: number | null;
|
|
31
|
+
|
|
32
|
+
@ApiPropertyOptional({ description: 'Max total uses snapshot' })
|
|
33
|
+
maxTotalUses?: number | null;
|
|
34
|
+
|
|
35
|
+
@ApiPropertyOptional({ description: 'Max uses per patient snapshot' })
|
|
36
|
+
maxUsesPerPatient?: number | null;
|
|
37
|
+
|
|
38
|
+
@ApiPropertyOptional({ description: 'Code expiration date' })
|
|
39
|
+
codeExpiresAt?: string | null;
|
|
40
|
+
|
|
41
|
+
@ApiProperty({ description: 'Total number of times used' })
|
|
42
|
+
totalUsesCount: number;
|
|
43
|
+
|
|
44
|
+
@ApiProperty({ description: 'Whether code is active' })
|
|
45
|
+
isActive: boolean;
|
|
46
|
+
|
|
47
|
+
@ApiProperty({ description: 'Creation timestamp' })
|
|
48
|
+
createdAt: string;
|
|
49
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Response DTO for using a referral code
|
|
5
|
+
*/
|
|
6
|
+
export class UseReferralCodeResponseDto {
|
|
7
|
+
@ApiProperty({ description: 'Cashback amount awarded to the referrer' })
|
|
8
|
+
cashbackAmount: number;
|
|
9
|
+
|
|
10
|
+
@ApiProperty({ description: 'Discount amount applied to the referred patient' })
|
|
11
|
+
discountAmount: number;
|
|
12
|
+
|
|
13
|
+
@ApiProperty({ description: 'Patient ID of the referrer (code owner)' })
|
|
14
|
+
referrerPatientId: string;
|
|
15
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -72,14 +72,15 @@ export class CreateGatewayPaymentDto {
|
|
|
72
72
|
@Min(0.01)
|
|
73
73
|
amount: number;
|
|
74
74
|
|
|
75
|
-
@
|
|
76
|
-
description:
|
|
75
|
+
@ApiPropertyOptional({
|
|
76
|
+
description:
|
|
77
|
+
'Gateway explícito. Se omitido, o payment-gateway-service resolve pela rota global (prioridade + métodos).',
|
|
77
78
|
enum: PAYMENT_GATEWAYS,
|
|
78
79
|
example: 'ASAAS',
|
|
79
80
|
})
|
|
81
|
+
@IsOptional()
|
|
80
82
|
@IsEnum(PAYMENT_GATEWAYS)
|
|
81
|
-
|
|
82
|
-
gateway: PaymentGatewayDto;
|
|
83
|
+
gateway?: PaymentGatewayDto;
|
|
83
84
|
|
|
84
85
|
@ApiProperty({
|
|
85
86
|
description: 'Payment method',
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export * from './payment-gateway.enums';
|
|
2
|
+
export * from './payment-gateway-routing-matrix';
|
|
3
|
+
export * from './payment-gateway-routing.dto';
|
|
4
|
+
export * from './initiate-billing-payment-response.dto';
|
|
5
|
+
export * from './initiate-billing-payment.mapper';
|
|
6
|
+
export * from './platform-configuration.topics';
|
|
2
7
|
export * from './create-gateway-payment.dto';
|
|
3
8
|
export * from './update-gateway-payment.dto';
|
|
4
9
|
export * from './gateway-payment-response.dto';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
+
import { GatewayPaymentResponseDto } from './gateway-payment-response.dto';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resposta de iniciar pagamento de cobrança: inclui o registro do pagamento e
|
|
6
|
+
* campos explícitos copiados de metadata quando presentes (PIX, checkout, boleto).
|
|
7
|
+
*/
|
|
8
|
+
export class InitiateBillingPaymentResponseDto extends GatewayPaymentResponseDto {
|
|
9
|
+
@ApiPropertyOptional({
|
|
10
|
+
description: 'URL para fluxo de pagamento (cartão, checkout hospedado, etc.)',
|
|
11
|
+
})
|
|
12
|
+
checkoutUrl?: string | null;
|
|
13
|
+
|
|
14
|
+
@ApiPropertyOptional({ description: 'QR Code PIX em base64 quando aplicável' })
|
|
15
|
+
pixQrCode?: string | null;
|
|
16
|
+
|
|
17
|
+
@ApiPropertyOptional({ description: 'PIX copia e cola quando aplicável' })
|
|
18
|
+
pixCopyPaste?: string | null;
|
|
19
|
+
|
|
20
|
+
@ApiPropertyOptional({ description: 'URL do boleto quando aplicável' })
|
|
21
|
+
boletoUrl?: string | null;
|
|
22
|
+
|
|
23
|
+
@ApiPropertyOptional({ description: 'Código de barras do boleto quando aplicável' })
|
|
24
|
+
boletoBarcode?: string | null;
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GatewayPaymentResponseDto } from './gateway-payment-response.dto';
|
|
2
|
+
import { InitiateBillingPaymentResponseDto } from './initiate-billing-payment-response.dto';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copia campos conhecidos de `metadata` para a resposta explícita de checkout/PIX/boleto.
|
|
6
|
+
*/
|
|
7
|
+
export function toInitiateBillingPaymentResponseDto(
|
|
8
|
+
payment: GatewayPaymentResponseDto,
|
|
9
|
+
): InitiateBillingPaymentResponseDto {
|
|
10
|
+
const meta = (payment.metadata ?? {}) as Record<string, unknown>;
|
|
11
|
+
return {
|
|
12
|
+
...payment,
|
|
13
|
+
checkoutUrl: (meta.paymentUrl as string | undefined) ?? undefined,
|
|
14
|
+
pixQrCode: (meta.pixQrCode as string | undefined) ?? undefined,
|
|
15
|
+
pixCopyPaste: (meta.pixCopyPaste as string | undefined) ?? undefined,
|
|
16
|
+
boletoUrl: (meta.boletoUrl as string | undefined) ?? undefined,
|
|
17
|
+
boletoBarcode: (meta.boletoBarcode as string | undefined) ?? undefined,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GatewayPaymentMethodDto, PaymentGatewayDto } from './payment-gateway.enums';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Matriz fixa gateway × meio (alinhada ao README do payment-gateway-service).
|
|
5
|
+
* Usada para validar configuração persistida e para checagens determinísticas.
|
|
6
|
+
*/
|
|
7
|
+
const SUPPORTED: Record<PaymentGatewayDto, ReadonlySet<GatewayPaymentMethodDto>> = {
|
|
8
|
+
ASAAS: new Set(['PIX', 'CREDIT_CARD', 'DEBIT_CARD', 'BOLETO']),
|
|
9
|
+
MERCADO_PAGO: new Set(['PIX', 'CREDIT_CARD', 'DEBIT_CARD']),
|
|
10
|
+
STRIPE: new Set(['CREDIT_CARD', 'DEBIT_CARD']),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function isMethodSupportedByGateway(
|
|
14
|
+
gateway: PaymentGatewayDto,
|
|
15
|
+
method: GatewayPaymentMethodDto,
|
|
16
|
+
): boolean {
|
|
17
|
+
return SUPPORTED[gateway]?.has(method) ?? false;
|
|
18
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
2
|
+
import { Type } from 'class-transformer';
|
|
3
|
+
import {
|
|
4
|
+
ArrayMinSize,
|
|
5
|
+
IsArray,
|
|
6
|
+
IsEnum,
|
|
7
|
+
Validate,
|
|
8
|
+
ValidateNested,
|
|
9
|
+
ValidationArguments,
|
|
10
|
+
ValidatorConstraint,
|
|
11
|
+
ValidatorConstraintInterface,
|
|
12
|
+
} from 'class-validator';
|
|
13
|
+
import {
|
|
14
|
+
GATEWAY_PAYMENT_METHODS,
|
|
15
|
+
type GatewayPaymentMethodDto,
|
|
16
|
+
PAYMENT_GATEWAYS,
|
|
17
|
+
type PaymentGatewayDto,
|
|
18
|
+
} from './payment-gateway.enums';
|
|
19
|
+
import { isMethodSupportedByGateway } from './payment-gateway-routing-matrix';
|
|
20
|
+
|
|
21
|
+
@ValidatorConstraint({ name: 'paymentGatewayRoutingEntriesValid', async: false })
|
|
22
|
+
export class PaymentGatewayRoutingEntriesConstraint implements ValidatorConstraintInterface {
|
|
23
|
+
validate(entries: unknown, _args: ValidationArguments): boolean {
|
|
24
|
+
if (!Array.isArray(entries) || entries.length < 1) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const seenGateways = new Set<string>();
|
|
28
|
+
for (const raw of entries) {
|
|
29
|
+
if (!raw || typeof raw !== 'object') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const e = raw as { gateway?: unknown; methods?: unknown };
|
|
33
|
+
if (typeof e.gateway !== 'string' || !PAYMENT_GATEWAYS.includes(e.gateway as PaymentGatewayDto)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const gateway = e.gateway as PaymentGatewayDto;
|
|
37
|
+
if (seenGateways.has(gateway)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
seenGateways.add(gateway);
|
|
41
|
+
if (!Array.isArray(e.methods) || e.methods.length < 1) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
for (const m of e.methods) {
|
|
45
|
+
if (typeof m !== 'string' || !GATEWAY_PAYMENT_METHODS.includes(m as GatewayPaymentMethodDto)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (!isMethodSupportedByGateway(gateway, m as GatewayPaymentMethodDto)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
defaultMessage(): string {
|
|
57
|
+
return (
|
|
58
|
+
'paymentGatewayRouting.entries inválido: ordem vazia, gateway duplicado, methods vazio ' +
|
|
59
|
+
'ou combinação gateway/método não suportada pela plataforma'
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class PaymentGatewayRoutingEntryDto {
|
|
65
|
+
@ApiProperty({ enum: PAYMENT_GATEWAYS })
|
|
66
|
+
@IsEnum(PAYMENT_GATEWAYS as unknown as object)
|
|
67
|
+
gateway: PaymentGatewayDto;
|
|
68
|
+
|
|
69
|
+
@ApiProperty({ enum: GATEWAY_PAYMENT_METHODS, isArray: true })
|
|
70
|
+
@IsArray()
|
|
71
|
+
@ArrayMinSize(1)
|
|
72
|
+
@IsEnum(GATEWAY_PAYMENT_METHODS as unknown as object, { each: true })
|
|
73
|
+
methods: GatewayPaymentMethodDto[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class PaymentGatewayRoutingDto {
|
|
77
|
+
@ApiProperty({ type: [PaymentGatewayRoutingEntryDto] })
|
|
78
|
+
@IsArray()
|
|
79
|
+
@ArrayMinSize(1)
|
|
80
|
+
@ValidateNested({ each: true })
|
|
81
|
+
@Type(() => PaymentGatewayRoutingEntryDto)
|
|
82
|
+
@Validate(PaymentGatewayRoutingEntriesConstraint)
|
|
83
|
+
entries: PaymentGatewayRoutingEntryDto[];
|
|
84
|
+
}
|