@hed-hog/billing 0.0.2
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/adapters/billing-gateway-registry.d.ts +8 -0
- package/dist/adapters/billing-gateway-registry.d.ts.map +1 -0
- package/dist/adapters/billing-gateway-registry.js +33 -0
- package/dist/adapters/billing-gateway-registry.js.map +1 -0
- package/dist/adapters/mercadopago.adapter.d.ts +44 -0
- package/dist/adapters/mercadopago.adapter.d.ts.map +1 -0
- package/dist/adapters/mercadopago.adapter.js +68 -0
- package/dist/adapters/mercadopago.adapter.js.map +1 -0
- package/dist/adapters/pagarme.adapter.d.ts +44 -0
- package/dist/adapters/pagarme.adapter.d.ts.map +1 -0
- package/dist/adapters/pagarme.adapter.js +68 -0
- package/dist/adapters/pagarme.adapter.js.map +1 -0
- package/dist/adapters/payment-gateway.adapter.d.ts +15 -0
- package/dist/adapters/payment-gateway.adapter.d.ts.map +1 -0
- package/dist/adapters/payment-gateway.adapter.js +3 -0
- package/dist/adapters/payment-gateway.adapter.js.map +1 -0
- package/dist/adapters/stripe.adapter.d.ts +44 -0
- package/dist/adapters/stripe.adapter.d.ts.map +1 -0
- package/dist/adapters/stripe.adapter.js +69 -0
- package/dist/adapters/stripe.adapter.js.map +1 -0
- package/dist/billing-contracts.controller.d.ts +22 -0
- package/dist/billing-contracts.controller.d.ts.map +1 -0
- package/dist/billing-contracts.controller.js +84 -0
- package/dist/billing-contracts.controller.js.map +1 -0
- package/dist/billing-coupons.controller.d.ts +22 -0
- package/dist/billing-coupons.controller.d.ts.map +1 -0
- package/dist/billing-coupons.controller.js +84 -0
- package/dist/billing-coupons.controller.js.map +1 -0
- package/dist/billing-dashboard.controller.d.ts +13 -0
- package/dist/billing-dashboard.controller.d.ts.map +1 -0
- package/dist/billing-dashboard.controller.js +36 -0
- package/dist/billing-dashboard.controller.js.map +1 -0
- package/dist/billing-entitlements.controller.d.ts +19 -0
- package/dist/billing-entitlements.controller.d.ts.map +1 -0
- package/dist/billing-entitlements.controller.js +62 -0
- package/dist/billing-entitlements.controller.js.map +1 -0
- package/dist/billing-gateways.controller.d.ts +8 -0
- package/dist/billing-gateways.controller.d.ts.map +1 -0
- package/dist/billing-gateways.controller.js +50 -0
- package/dist/billing-gateways.controller.js.map +1 -0
- package/dist/billing-invoices.controller.d.ts +18 -0
- package/dist/billing-invoices.controller.d.ts.map +1 -0
- package/dist/billing-invoices.controller.js +61 -0
- package/dist/billing-invoices.controller.js.map +1 -0
- package/dist/billing-offers.controller.d.ts +22 -0
- package/dist/billing-offers.controller.d.ts.map +1 -0
- package/dist/billing-offers.controller.js +84 -0
- package/dist/billing-offers.controller.js.map +1 -0
- package/dist/billing-orders.controller.d.ts +19 -0
- package/dist/billing-orders.controller.d.ts.map +1 -0
- package/dist/billing-orders.controller.js +62 -0
- package/dist/billing-orders.controller.js.map +1 -0
- package/dist/billing-payments.controller.d.ts +17 -0
- package/dist/billing-payments.controller.d.ts.map +1 -0
- package/dist/billing-payments.controller.js +51 -0
- package/dist/billing-payments.controller.js.map +1 -0
- package/dist/billing-prices.controller.d.ts +22 -0
- package/dist/billing-prices.controller.d.ts.map +1 -0
- package/dist/billing-prices.controller.js +84 -0
- package/dist/billing-prices.controller.js.map +1 -0
- package/dist/billing-products.controller.d.ts +22 -0
- package/dist/billing-products.controller.d.ts.map +1 -0
- package/dist/billing-products.controller.js +84 -0
- package/dist/billing-products.controller.js.map +1 -0
- package/dist/billing-refunds.controller.d.ts +16 -0
- package/dist/billing-refunds.controller.d.ts.map +1 -0
- package/dist/billing-refunds.controller.js +41 -0
- package/dist/billing-refunds.controller.js.map +1 -0
- package/dist/billing-subscriptions.controller.d.ts +22 -0
- package/dist/billing-subscriptions.controller.d.ts.map +1 -0
- package/dist/billing-subscriptions.controller.js +92 -0
- package/dist/billing-subscriptions.controller.js.map +1 -0
- package/dist/billing-webhooks.controller.d.ts +16 -0
- package/dist/billing-webhooks.controller.d.ts.map +1 -0
- package/dist/billing-webhooks.controller.js +41 -0
- package/dist/billing-webhooks.controller.js.map +1 -0
- package/dist/billing.module.d.ts +3 -0
- package/dist/billing.module.d.ts.map +1 -0
- package/dist/billing.module.js +61 -0
- package/dist/billing.module.js.map +1 -0
- package/dist/billing.service.d.ts +169 -0
- package/dist/billing.service.d.ts.map +1 -0
- package/dist/billing.service.js +290 -0
- package/dist/billing.service.js.map +1 -0
- package/dist/dto/create-contract.dto.d.ts +11 -0
- package/dist/dto/create-contract.dto.d.ts.map +1 -0
- package/dist/dto/create-contract.dto.js +52 -0
- package/dist/dto/create-contract.dto.js.map +1 -0
- package/dist/dto/create-coupon.dto.d.ts +12 -0
- package/dist/dto/create-coupon.dto.d.ts.map +1 -0
- package/dist/dto/create-coupon.dto.js +60 -0
- package/dist/dto/create-coupon.dto.js.map +1 -0
- package/dist/dto/create-entitlement.dto.d.ts +12 -0
- package/dist/dto/create-entitlement.dto.d.ts.map +1 -0
- package/dist/dto/create-entitlement.dto.js +54 -0
- package/dist/dto/create-entitlement.dto.js.map +1 -0
- package/dist/dto/create-offer.dto.d.ts +7 -0
- package/dist/dto/create-offer.dto.d.ts.map +1 -0
- package/dist/dto/create-offer.dto.js +35 -0
- package/dist/dto/create-offer.dto.js.map +1 -0
- package/dist/dto/create-order.dto.d.ts +12 -0
- package/dist/dto/create-order.dto.d.ts.map +1 -0
- package/dist/dto/create-order.dto.js +65 -0
- package/dist/dto/create-order.dto.js.map +1 -0
- package/dist/dto/create-price.dto.d.ts +15 -0
- package/dist/dto/create-price.dto.d.ts.map +1 -0
- package/dist/dto/create-price.dto.js +76 -0
- package/dist/dto/create-price.dto.js.map +1 -0
- package/dist/dto/create-product.dto.d.ts +9 -0
- package/dist/dto/create-product.dto.d.ts.map +1 -0
- package/dist/dto/create-product.dto.js +45 -0
- package/dist/dto/create-product.dto.js.map +1 -0
- package/dist/dto/create-subscription.dto.d.ts +14 -0
- package/dist/dto/create-subscription.dto.d.ts.map +1 -0
- package/dist/dto/create-subscription.dto.js +67 -0
- package/dist/dto/create-subscription.dto.js.map +1 -0
- package/dist/dto/update-contract.dto.d.ts +6 -0
- package/dist/dto/update-contract.dto.d.ts.map +1 -0
- package/dist/dto/update-contract.dto.js +9 -0
- package/dist/dto/update-contract.dto.js.map +1 -0
- package/dist/dto/update-coupon.dto.d.ts +6 -0
- package/dist/dto/update-coupon.dto.d.ts.map +1 -0
- package/dist/dto/update-coupon.dto.js +9 -0
- package/dist/dto/update-coupon.dto.js.map +1 -0
- package/dist/dto/update-offer.dto.d.ts +6 -0
- package/dist/dto/update-offer.dto.d.ts.map +1 -0
- package/dist/dto/update-offer.dto.js +9 -0
- package/dist/dto/update-offer.dto.js.map +1 -0
- package/dist/dto/update-order.dto.d.ts +6 -0
- package/dist/dto/update-order.dto.d.ts.map +1 -0
- package/dist/dto/update-order.dto.js +9 -0
- package/dist/dto/update-order.dto.js.map +1 -0
- package/dist/dto/update-price.dto.d.ts +6 -0
- package/dist/dto/update-price.dto.d.ts.map +1 -0
- package/dist/dto/update-price.dto.js +9 -0
- package/dist/dto/update-price.dto.js.map +1 -0
- package/dist/dto/update-product.dto.d.ts +6 -0
- package/dist/dto/update-product.dto.d.ts.map +1 -0
- package/dist/dto/update-product.dto.js +9 -0
- package/dist/dto/update-product.dto.js.map +1 -0
- package/dist/dto/update-subscription.dto.d.ts +6 -0
- package/dist/dto/update-subscription.dto.d.ts.map +1 -0
- package/dist/dto/update-subscription.dto.js +9 -0
- package/dist/dto/update-subscription.dto.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/hedhog/data/menu.yaml +284 -0
- package/hedhog/data/role.yaml +7 -0
- package/hedhog/data/route.yaml +422 -0
- package/hedhog/frontend/app/_lib/billing-mocks.ts.ejs +270 -0
- package/hedhog/frontend/app/contracts/page.tsx.ejs +562 -0
- package/hedhog/frontend/app/coupons/page.tsx.ejs +669 -0
- package/hedhog/frontend/app/entitlements/page.tsx.ejs +526 -0
- package/hedhog/frontend/app/gateways/page.tsx.ejs +308 -0
- package/hedhog/frontend/app/invoices/page.tsx.ejs +179 -0
- package/hedhog/frontend/app/offers/page.tsx.ejs +483 -0
- package/hedhog/frontend/app/orders/page.tsx.ejs +424 -0
- package/hedhog/frontend/app/page.tsx.ejs +186 -0
- package/hedhog/frontend/app/payments/page.tsx.ejs +187 -0
- package/hedhog/frontend/app/prices/page.tsx.ejs +704 -0
- package/hedhog/frontend/app/products/page.tsx.ejs +568 -0
- package/hedhog/frontend/app/refunds/page.tsx.ejs +174 -0
- package/hedhog/frontend/app/reports/page.tsx.ejs +177 -0
- package/hedhog/frontend/app/subscriptions/page.tsx.ejs +283 -0
- package/hedhog/frontend/app/webhooks/page.tsx.ejs +172 -0
- package/hedhog/frontend/messages/en.json +551 -0
- package/hedhog/frontend/messages/pt.json +563 -0
- package/hedhog/table/billing_contract.yaml +37 -0
- package/hedhog/table/billing_contract_seat.yaml +28 -0
- package/hedhog/table/billing_coupon.yaml +42 -0
- package/hedhog/table/billing_entitlement.yaml +41 -0
- package/hedhog/table/billing_entitlement_event.yaml +20 -0
- package/hedhog/table/billing_invoice.yaml +60 -0
- package/hedhog/table/billing_invoice_item.yaml +25 -0
- package/hedhog/table/billing_offer.yaml +22 -0
- package/hedhog/table/billing_offer_price.yaml +23 -0
- package/hedhog/table/billing_order.yaml +50 -0
- package/hedhog/table/billing_order_item.yaml +35 -0
- package/hedhog/table/billing_payment.yaml +66 -0
- package/hedhog/table/billing_payment_method.yaml +49 -0
- package/hedhog/table/billing_payment_provider.yaml +21 -0
- package/hedhog/table/billing_price.yaml +53 -0
- package/hedhog/table/billing_product.yaml +31 -0
- package/hedhog/table/billing_product_item.yaml +24 -0
- package/hedhog/table/billing_provider_event.yaml +31 -0
- package/hedhog/table/billing_refund.yaml +41 -0
- package/hedhog/table/billing_seat_allocation.yaml +42 -0
- package/hedhog/table/billing_subscription.yaml +66 -0
- package/hedhog/table/billing_subscription_event.yaml +20 -0
- package/hedhog/table/billing_subscription_item.yaml +29 -0
- package/package.json +37 -0
- package/src/adapters/billing-gateway-registry.ts +23 -0
- package/src/adapters/mercadopago.adapter.ts +66 -0
- package/src/adapters/pagarme.adapter.ts +66 -0
- package/src/adapters/payment-gateway.adapter.ts +14 -0
- package/src/adapters/stripe.adapter.ts +67 -0
- package/src/billing-contracts.controller.ts +46 -0
- package/src/billing-coupons.controller.ts +46 -0
- package/src/billing-dashboard.controller.ts +14 -0
- package/src/billing-entitlements.controller.ts +34 -0
- package/src/billing-gateways.controller.ts +19 -0
- package/src/billing-invoices.controller.ts +32 -0
- package/src/billing-offers.controller.ts +46 -0
- package/src/billing-orders.controller.ts +33 -0
- package/src/billing-payments.controller.ts +20 -0
- package/src/billing-prices.controller.ts +46 -0
- package/src/billing-products.controller.ts +46 -0
- package/src/billing-refunds.controller.ts +15 -0
- package/src/billing-subscriptions.controller.ts +49 -0
- package/src/billing-webhooks.controller.ts +15 -0
- package/src/billing.module.ts +48 -0
- package/src/billing.service.ts +391 -0
- package/src/dto/create-contract.dto.ts +30 -0
- package/src/dto/create-coupon.dto.ts +37 -0
- package/src/dto/create-entitlement.dto.ts +31 -0
- package/src/dto/create-offer.dto.ts +17 -0
- package/src/dto/create-order.dto.ts +42 -0
- package/src/dto/create-price.dto.ts +50 -0
- package/src/dto/create-product.dto.ts +25 -0
- package/src/dto/create-subscription.dto.ts +42 -0
- package/src/dto/update-contract.dto.ts +4 -0
- package/src/dto/update-coupon.dto.ts +4 -0
- package/src/dto/update-offer.dto.ts +4 -0
- package/src/dto/update-order.dto.ts +4 -0
- package/src/dto/update-price.dto.ts +4 -0
- package/src/dto/update-product.dto.ts +4 -0
- package/src/dto/update-subscription.dto.ts +4 -0
- package/src/index.ts +32 -0
- package/src/language/en.json +8 -0
- package/src/language/pt.json +8 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Role } from '@hed-hog/api';
|
|
2
|
+
import { Pagination, PaginationDTO } from '@hed-hog/api-pagination';
|
|
3
|
+
import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common';
|
|
4
|
+
import { BillingService } from './billing.service';
|
|
5
|
+
|
|
6
|
+
@Role()
|
|
7
|
+
@Controller('billing')
|
|
8
|
+
export class BillingPaymentsController {
|
|
9
|
+
constructor(private readonly billingService: BillingService) {}
|
|
10
|
+
|
|
11
|
+
@Get('payments')
|
|
12
|
+
list(@Pagination() paginationParams: PaginationDTO) {
|
|
13
|
+
return this.billingService.listPayments(paginationParams);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Get('payments/:id')
|
|
17
|
+
get(@Param('id', ParseIntPipe) id: number) {
|
|
18
|
+
return this.billingService.getPayment(id);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Role } from '@hed-hog/api';
|
|
2
|
+
import { Pagination, PaginationDTO } from '@hed-hog/api-pagination';
|
|
3
|
+
import {
|
|
4
|
+
Body,
|
|
5
|
+
Controller,
|
|
6
|
+
Delete,
|
|
7
|
+
Get,
|
|
8
|
+
Param,
|
|
9
|
+
ParseIntPipe,
|
|
10
|
+
Patch,
|
|
11
|
+
Post,
|
|
12
|
+
} from '@nestjs/common';
|
|
13
|
+
import { BillingService } from './billing.service';
|
|
14
|
+
import { CreatePriceDto } from './dto/create-price.dto';
|
|
15
|
+
import { UpdatePriceDto } from './dto/update-price.dto';
|
|
16
|
+
|
|
17
|
+
@Role()
|
|
18
|
+
@Controller('billing')
|
|
19
|
+
export class BillingPricesController {
|
|
20
|
+
constructor(private readonly billingService: BillingService) {}
|
|
21
|
+
|
|
22
|
+
@Get('prices')
|
|
23
|
+
list(@Pagination() paginationParams: PaginationDTO) {
|
|
24
|
+
return this.billingService.listPrices(paginationParams);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Get('prices/:id')
|
|
28
|
+
get(@Param('id', ParseIntPipe) id: number) {
|
|
29
|
+
return this.billingService.getPrice(id);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Post('prices')
|
|
33
|
+
create(@Body() dto: CreatePriceDto) {
|
|
34
|
+
return this.billingService.createPrice(dto);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Patch('prices/:id')
|
|
38
|
+
update(@Param('id', ParseIntPipe) id: number, @Body() dto: UpdatePriceDto) {
|
|
39
|
+
return this.billingService.updatePrice(id, dto);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Delete('prices/:id')
|
|
43
|
+
remove(@Param('id', ParseIntPipe) id: number) {
|
|
44
|
+
return this.billingService.deletePrice(id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Role } from '@hed-hog/api';
|
|
2
|
+
import { Pagination, PaginationDTO } from '@hed-hog/api-pagination';
|
|
3
|
+
import {
|
|
4
|
+
Body,
|
|
5
|
+
Controller,
|
|
6
|
+
Delete,
|
|
7
|
+
Get,
|
|
8
|
+
Param,
|
|
9
|
+
ParseIntPipe,
|
|
10
|
+
Patch,
|
|
11
|
+
Post,
|
|
12
|
+
} from '@nestjs/common';
|
|
13
|
+
import { BillingService } from './billing.service';
|
|
14
|
+
import { CreateProductDto } from './dto/create-product.dto';
|
|
15
|
+
import { UpdateProductDto } from './dto/update-product.dto';
|
|
16
|
+
|
|
17
|
+
@Role()
|
|
18
|
+
@Controller('billing')
|
|
19
|
+
export class BillingProductsController {
|
|
20
|
+
constructor(private readonly billingService: BillingService) {}
|
|
21
|
+
|
|
22
|
+
@Get('products')
|
|
23
|
+
list(@Pagination() paginationParams: PaginationDTO) {
|
|
24
|
+
return this.billingService.listProducts(paginationParams);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Get('products/:id')
|
|
28
|
+
get(@Param('id', ParseIntPipe) id: number) {
|
|
29
|
+
return this.billingService.getProduct(id);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Post('products')
|
|
33
|
+
create(@Body() dto: CreateProductDto) {
|
|
34
|
+
return this.billingService.createProduct(dto);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Patch('products/:id')
|
|
38
|
+
update(@Param('id', ParseIntPipe) id: number, @Body() dto: UpdateProductDto) {
|
|
39
|
+
return this.billingService.updateProduct(id, dto);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Delete('products/:id')
|
|
43
|
+
remove(@Param('id', ParseIntPipe) id: number) {
|
|
44
|
+
return this.billingService.deleteProduct(id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Role } from '@hed-hog/api';
|
|
2
|
+
import { Pagination, PaginationDTO } from '@hed-hog/api-pagination';
|
|
3
|
+
import { Controller, Get } from '@nestjs/common';
|
|
4
|
+
import { BillingService } from './billing.service';
|
|
5
|
+
|
|
6
|
+
@Role()
|
|
7
|
+
@Controller('billing')
|
|
8
|
+
export class BillingRefundsController {
|
|
9
|
+
constructor(private readonly billingService: BillingService) {}
|
|
10
|
+
|
|
11
|
+
@Get('refunds')
|
|
12
|
+
list(@Pagination() paginationParams: PaginationDTO) {
|
|
13
|
+
return this.billingService.listRefunds(paginationParams);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Role } from '@hed-hog/api';
|
|
2
|
+
import { Pagination, PaginationDTO } from '@hed-hog/api-pagination';
|
|
3
|
+
import {
|
|
4
|
+
Body,
|
|
5
|
+
Controller,
|
|
6
|
+
Get,
|
|
7
|
+
Param,
|
|
8
|
+
ParseIntPipe,
|
|
9
|
+
Patch,
|
|
10
|
+
Post,
|
|
11
|
+
} from '@nestjs/common';
|
|
12
|
+
import { BillingService } from './billing.service';
|
|
13
|
+
import { CreateSubscriptionDto } from './dto/create-subscription.dto';
|
|
14
|
+
|
|
15
|
+
@Role()
|
|
16
|
+
@Controller('billing')
|
|
17
|
+
export class BillingSubscriptionsController {
|
|
18
|
+
constructor(private readonly billingService: BillingService) {}
|
|
19
|
+
|
|
20
|
+
@Get('subscriptions')
|
|
21
|
+
list(@Pagination() paginationParams: PaginationDTO) {
|
|
22
|
+
return this.billingService.listSubscriptions(paginationParams);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Get('subscriptions/:id')
|
|
26
|
+
get(@Param('id', ParseIntPipe) id: number) {
|
|
27
|
+
return this.billingService.getSubscription(id);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Post('subscriptions')
|
|
31
|
+
create(@Body() dto: CreateSubscriptionDto) {
|
|
32
|
+
return this.billingService.createSubscription(dto);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Patch('subscriptions/:id/cancel')
|
|
36
|
+
cancel(@Param('id', ParseIntPipe) id: number) {
|
|
37
|
+
return this.billingService.cancelSubscription(id);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Patch('subscriptions/:id/pause')
|
|
41
|
+
pause(@Param('id', ParseIntPipe) id: number) {
|
|
42
|
+
return this.billingService.pauseSubscription(id);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Patch('subscriptions/:id/resume')
|
|
46
|
+
resume(@Param('id', ParseIntPipe) id: number) {
|
|
47
|
+
return this.billingService.resumeSubscription(id);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Role } from '@hed-hog/api';
|
|
2
|
+
import { Pagination, PaginationDTO } from '@hed-hog/api-pagination';
|
|
3
|
+
import { Controller, Get } from '@nestjs/common';
|
|
4
|
+
import { BillingService } from './billing.service';
|
|
5
|
+
|
|
6
|
+
@Role()
|
|
7
|
+
@Controller('billing')
|
|
8
|
+
export class BillingWebhooksController {
|
|
9
|
+
constructor(private readonly billingService: BillingService) {}
|
|
10
|
+
|
|
11
|
+
@Get('webhooks')
|
|
12
|
+
list(@Pagination() paginationParams: PaginationDTO) {
|
|
13
|
+
return this.billingService.listWebhooks(paginationParams);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { LocaleModule } from '@hed-hog/api-locale';
|
|
2
|
+
import { PaginationModule } from '@hed-hog/api-pagination';
|
|
3
|
+
import { PrismaModule } from '@hed-hog/api-prisma';
|
|
4
|
+
import { forwardRef, Module } from '@nestjs/common';
|
|
5
|
+
import { ConfigModule } from '@nestjs/config';
|
|
6
|
+
import { BillingContractsController } from './billing-contracts.controller';
|
|
7
|
+
import { BillingCouponsController } from './billing-coupons.controller';
|
|
8
|
+
import { BillingDashboardController } from './billing-dashboard.controller';
|
|
9
|
+
import { BillingEntitlementsController } from './billing-entitlements.controller';
|
|
10
|
+
import { BillingGatewaysController } from './billing-gateways.controller';
|
|
11
|
+
import { BillingInvoicesController } from './billing-invoices.controller';
|
|
12
|
+
import { BillingOffersController } from './billing-offers.controller';
|
|
13
|
+
import { BillingOrdersController } from './billing-orders.controller';
|
|
14
|
+
import { BillingPaymentsController } from './billing-payments.controller';
|
|
15
|
+
import { BillingPricesController } from './billing-prices.controller';
|
|
16
|
+
import { BillingProductsController } from './billing-products.controller';
|
|
17
|
+
import { BillingRefundsController } from './billing-refunds.controller';
|
|
18
|
+
import { BillingSubscriptionsController } from './billing-subscriptions.controller';
|
|
19
|
+
import { BillingWebhooksController } from './billing-webhooks.controller';
|
|
20
|
+
import { BillingService } from './billing.service';
|
|
21
|
+
|
|
22
|
+
@Module({
|
|
23
|
+
imports: [
|
|
24
|
+
ConfigModule.forRoot(),
|
|
25
|
+
forwardRef(() => PaginationModule),
|
|
26
|
+
forwardRef(() => PrismaModule),
|
|
27
|
+
forwardRef(() => LocaleModule),
|
|
28
|
+
],
|
|
29
|
+
controllers: [
|
|
30
|
+
BillingDashboardController,
|
|
31
|
+
BillingProductsController,
|
|
32
|
+
BillingPricesController,
|
|
33
|
+
BillingOffersController,
|
|
34
|
+
BillingCouponsController,
|
|
35
|
+
BillingOrdersController,
|
|
36
|
+
BillingSubscriptionsController,
|
|
37
|
+
BillingInvoicesController,
|
|
38
|
+
BillingPaymentsController,
|
|
39
|
+
BillingRefundsController,
|
|
40
|
+
BillingEntitlementsController,
|
|
41
|
+
BillingContractsController,
|
|
42
|
+
BillingGatewaysController,
|
|
43
|
+
BillingWebhooksController,
|
|
44
|
+
],
|
|
45
|
+
providers: [BillingService],
|
|
46
|
+
exports: [BillingService],
|
|
47
|
+
})
|
|
48
|
+
export class BillingModule {}
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
|
|
2
|
+
import { PrismaService } from '@hed-hog/api-prisma';
|
|
3
|
+
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
4
|
+
import { CreateContractDto } from './dto/create-contract.dto';
|
|
5
|
+
import { CreateCouponDto } from './dto/create-coupon.dto';
|
|
6
|
+
import { CreateEntitlementDto } from './dto/create-entitlement.dto';
|
|
7
|
+
import { CreateOfferDto } from './dto/create-offer.dto';
|
|
8
|
+
import { CreateOrderDto } from './dto/create-order.dto';
|
|
9
|
+
import { CreatePriceDto } from './dto/create-price.dto';
|
|
10
|
+
import { CreateProductDto } from './dto/create-product.dto';
|
|
11
|
+
import { CreateSubscriptionDto } from './dto/create-subscription.dto';
|
|
12
|
+
import { UpdateContractDto } from './dto/update-contract.dto';
|
|
13
|
+
import { UpdateOfferDto } from './dto/update-offer.dto';
|
|
14
|
+
import { UpdatePriceDto } from './dto/update-price.dto';
|
|
15
|
+
import { UpdateProductDto } from './dto/update-product.dto';
|
|
16
|
+
|
|
17
|
+
@Injectable()
|
|
18
|
+
export class BillingService {
|
|
19
|
+
constructor(
|
|
20
|
+
private readonly prisma: PrismaService,
|
|
21
|
+
private readonly paginationService: PaginationService,
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
// ─── Products ─────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
async listProducts(paginationParams: PaginationDTO) {
|
|
27
|
+
return this.paginationService.paginate(
|
|
28
|
+
this.prisma.billing_product,
|
|
29
|
+
paginationParams,
|
|
30
|
+
{ orderBy: { created_at: 'desc' } },
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async getProduct(id: number) {
|
|
35
|
+
const product = await this.prisma.billing_product.findUnique({
|
|
36
|
+
where: { id },
|
|
37
|
+
include: { billing_price: true },
|
|
38
|
+
});
|
|
39
|
+
if (!product) throw new NotFoundException('Product not found');
|
|
40
|
+
return product;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async createProduct(data: CreateProductDto) {
|
|
44
|
+
return this.prisma.billing_product.create({ data });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async updateProduct(id: number, data: UpdateProductDto) {
|
|
48
|
+
return this.prisma.billing_product.update({ where: { id }, data });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async deleteProduct(id: number) {
|
|
52
|
+
return this.prisma.billing_product.delete({ where: { id } });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─── Prices ───────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
async listPrices(paginationParams: PaginationDTO) {
|
|
58
|
+
return this.paginationService.paginate(
|
|
59
|
+
this.prisma.billing_price,
|
|
60
|
+
paginationParams,
|
|
61
|
+
{
|
|
62
|
+
include: { billing_product: { select: { id: true, name: true } } },
|
|
63
|
+
orderBy: { created_at: 'desc' },
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getPrice(id: number) {
|
|
69
|
+
const price = await this.prisma.billing_price.findUnique({
|
|
70
|
+
where: { id },
|
|
71
|
+
include: { billing_product: true },
|
|
72
|
+
});
|
|
73
|
+
if (!price) throw new NotFoundException('Price not found');
|
|
74
|
+
return price;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async createPrice(data: CreatePriceDto) {
|
|
78
|
+
return this.prisma.billing_price.create({ data });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async updatePrice(id: number, data: UpdatePriceDto) {
|
|
82
|
+
return this.prisma.billing_price.update({ where: { id }, data });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async deletePrice(id: number) {
|
|
86
|
+
return this.prisma.billing_price.delete({ where: { id } });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ─── Offers ───────────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
async listOffers(paginationParams: PaginationDTO) {
|
|
92
|
+
return this.paginationService.paginate(
|
|
93
|
+
this.prisma.billing_offer,
|
|
94
|
+
paginationParams,
|
|
95
|
+
{ orderBy: { created_at: 'desc' } },
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async getOffer(id: number) {
|
|
100
|
+
const offer = await this.prisma.billing_offer.findUnique({
|
|
101
|
+
where: { id },
|
|
102
|
+
include: { billing_offer_price: { include: { billing_price: true } } },
|
|
103
|
+
});
|
|
104
|
+
if (!offer) throw new NotFoundException('Offer not found');
|
|
105
|
+
return offer;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async createOffer(data: CreateOfferDto) {
|
|
109
|
+
return this.prisma.billing_offer.create({ data });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async updateOffer(id: number, data: UpdateOfferDto) {
|
|
113
|
+
return this.prisma.billing_offer.update({ where: { id }, data });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async deleteOffer(id: number) {
|
|
117
|
+
return this.prisma.billing_offer.delete({ where: { id } });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ─── Coupons ──────────────────────────────────────────────────────────────
|
|
121
|
+
|
|
122
|
+
async listCoupons(paginationParams: PaginationDTO) {
|
|
123
|
+
return this.paginationService.paginate(
|
|
124
|
+
this.prisma.billing_coupon,
|
|
125
|
+
paginationParams,
|
|
126
|
+
{ orderBy: { created_at: 'desc' } },
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async getCoupon(id: number) {
|
|
131
|
+
const coupon = await this.prisma.billing_coupon.findUnique({ where: { id } });
|
|
132
|
+
if (!coupon) throw new NotFoundException('Coupon not found');
|
|
133
|
+
return coupon;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async createCoupon(data: CreateCouponDto) {
|
|
137
|
+
return this.prisma.billing_coupon.create({ data });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async updateCoupon(id: number, data: Partial<CreateCouponDto>) {
|
|
141
|
+
return this.prisma.billing_coupon.update({ where: { id }, data });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async deleteCoupon(id: number) {
|
|
145
|
+
return this.prisma.billing_coupon.delete({ where: { id } });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ─── Orders ───────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
async listOrders(paginationParams: PaginationDTO) {
|
|
151
|
+
return this.paginationService.paginate(
|
|
152
|
+
this.prisma.billing_order,
|
|
153
|
+
paginationParams,
|
|
154
|
+
{ orderBy: { created_at: 'desc' } },
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async getOrder(id: number) {
|
|
159
|
+
const order = await this.prisma.billing_order.findUnique({
|
|
160
|
+
where: { id },
|
|
161
|
+
include: { billing_order_item: true },
|
|
162
|
+
});
|
|
163
|
+
if (!order) throw new NotFoundException('Order not found');
|
|
164
|
+
return order;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async createOrder(data: CreateOrderDto) {
|
|
168
|
+
return this.prisma.billing_order.create({ data });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ─── Subscriptions ────────────────────────────────────────────────────────
|
|
172
|
+
|
|
173
|
+
async listSubscriptions(paginationParams: PaginationDTO) {
|
|
174
|
+
return this.paginationService.paginate(
|
|
175
|
+
this.prisma.billing_subscription,
|
|
176
|
+
paginationParams,
|
|
177
|
+
{
|
|
178
|
+
include: {
|
|
179
|
+
billing_product: { select: { id: true, name: true } },
|
|
180
|
+
billing_price: { select: { id: true, name: true, amount_cents: true, interval_unit: true } },
|
|
181
|
+
},
|
|
182
|
+
orderBy: { created_at: 'desc' },
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async getSubscription(id: number) {
|
|
188
|
+
const sub = await this.prisma.billing_subscription.findUnique({
|
|
189
|
+
where: { id },
|
|
190
|
+
include: {
|
|
191
|
+
billing_product: true,
|
|
192
|
+
billing_price: true,
|
|
193
|
+
billing_subscription_item: true,
|
|
194
|
+
billing_invoice: { take: 5, orderBy: { created_at: 'desc' } },
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
if (!sub) throw new NotFoundException('Subscription not found');
|
|
198
|
+
return sub;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async createSubscription(data: CreateSubscriptionDto) {
|
|
202
|
+
return this.prisma.billing_subscription.create({ data });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async cancelSubscription(id: number) {
|
|
206
|
+
return this.prisma.billing_subscription.update({
|
|
207
|
+
where: { id },
|
|
208
|
+
data: { status: 'canceled', canceled_at: new Date() },
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async pauseSubscription(id: number) {
|
|
213
|
+
return this.prisma.billing_subscription.update({
|
|
214
|
+
where: { id },
|
|
215
|
+
data: { status: 'paused' },
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async resumeSubscription(id: number) {
|
|
220
|
+
return this.prisma.billing_subscription.update({
|
|
221
|
+
where: { id },
|
|
222
|
+
data: { status: 'active' },
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ─── Invoices ─────────────────────────────────────────────────────────────
|
|
227
|
+
|
|
228
|
+
async listInvoices(paginationParams: PaginationDTO) {
|
|
229
|
+
return this.paginationService.paginate(
|
|
230
|
+
this.prisma.billing_invoice,
|
|
231
|
+
paginationParams,
|
|
232
|
+
{ orderBy: { created_at: 'desc' } },
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async getInvoice(id: number) {
|
|
237
|
+
const invoice = await this.prisma.billing_invoice.findUnique({
|
|
238
|
+
where: { id },
|
|
239
|
+
include: { billing_invoice_item: true, billing_payment: { take: 5 } },
|
|
240
|
+
});
|
|
241
|
+
if (!invoice) throw new NotFoundException('Invoice not found');
|
|
242
|
+
return invoice;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async createInvoice(data: Record<string, unknown>) {
|
|
246
|
+
return this.prisma.billing_invoice.create({ data: data as any });
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ─── Payments ─────────────────────────────────────────────────────────────
|
|
250
|
+
|
|
251
|
+
async listPayments(paginationParams: PaginationDTO) {
|
|
252
|
+
return this.paginationService.paginate(
|
|
253
|
+
this.prisma.billing_payment,
|
|
254
|
+
paginationParams,
|
|
255
|
+
{ orderBy: { created_at: 'desc' } },
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async getPayment(id: number) {
|
|
260
|
+
const payment = await this.prisma.billing_payment.findUnique({ where: { id } });
|
|
261
|
+
if (!payment) throw new NotFoundException('Payment not found');
|
|
262
|
+
return payment;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ─── Refunds ──────────────────────────────────────────────────────────────
|
|
266
|
+
|
|
267
|
+
async listRefunds(paginationParams: PaginationDTO) {
|
|
268
|
+
return this.paginationService.paginate(
|
|
269
|
+
this.prisma.billing_refund,
|
|
270
|
+
paginationParams,
|
|
271
|
+
{ orderBy: { created_at: 'desc' } },
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ─── Entitlements ─────────────────────────────────────────────────────────
|
|
276
|
+
|
|
277
|
+
async listEntitlements(paginationParams: PaginationDTO) {
|
|
278
|
+
return this.paginationService.paginate(
|
|
279
|
+
this.prisma.billing_entitlement,
|
|
280
|
+
paginationParams,
|
|
281
|
+
{ orderBy: { created_at: 'desc' } },
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async createEntitlement(data: CreateEntitlementDto) {
|
|
286
|
+
return this.prisma.billing_entitlement.create({ data });
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async deleteEntitlement(id: number) {
|
|
290
|
+
return this.prisma.billing_entitlement.update({
|
|
291
|
+
where: { id },
|
|
292
|
+
data: { status: 'revoked' },
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ─── Contracts ────────────────────────────────────────────────────────────
|
|
297
|
+
|
|
298
|
+
async listContracts(paginationParams: PaginationDTO) {
|
|
299
|
+
return this.paginationService.paginate(
|
|
300
|
+
this.prisma.billing_contract,
|
|
301
|
+
paginationParams,
|
|
302
|
+
{ orderBy: { created_at: 'desc' } },
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async getContract(id: number) {
|
|
307
|
+
const contract = await this.prisma.billing_contract.findUnique({
|
|
308
|
+
where: { id },
|
|
309
|
+
include: {
|
|
310
|
+
billing_contract_seat: { include: { billing_product: true } },
|
|
311
|
+
billing_seat_allocation: true,
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
if (!contract) throw new NotFoundException('Contract not found');
|
|
315
|
+
return contract;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async createContract(data: CreateContractDto) {
|
|
319
|
+
return this.prisma.billing_contract.create({ data });
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async updateContract(id: number, data: UpdateContractDto) {
|
|
323
|
+
return this.prisma.billing_contract.update({ where: { id }, data });
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async deleteContract(id: number) {
|
|
327
|
+
return this.prisma.billing_contract.delete({ where: { id } });
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// ─── Gateways ─────────────────────────────────────────────────────────────
|
|
331
|
+
|
|
332
|
+
async listGateways() {
|
|
333
|
+
return this.prisma.billing_payment_provider.findMany({
|
|
334
|
+
orderBy: { name: 'asc' },
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
async updateGateway(slug: string, data: Record<string, unknown>) {
|
|
339
|
+
return this.prisma.billing_payment_provider.upsert({
|
|
340
|
+
where: { slug },
|
|
341
|
+
update: data as any,
|
|
342
|
+
create: { slug, name: slug, ...data } as any,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ─── Webhooks ─────────────────────────────────────────────────────────────
|
|
347
|
+
|
|
348
|
+
async listWebhooks(paginationParams: PaginationDTO) {
|
|
349
|
+
return this.paginationService.paginate(
|
|
350
|
+
this.prisma.billing_provider_event,
|
|
351
|
+
paginationParams,
|
|
352
|
+
{ orderBy: { created_at: 'desc' } },
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// ─── Dashboard ────────────────────────────────────────────────────────────
|
|
357
|
+
|
|
358
|
+
async getDashboardData() {
|
|
359
|
+
const [
|
|
360
|
+
activeSubscriptions,
|
|
361
|
+
failedPayments,
|
|
362
|
+
overdueInvoices,
|
|
363
|
+
recentPayments,
|
|
364
|
+
] = await Promise.all([
|
|
365
|
+
this.prisma.billing_subscription.count({ where: { status: 'active' } }),
|
|
366
|
+
this.prisma.billing_payment.count({ where: { status: 'failed' } }),
|
|
367
|
+
this.prisma.billing_invoice.count({ where: { status: 'open' } }),
|
|
368
|
+
this.prisma.billing_payment.findMany({
|
|
369
|
+
where: { status: 'paid' },
|
|
370
|
+
orderBy: { paid_at: 'desc' },
|
|
371
|
+
take: 10,
|
|
372
|
+
}),
|
|
373
|
+
]);
|
|
374
|
+
|
|
375
|
+
const paidThisMonth = await this.prisma.billing_payment.aggregate({
|
|
376
|
+
where: {
|
|
377
|
+
status: 'paid',
|
|
378
|
+
paid_at: { gte: new Date(new Date().getFullYear(), new Date().getMonth(), 1) },
|
|
379
|
+
},
|
|
380
|
+
_sum: { amount_cents: true },
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
activeSubscriptions,
|
|
385
|
+
failedPayments,
|
|
386
|
+
overdueInvoices,
|
|
387
|
+
revenueThisMonthCents: paidThisMonth._sum.amount_cents ?? 0,
|
|
388
|
+
recentPayments,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IsEnum, IsNumber, IsOptional, IsString } from 'class-validator';
|
|
2
|
+
|
|
3
|
+
export class CreateContractDto {
|
|
4
|
+
@IsNumber()
|
|
5
|
+
contact_id: number;
|
|
6
|
+
|
|
7
|
+
@IsString()
|
|
8
|
+
name: string;
|
|
9
|
+
|
|
10
|
+
@IsOptional()
|
|
11
|
+
@IsString()
|
|
12
|
+
description?: string;
|
|
13
|
+
|
|
14
|
+
@IsString()
|
|
15
|
+
starts_at: string;
|
|
16
|
+
|
|
17
|
+
@IsOptional()
|
|
18
|
+
ends_at?: string;
|
|
19
|
+
|
|
20
|
+
@IsOptional()
|
|
21
|
+
@IsNumber()
|
|
22
|
+
total_seats?: number;
|
|
23
|
+
|
|
24
|
+
@IsOptional()
|
|
25
|
+
@IsEnum(['draft', 'active', 'expired', 'terminated'])
|
|
26
|
+
status?: string;
|
|
27
|
+
|
|
28
|
+
@IsOptional()
|
|
29
|
+
signed_at?: string;
|
|
30
|
+
}
|